schm

node v7.10.1
version: 0.0.8
endpointsharetweet
const schema = require('schm') const userSchema = schema({ name: String, age: Number, }) userSchema.parse({ name: 'Haz', age: '27', })
const computed = require('schm-computed') const userSchema2 = schema({ firstName: String, lastName: String, }, computed({ fullName: values => `${values.firstName} ${values.lastName}`, })) userSchema2.parse({ firstName: 'Diego', lastName: 'Haz', })
const methods = require('schm-methods') const userSchema3 = schema({ name: String, preferredLanguages: [String], }, methods({ codeIn: (values, language) => values.preferredLanguages.includes(language), })) const user3 = userSchema3.parse({ name: 'Haz', preferredLanguages: ['JavaScript', 'Swift', 'C#'], }) user3.codeIn('JavaScript')
const translate = require('schm-translate') const userSchema4 = schema({ name: String, email: String, }, translate({ name: 'username', email: 'emails.0', })) userSchema4.parse({ username: 'Haz', emails: [ 'hazdiego@gmail.com', 'diegohaz@live.com', ], })
const { query, near, fields, page } = require('schm-mongo') const placeSchema = schema({ name: String, location: [Number], }) const querySchema = schema( placeSchema, fields(), page(), query(), near('location'), ) const parsedQuery = querySchema.parse({ name: 'foo', fields: 'name', near: '-22.4321,40.4321', min_distance: 1000, max_distance: 2000, limit: 10, sort: '-createdAt', }) JSON.stringify(parsedQuery, null, 2)
Loading…

no comments

    sign in to comment