@itenneti/stateless-validation

1.2.0 • Public • Published

stateless-validation

Reusable validation logic as pure functions

This package allows us to reuse the same validation logic between the UI/frontend and the REST API/backend.

Install

$ npm i --save @itenneti/stateless-validation
// with babel
import sv from '@itenneti/stateless-validation'
// without babel
const sv = require('@itenneti/stateless-validation')

API

sv.isValidSlug(string)

Accepts a single string and returns a boolean indicating if the given string is a valid URL-friendly slug (i.e. a username).

A slug is valid if it meets the following criteria:

  • Starts with a lowercase letter
  • Is 3 to 64 characters long
  • Consists of only lowercase letters, numbers, underscores, or hyphens

sv.isValidPassword(string)

Accepts a single string and returns a boolean indicating if the given string is a valid password.

A password is valid if it meets the following criteria:

  • Is at least 6 characters long

sv.isValidEmail(string)

Accepts a single string and returns a boolean indicating if the given string is a valid email.

An email is valid if it meets the following criteria:

  • Conforms to the format of {local-part}@{domain}

Releasing

After one or more PRs have been merged to master, you can cut a new release with the following commands:

# update local master branch
git checkout master && git pull origin master
# make sure tests pass
npm it
# bump version, update changelog, and create git tag
npm run release
# push release to github
git push -u --follow-tags origin master
npm publish --access public

Then you can update the version referenced by any apps/packages that use this as a dependency.

Readme

Keywords

none

Package Sidebar

Install

npm i @itenneti/stateless-validation

Weekly Downloads

0

Version

1.2.0

License

ISC

Last publish

Collaborators

  • kylescarbx
  • nexdrew
  • broanius