0.15.10 • Published 3 months ago

doormen v0.15.10

Weekly downloads
7
License
MIT
Repository
github
Last release
3 months ago

Doormen

Validate, sanitize and assert: the silver bullet of data!

Beta version.

/!\ This documentation is still a Work In Progress /!\

Basic validation

  • sanitize Array of string the sanitizer's name to apply before any type checking
  • optional boolean the data can be null or undefined, if so the data validate immediately
  • default (anything) the data can be null or undefined, if so it is overwritten by the default value and it validates immediately
  • type string the name of the type checker
  • instanceOf
  • min
  • max
  • length
  • minLength
  • maxLength
  • match
  • in
  • notIn
  • when
  • properties object of schema, it iterates through each properties and checks that they all match their own schema
  • elements Array same than properties but for arrays
  • only boolean used in conjunction with properties or elements, it checks that no properties other than those listed are present
  • of object contains one schema that will check each elements of an array or each properties

Type Checkers

Javascript primitive types:

  • undefined: the data should be undefined
  • null: the data should be null
  • boolean: the data should be a boolean, i.e. true or false
  • number: the data should be a number. NOTE that Infinity and NaN are ok, so you may consider using real/float instead of number in almost all cases
  • string: the data should be a string
  • object: the data should be an Object
  • function: the data should be a Function

Javascript/Node.js built-in types:

  • array: the data should be an Array
  • error: the data should be an instance of Error
  • date: the data should be an instance of Date
  • regexp: a regular expression
  • buffer: the data should be a Node.js Buffer

Common meta types:

  • unset: null or undefined
  • real or float: a number that is not NaN nor +/- Infinity
  • integer: a number that is not NaN nor +/- Infinity, and that do not have decimal part
  • hex: a string representing an hexadecimal number, having only 0-9, a-f and A-F characters
  • strictObject: an object that is not an array
  • looseObject: object-like: object or function

Internet:

  • ipv4: a string that is a IPv4 address
  • ipv6: a string that is a IPv6 address
  • ip: an IPv4 or IPv6 address
  • hostname: a string that is a valid hostname (domain + subdomain)
  • host: a hostname or an ip address
  • url: a string that is a valid URL (generic URL) including the scheme
  • weburl: a valid web/internet URL, a subset of the URL type
  • email: a string that is a valid email address

Misc:

  • schema: an object which is a valid doormen schema
  • mongoId: an object which is a MongoDB's ObjectId OR a string that is a correct ObjectId string representation

Sanitizers

Common cast:

  • toNumber: try to convert to a number (mostly from string)
  • toReal or toFloat: try to convert to a float/real (not much difference with toNumber)
  • toInteger: try to convert to an integer, rounding the number if necessary
  • toString: try to convert to a string
  • toBoolean: try to convert to a boolean very loosely, so it accepts strings like true/false, yes/no, on/off or numbers like 1/0, or fallback to truthy/falsy values.
  • toArray: try to convert to an array, non-array are converted to an array with a single element
  • toDate: try to convert to a Date (number are timestamp, string are parsed, object are considered like a Date-object)
  • nullToUndefined: transform null to undefined

String modifiers:

  • trim: trim the string, removing whitespace at the beginning and the end
  • toUpperCase: transform all characters into their upper-case counterparts
  • toLowerCase: transform all characters into theier lower-case counterparts
  • capitalize: transform to title case, each word starts with an upper-case
  • titleCase: transform to title case, each word starts with an upper-case following lower-case characters (except ALL-CAPS words)
  • latinize: transform letter to latin (remove accent, transform modified letters to their latin counterparts)
  • dashToCamelCase: transform identifiers having word separated by dash/hyphen to camelCase

Enforcers:

  • resize: resize a string if it does not match the required length/minLength/maxLength (truncate, or use leftPadding/rightPadding properties of the schema)
  • removeExtraProperties: remove extra-properties from the object that are not in the schema (clone it, not in-place)

Misc:

  • mongoId: convert a string to a MongoDB's ObjectId if possible
0.15.8

4 months ago

0.15.9

4 months ago

0.15.10

3 months ago

0.15.7

4 months ago

0.15.6

10 months ago

0.15.4

1 year ago

0.15.5

1 year ago

0.15.0

2 years ago

0.15.1

2 years ago

0.15.2

2 years ago

0.15.3

2 years ago

0.14.8

2 years ago

0.14.9

2 years ago

0.14.7

2 years ago

0.14.6

2 years ago

0.14.5

3 years ago

0.14.4

3 years ago

0.14.3

3 years ago

0.14.0

3 years ago

0.14.1

3 years ago

0.14.2

3 years ago

0.13.1

4 years ago

0.13.2

4 years ago

0.13.0

4 years ago

0.12.5

4 years ago

0.12.4

4 years ago

0.12.0

4 years ago

0.12.1

4 years ago

0.12.2

4 years ago

0.12.3

4 years ago

0.11.3

4 years ago

0.11.2

4 years ago

0.11.1

5 years ago

0.11.0

5 years ago

0.10.21

5 years ago

0.10.20

5 years ago

0.10.19

5 years ago

0.10.18

6 years ago

0.10.17

6 years ago

0.10.16

6 years ago

0.10.15

6 years ago

0.10.14

6 years ago

0.10.13

6 years ago

0.10.12

6 years ago

0.10.11

6 years ago

0.10.10

6 years ago

0.10.9

6 years ago

0.10.8

6 years ago

0.10.7

6 years ago

0.10.6

6 years ago

0.10.5

6 years ago

0.10.4

6 years ago

0.10.3

6 years ago

0.10.2

6 years ago

0.10.1

6 years ago

0.10.0

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.5

6 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.7.30

7 years ago

0.7.29

7 years ago

0.7.28

7 years ago

0.7.27

7 years ago

0.7.26

7 years ago

0.7.25

7 years ago

0.7.24

7 years ago

0.7.23

7 years ago

0.7.22

7 years ago

0.7.21

7 years ago

0.7.20

7 years ago

0.7.19

7 years ago

0.7.18

7 years ago

0.7.17

7 years ago

0.7.16

7 years ago

0.7.15

7 years ago

0.7.14

7 years ago

0.7.13

7 years ago

0.7.12

7 years ago

0.7.11

7 years ago

0.7.10

7 years ago

0.7.9

7 years ago

0.7.8

7 years ago

0.7.7

7 years ago

0.7.6

7 years ago

0.7.5

7 years ago

0.7.4

7 years ago

0.7.3

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.10

7 years ago

0.6.9

8 years ago

0.6.8

8 years ago

0.6.7

9 years ago

0.6.6

9 years ago

0.6.5

9 years ago

0.6.4

9 years ago

0.6.3

9 years ago

0.6.2

9 years ago

0.6.0

9 years ago

0.5.2

9 years ago

0.5.1

9 years ago

0.5.0

9 years ago

0.4.32

9 years ago

0.4.31

9 years ago

0.4.30

9 years ago

0.4.29

9 years ago

0.4.28

9 years ago

0.4.27

9 years ago

0.4.26

9 years ago

0.4.25

9 years ago

0.4.24

9 years ago

0.4.22

9 years ago

0.4.21

9 years ago

0.4.20

9 years ago

0.4.19

9 years ago

0.4.18

9 years ago

0.4.17

9 years ago

0.4.16

9 years ago

0.4.15

9 years ago

0.4.14

9 years ago

0.4.13

9 years ago

0.4.12

9 years ago

0.4.11

9 years ago

0.4.10

9 years ago

0.4.9

9 years ago

0.4.8

9 years ago

0.4.7

9 years ago

0.4.6

9 years ago

0.4.5

9 years ago

0.4.4

9 years ago

0.4.3

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.2.17

10 years ago

0.2.16

10 years ago

0.2.15

10 years ago

0.2.14

10 years ago

0.2.13

10 years ago

0.2.12

10 years ago

0.2.11

10 years ago

0.2.10

10 years ago

0.2.9

10 years ago

0.2.8

10 years ago

0.2.7

10 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.45

10 years ago

0.0.44

10 years ago

0.0.43

10 years ago

0.0.42

10 years ago

0.0.41

10 years ago

0.0.40

10 years ago

0.0.39

10 years ago

0.0.38

10 years ago

0.0.37

10 years ago

0.0.36

10 years ago

0.0.35

10 years ago

0.0.34

10 years ago

0.0.33

10 years ago

0.0.32

10 years ago

0.0.31

10 years ago

0.0.30

10 years ago

0.0.29

10 years ago

0.0.28

10 years ago

0.0.27

10 years ago

0.0.26

10 years ago

0.0.25

10 years ago

0.0.24

10 years ago

0.0.23

10 years ago

0.0.22

10 years ago

0.0.21

10 years ago

0.0.20

10 years ago

0.0.19

10 years ago

0.0.18

10 years ago

0.0.17

10 years ago

0.0.16

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago