New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kya

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kya

Javascript Object Validation

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Kya - Javascript Object Validation

Kya is written to make object validation easier. It support JS native type, required field and easy customized validate function, all in single object as descriptor. The validation is asynchronous.

Install

npm i kya --save

Support type

  • String
  • Number
  • Date
  • Boolean
  • Array
  • Array validation
  • Nested object validation

Examples

  const usernameValidator = {
    required: true,
    type: String,
  }

  const schema = kya(
    {
      username: usernameValidator,
      telephone: Number,
    },
    {
      username: {
        required: 'username is required',
        type: 'Type error!'
      },
      telephone: {
        type: 'Type error!'
      },
    }
  )

  schema
    .validate({ username: 'kya', age: 19 })
    .then(result => {
      console.log('result', result) // { username: { valid: true }, telephone: { valid: true } }​​​​​
    })

API

kya

  function kya(schema?: Schema, messages?: Messages): {
    validate: (target?: Object) => Promise<Object>;
    validateOn: (target?: Object, ...onfields: string[]) => Promise<Object>;
  };
interface Schema {
  [field: string]: FieldSchema;
}
type SupportType = String | Number | Boolean | Array<any> | Date | Object;
type Type = { type: string; } | SupportType;
type FieldSchema =
  (Type & {required?: boolean; }) &
  {
    [customrule: string]: any
  };
export interface Messages {
  [field: string]: Object;
}

There are two arguments, schema and message, in kya. Schema is an object that specify fields you want to check, and in each field you wanna specify field schema, where your validation rule goes here. Message is the error message it gonna show whenever your field validation is not valid.

Keywords

FAQs

Package last updated on 17 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc