Giter Site home page Giter Site logo

konstantinsimeonov / fluent-schemer Goto Github PK

View Code? Open in Web Editor NEW
47.0 5.0 0.0 514 KB

i wrote this so i can validate stuff without suffering

License: MIT License

JavaScript 54.60% TypeScript 44.73% Shell 0.67%
validation validation-library schema-validation declarative javascript

fluent-schemer's Introduction

fluent-schemer

Coverage Status Coverage Status

const librarySchema = object({
	dependenciesCount: number().min(0).max(10).integer().optional(),
	name: string().minlength(2).maxlength(10),
	testCoverage: number().min(0).max(100).optional(),
	lastCommitDate: date().after(new Date(new Date().setMonth(new Date().getMonth() - 1))),
	contributors: array(
		object({
			username: string().minlength(5),
			email: string().pattern(/\S+@\S+\.\S+/)
		})
	),
	issues: array(string()),
	activelyMaintained: bool(),
	license: enumeration('MIT', 'BSD', 'GPL')
});

const { errorCounts, errors } = librarySchema.validate(someLibraryRecord);

Incoming:

  • default values, something like
const { corrected: pageSize } = number().min(10).max(100).integer().default(10).validate(-5);
console.log(corrected); // 10

const { corrected: username } = string()
	.minlength(2)
	.maxlength(10)
	.defaultExpression(value => ('_________' + value).slice(0, 10))
	.validate('1');
console.log(username); // _________1

Aims to provide declarative, expressive and elegant approach to validation, while providing an intuitive, easy-to-use api.

It's cool, because

  • it fully embraces ES2015 features such as classes, fat arrow functions, mixins, destructuring statements, modules
  • has typescript type definitions - v2.0 comes with typings for enhanced development experience
  • has flow libdefs, which will soon be available on flow-typed
  • easy to use and pick up, write a little code for a lot of common validation logic
  • has a fluent, readable and declarative api
  • umd compliant - use in node/browser, with commonjs, umd, script tags, harmony modules, whatever
  • no production dependencies, small codebase
  • helps developers get rid of imperative code, long if-else's and writing boring validations all over again
  • promotes code reuse - easily share code between modules, between clients, servers and across projects
  • easy to extends with custom schemas
  • statically type checked with latest typescript, checked for correctness with a bunch of unit tests
  • throws errors when rubbish arguments are provided to schema methods, instead of failing silently

Running the tests

yarn build && yarn lint && yarn test

Examples

Examples can be found in the docs, in the source code and in the tests.

fluent-schemer's People

Contributors

konstantinsimeonov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fluent-schemer's Issues

Image schema validator

Implement an image (base64 data) validator.

Features:

  • verify mime type (png, jpeg, garbage)
  • check for dimensions HxW
  • verify file size doesn't exceed X bytes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.