first commit
This commit is contained in:
9
node_modules/ow-lite/.editorconfig
generated
vendored
Normal file
9
node_modules/ow-lite/.editorconfig
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
5
node_modules/ow-lite/.eslintrc
generated
vendored
Normal file
5
node_modules/ow-lite/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": [
|
||||
"standard"
|
||||
]
|
||||
}
|
||||
8
node_modules/ow-lite/.travis.yml
generated
vendored
Normal file
8
node_modules/ow-lite/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
language: node_js
|
||||
cache: yarn
|
||||
node_js:
|
||||
- 10
|
||||
- 9
|
||||
- 8
|
||||
- 7
|
||||
- 6
|
||||
105
node_modules/ow-lite/index.js
generated
vendored
Normal file
105
node_modules/ow-lite/index.js
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
'use strict'
|
||||
|
||||
const symbols = require('./lib/symbols')
|
||||
const number = require('./lib/number')
|
||||
const string = require('./lib/string')
|
||||
const object = require('./lib/object')
|
||||
|
||||
const typePredicates = {
|
||||
number,
|
||||
string,
|
||||
object
|
||||
}
|
||||
|
||||
const createOw = ({
|
||||
validators = [],
|
||||
predicates = typePredicates,
|
||||
type = null
|
||||
} = { }) => {
|
||||
const ow = new Proxy(function () { }, {
|
||||
get: (obj, key) => {
|
||||
if (key === symbols.validate) {
|
||||
return (value, label = 'argument') => {
|
||||
if (!type) {
|
||||
return new Error('missing required type specifier')
|
||||
}
|
||||
|
||||
for (let i = 0; i < validators.length; ++i) {
|
||||
const validator = validators[i]
|
||||
const result = validator.fn(value)
|
||||
|
||||
if (!result) {
|
||||
if (i === 0) {
|
||||
throw new Error(`Expected ${label} \`${value}\` to be of type \`${type}\`, but received type \`${typeof value}\``)
|
||||
} else {
|
||||
throw new Error(`Expected ${type} \`${label}\` \`${value}\` failed predicate \`${validator.key}\``)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const predicate = predicates[key]
|
||||
|
||||
if (predicate) {
|
||||
if (typeof predicate === 'function') {
|
||||
validators.push({
|
||||
key,
|
||||
fn: predicate
|
||||
})
|
||||
|
||||
return ow
|
||||
} else {
|
||||
return createOw({
|
||||
type: key,
|
||||
validators: [
|
||||
{
|
||||
key,
|
||||
fn: predicate.validator
|
||||
}
|
||||
],
|
||||
predicates: predicate.predicates
|
||||
})
|
||||
}
|
||||
} else {
|
||||
const fn = predicates[symbols.func] && predicates[symbols.func][key]
|
||||
|
||||
if (fn) {
|
||||
return new Proxy(function () { }, {
|
||||
get: () => {
|
||||
throw new Error(`invalid use of functional predicate "${key}"`)
|
||||
},
|
||||
|
||||
apply: (obj, thisArg, args) => {
|
||||
validators.push({
|
||||
key,
|
||||
fn: fn(...args)
|
||||
})
|
||||
|
||||
return ow
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (key === 'default' || key === '__esModule') {
|
||||
return ow
|
||||
}
|
||||
|
||||
return ow
|
||||
// throw new Error(`unrecognized predicate "${key}"`)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
apply: (obj, thisArg, args) => {
|
||||
if (args.length !== 2 && args.length !== 3) {
|
||||
throw new Error('invalid number of arguments to "ow"')
|
||||
} else {
|
||||
args[1][symbols.validate](args[0], args[2])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return ow
|
||||
}
|
||||
|
||||
module.exports = createOw()
|
||||
26
node_modules/ow-lite/lib/number.js
generated
vendored
Normal file
26
node_modules/ow-lite/lib/number.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
const { func } = require('./symbols')
|
||||
|
||||
const numberPredicates = {
|
||||
positive: (value) => (value > 0),
|
||||
negative: (value) => (value < 0),
|
||||
nonNegative: (value) => (value >= 0),
|
||||
integer: (value) => (value === (value | 0)),
|
||||
|
||||
[func]: {
|
||||
is: (fn) => fn,
|
||||
eq: (v) => (value) => (value === v),
|
||||
gt: (v) => (value) => (value > v),
|
||||
gte: (v) => (value) => (value >= v),
|
||||
lt: (v) => (value) => (value < v),
|
||||
lte: (v) => (value) => (value <= v)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
predicates: numberPredicates,
|
||||
validator: (value) => {
|
||||
return typeof value === 'number'
|
||||
}
|
||||
}
|
||||
26
node_modules/ow-lite/lib/object.js
generated
vendored
Normal file
26
node_modules/ow-lite/lib/object.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
const { func } = require('./symbols')
|
||||
|
||||
const objectPredicates = {
|
||||
plain: (value) => {
|
||||
if (typeof value !== 'object') return false
|
||||
|
||||
const proto = Object.getPrototypeOf(value)
|
||||
return proto === null || proto === Object.getPrototypeOf({})
|
||||
},
|
||||
empty: (value) => Object.keys(value).length === 0,
|
||||
nonEmpty: (value) => Object.keys(value).length > 0,
|
||||
|
||||
[func]: {
|
||||
is: (fn) => fn,
|
||||
instanceOf: (v) => (value) => (value instanceof v)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
predicates: objectPredicates,
|
||||
validator: (value) => {
|
||||
return typeof value === 'object'
|
||||
}
|
||||
}
|
||||
26
node_modules/ow-lite/lib/string.js
generated
vendored
Normal file
26
node_modules/ow-lite/lib/string.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
const { func } = require('./symbols')
|
||||
|
||||
const stringPredicates = {
|
||||
empty: (value) => (value === ''),
|
||||
nonEmpty: (value) => (value !== ''),
|
||||
|
||||
[func]: {
|
||||
is: (fn) => fn,
|
||||
eq: (v) => (value) => (value === v),
|
||||
length: (v) => (value) => (value.length === v),
|
||||
minLength: (v) => (value) => (value.length >= v),
|
||||
maxLength: (v) => (value) => (value.length <= v),
|
||||
matches: (v) => (value) => v.test(value),
|
||||
startsWith: (v) => (value) => value.startsWith(v),
|
||||
endsWith: (v) => (value) => value.endsWith(v)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
predicates: stringPredicates,
|
||||
validator: (value) => {
|
||||
return typeof value === 'string'
|
||||
}
|
||||
}
|
||||
4
node_modules/ow-lite/lib/symbols.js
generated
vendored
Normal file
4
node_modules/ow-lite/lib/symbols.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
exports.func = Symbol('func')
|
||||
exports.validate = Symbol('validate')
|
||||
66
node_modules/ow-lite/package.json
generated
vendored
Normal file
66
node_modules/ow-lite/package.json
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"_from": "ow-lite@^0.0.2",
|
||||
"_id": "ow-lite@0.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-359QDmdAtlkKHpqWVzDUmo61l9E=",
|
||||
"_location": "/ow-lite",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "ow-lite@^0.0.2",
|
||||
"name": "ow-lite",
|
||||
"escapedName": "ow-lite",
|
||||
"rawSpec": "^0.0.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.0.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/random"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ow-lite/-/ow-lite-0.0.2.tgz",
|
||||
"_shasum": "df9f500e6740b6590a1e9a965730d49a8eb597d1",
|
||||
"_spec": "ow-lite@^0.0.2",
|
||||
"_where": "/home/bo_wsl/code/api/node_modules/random",
|
||||
"author": {
|
||||
"name": "Travis Fischer",
|
||||
"email": "travis@automagical.ai"
|
||||
},
|
||||
"ava": {
|
||||
"require": [
|
||||
"esm"
|
||||
]
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/transitive-bullshit/ow-lite/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Lightweight replacement for the ow validation library meant for browser usage.",
|
||||
"devDependencies": {
|
||||
"ava": "^0.25.0",
|
||||
"esm": "^3.0.49",
|
||||
"standard": "^11.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"homepage": "https://github.com/transitive-bullshit/ow-lite#readme",
|
||||
"keywords": [
|
||||
"ow",
|
||||
"browser",
|
||||
"shim",
|
||||
"lite"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "ow-lite",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/transitive-bullshit/ow-lite.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "ava -v && standard"
|
||||
},
|
||||
"version": "0.0.2"
|
||||
}
|
||||
45
node_modules/ow-lite/readme.md
generated
vendored
Normal file
45
node_modules/ow-lite/readme.md
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
# ow-lite
|
||||
|
||||
> Lightweight replacement for the [ow](https://github.com/sindresorhus/ow) validation library meant for browser usage.
|
||||
|
||||
[](https://www.npmjs.com/package/ow-lite) [](https://travis-ci.com/transitive-bullshit/ow-lite) [](https://standardjs.com)
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install --save ow-lite
|
||||
```
|
||||
|
||||
## Why
|
||||
|
||||
`ow-lite` supports 98% of practical `ow` usage and is **30x smaller**, which is really important for **browser usage**.
|
||||
|
||||
| Library | Size | Minified | GZip |
|
||||
|:---------------|:----------|:---------|:--------|
|
||||
| `ow@0.5.0` | 119.61kb | 65.95kb | 17.58kb |
|
||||
| `ow-lite` | 6kb | 2.2kb | 903b |
|
||||
|
||||
|
||||
`ow-lite` has the following drawbacks:
|
||||
|
||||
- less verbose error messages
|
||||
- less support for uncommon types and predicate methods
|
||||
|
||||
## Usage
|
||||
|
||||
You may use `ow-lite` as a mostly drop-in replacement for `ow`. It supports the following types:
|
||||
|
||||
- number
|
||||
- string
|
||||
- object
|
||||
|
||||
Webpack's [resolve.alias](https://webpack.js.org/configuration/resolve/#resolve-alias) is a solid option for replacing `ow` with `ow-lite` at build time. See also [ow-shim](https://github.com/transitive-bullshit/ow-shim) if you want to replace `ow` usage with noops in production.
|
||||
|
||||
## Related
|
||||
|
||||
- [ow](https://github.com/sindresorhus/ow) - Function argument validation for humans.
|
||||
- [ow-shim](https://github.com/transitive-bullshit/ow-shim) - Drop-in replacement to make the ow validation library a noop in production.
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Travis Fischer](https://github.com/transitive-bullshit)
|
||||
83
node_modules/ow-lite/test/number.js
generated
vendored
Normal file
83
node_modules/ow-lite/test/number.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
import test from 'ava'
|
||||
import m from '..'
|
||||
|
||||
test('number', t => {
|
||||
t.notThrows(() => m(1, m.number))
|
||||
t.notThrows(() => m(1, m.number))
|
||||
t.throws(() => m('12', m.number))
|
||||
t.throws(() => m('12', m.number, 'foo'))
|
||||
})
|
||||
|
||||
test('number.gt', t => {
|
||||
t.notThrows(() => m(10, m.number.gt(5)))
|
||||
t.notThrows(() => m(10, m.number.gt(9)))
|
||||
t.throws(() => m(10, m.number.gt(10)))
|
||||
t.throws(() => m(10, m.number.gt(11)))
|
||||
t.throws(() => m(10, m.number.gt(20)))
|
||||
})
|
||||
|
||||
test('number.gte', t => {
|
||||
t.notThrows(() => m(10, m.number.gte(5)))
|
||||
t.notThrows(() => m(10, m.number.gte(10)))
|
||||
t.throws(() => m(10, m.number.gte(11)))
|
||||
t.throws(() => m(10, m.number.gte(20)))
|
||||
})
|
||||
|
||||
test('number.lt', t => {
|
||||
t.notThrows(() => m(10, m.number.lt(20)))
|
||||
t.notThrows(() => m(10, m.number.lt(11)))
|
||||
t.throws(() => m(10, m.number.lt(10)))
|
||||
t.throws(() => m(10, m.number.lt(9)))
|
||||
t.throws(() => m(10, m.number.lt(0)))
|
||||
})
|
||||
|
||||
test('number.lte', t => {
|
||||
t.notThrows(() => m(10, m.number.lte(20)))
|
||||
t.notThrows(() => m(10, m.number.lte(10)))
|
||||
t.throws(() => m(10, m.number.lte(9)))
|
||||
t.throws(() => m(10, m.number.lte(0)))
|
||||
})
|
||||
|
||||
test('number.eq', t => {
|
||||
t.notThrows(() => m(10, m.number.eq(10)))
|
||||
t.throws(() => m(10, m.number.eq(5)))
|
||||
})
|
||||
|
||||
test('number.integer', t => {
|
||||
t.notThrows(() => m(10, m.number.integer))
|
||||
t.throws(() => m(10.1, m.number.integer))
|
||||
})
|
||||
|
||||
test('number.positive', t => {
|
||||
t.notThrows(() => m(1, m.number.positive))
|
||||
t.throws(() => m(-1, m.number.positive))
|
||||
})
|
||||
|
||||
test('number.negative', t => {
|
||||
t.notThrows(() => m(-1, m.number.negative))
|
||||
t.throws(() => m(1, m.number.negative))
|
||||
})
|
||||
|
||||
/*
|
||||
test('number.finite', t => {
|
||||
t.notThrows(() => m(10, m.number.finite))
|
||||
t.throws(() => m(Infinity, m.number.finite), 'Expected number to be finite, got Infinity')
|
||||
})
|
||||
|
||||
test('number.infinite', t => {
|
||||
t.notThrows(() => m(Infinity, m.number.infinite))
|
||||
t.throws(() => m(10, m.number.infinite), 'Expected number to be infinite, got 10')
|
||||
})
|
||||
|
||||
test('number.inRange', t => {
|
||||
t.notThrows(() => m(10, m.number.inRange(0, 20)))
|
||||
t.notThrows(() => m(10, m.number.inRange(10, 20)))
|
||||
t.notThrows(() => m(10, m.number.inRange(0, 10)))
|
||||
t.notThrows(() => m(10, m.number.inRange(0, 10)))
|
||||
t.notThrows(() => m(10, m.number.inRange(0, 10)))
|
||||
t.throws(() => m(10, m.number.inRange(0, 9)), 'Expected number to be in range [0..9], got 10')
|
||||
t.throws(() => m(10, m.number.inRange(0, 9), 'foo'), 'Expected number `foo` to be in range [0..9], got 10')
|
||||
t.throws(() => m(10, m.number.inRange(0, 9), 'foo'), 'Expected number `foo` to be in range [0..9], got 10')
|
||||
t.throws(() => m(10, m.number.inRange(11, 20)), 'Expected number to be in range [11..20], got 10')
|
||||
})
|
||||
*/
|
||||
90
node_modules/ow-lite/test/object.js
generated
vendored
Normal file
90
node_modules/ow-lite/test/object.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
import test from 'ava'
|
||||
import m from '..'
|
||||
|
||||
class Unicorn {}
|
||||
|
||||
test('object', t => {
|
||||
t.notThrows(() => m({}, m.object))
|
||||
t.notThrows(() => m({}, m.object))
|
||||
t.notThrows(() => m(new Error('foo'), m.object))
|
||||
t.throws(() => m('foo', m.object))
|
||||
t.throws(() => m('foo', m.object))
|
||||
t.throws(() => m(1, m.object))
|
||||
})
|
||||
|
||||
test('object.plain', t => {
|
||||
t.notThrows(() => m({}, m.object.plain))
|
||||
t.notThrows(() => m({}, m.object.plain))
|
||||
t.notThrows(() => m({}, m.object.plain))
|
||||
t.throws(() => m(new Error('foo'), m.object.plain))
|
||||
t.throws(() => m(new Error('foo'), m.object.plain))
|
||||
t.throws(() => m(new Error('foo'), m.object.plain))
|
||||
})
|
||||
|
||||
test('object.empty', t => {
|
||||
t.notThrows(() => m({}, m.object.empty))
|
||||
t.throws(() => m({unicorn: '🦄'}, m.object.empty))
|
||||
})
|
||||
|
||||
test('object.nonEmpty', t => {
|
||||
t.notThrows(() => m({unicorn: '🦄'}, m.object.nonEmpty))
|
||||
t.throws(() => m({}, m.object.nonEmpty))
|
||||
})
|
||||
|
||||
test('object.instanceOf', t => {
|
||||
t.notThrows(() => m(new Error('🦄'), m.object.instanceOf(Error)))
|
||||
t.notThrows(() => m(new Unicorn(), m.object.instanceOf(Unicorn)))
|
||||
t.throws(() => m(new Unicorn(), m.object.instanceOf(Error)))
|
||||
t.throws(() => m(new Unicorn(), m.object.instanceOf(Error)))
|
||||
t.throws(() => m(new Error('🦄'), m.object.instanceOf(Unicorn)))
|
||||
t.throws(() => m({unicorn: '🦄'}, m.object.instanceOf(Unicorn)))
|
||||
})
|
||||
|
||||
/*
|
||||
test('object.valuesOfType', t => {
|
||||
t.notThrows(() => m({unicorn: '🦄'}, m.object.valuesOfType(m.string)))
|
||||
t.notThrows(() => m({unicorn: '🦄', rainbow: '🌈'}, m.object.valuesOfType(m.string)))
|
||||
t.notThrows(() => m({unicorn: 1, rainbow: 2}, m.object.valuesOfType(m.number)))
|
||||
t.notThrows(() => m({unicorn: 1, rainbow: 2}, m.object.valuesOfType(m.number)))
|
||||
t.throws(() => m({unicorn: '🦄', rainbow: 2}, m.object.valuesOfType(m.string)), '(object) Expected argument to be of type `string` but received type `number`')
|
||||
t.throws(() => m({unicorn: '🦄', rainbow: 2}, m.object.valuesOfType(m.string)), '(object `foo`) Expected argument to be of type `string` but received type `number`')
|
||||
t.throws(() => m({unicorn: '🦄', rainbow: 2}, m.object.valuesOfType(m.string)), '(object `foo`) Expected `bar` to be of type `string` but received type `number`')
|
||||
t.throws(() => m({unicorn: 'a', rainbow: 'b'}, m.object.valuesOfType(m.string.minLength(2))), '(object) Expected string to have a minimum length of `2`, got `a`')
|
||||
})
|
||||
|
||||
test('object.valuesOfTypeDeep', t => {
|
||||
t.notThrows(() => m({unicorn: '🦄'}, m.object.deepValuesOfType(m.string)))
|
||||
t.notThrows(() => m({unicorn: '🦄', rainbow: '🌈'}, m.object.deepValuesOfType(m.string)))
|
||||
t.notThrows(() => m({unicorn: {key: '🦄', value: '🌈'}}, m.object.deepValuesOfType(m.string)))
|
||||
t.notThrows(() => m({a: {b: {c: {d: 1}, e: 2}, f: 3}}, m.object.deepValuesOfType(m.number)))
|
||||
t.notThrows(() => m({a: {b: {c: {d: 1}, e: 2}, f: 3}}, m.object.deepValuesOfType(m.number)))
|
||||
t.throws(() => m({unicorn: {key: '🦄', value: 1}}, m.object.deepValuesOfType(m.string)), '(object) Expected argument to be of type `string` but received type `number`')
|
||||
t.throws(() => m({unicorn: {key: '🦄', value: 1}}, m.object.deepValuesOfType(m.string)), '(object `foo`) Expected argument to be of type `string` but received type `number`')
|
||||
t.throws(() => m({unicorn: {key: '🦄', value: 1}}, m.object.deepValuesOfType(m.string)), '(object `foo`) Expected `bar` to be of type `string` but received type `number`')
|
||||
t.throws(() => m({a: {b: {c: {d: 1}, e: '2'}, f: 3}}, m.object.deepValuesOfType(m.number)), '(object) Expected argument to be of type `number` but received type `string`')
|
||||
})
|
||||
|
||||
test('object.deepEqual', t => {
|
||||
t.notThrows(() => m({unicorn: '🦄'}, m.object.deepEqual({unicorn: '🦄'})))
|
||||
t.notThrows(() => m({unicorn: '🦄', rain: {bow: '🌈'}}, m.object.deepEqual({unicorn: '🦄', rain: {bow: '🌈'}})))
|
||||
t.throws(() => m({unicorn: '🦄'}, m.object.deepEqual({rainbow: '🌈'})))
|
||||
})
|
||||
|
||||
test('object.hasKeys', t => {
|
||||
t.notThrows(() => m({unicorn: '🦄'}, m.object.hasKeys('unicorn')))
|
||||
t.notThrows(() => m({unicorn: {value: '🦄'}}, m.object.hasKeys('unicorn')))
|
||||
t.notThrows(() => m({unicorn: {value: '🦄'}}, m.object.hasKeys('unicorn.value')))
|
||||
t.notThrows(() => m({unicorn: '🦄', rainbow: '🌈'}, m.object.hasKeys('unicorn', 'rainbow')))
|
||||
t.throws(() => m({unicorn: '🦄'}, m.object.hasKeys('unicorn', 'rainbow')))
|
||||
t.throws(() => m({unicorn: {value: '🦄'}}, m.object.hasKeys('unicorn.foo')))
|
||||
})
|
||||
|
||||
test('object.hasAnyKeys', t => {
|
||||
t.notThrows(() => m({unicorn: '🦄'}, m.object.hasAnyKeys('unicorn', 'rainbow', 'foo.bar')))
|
||||
t.notThrows(() => m({unicorn: {value: '🦄'}}, m.object.hasAnyKeys('unicorn', 'rainbow')))
|
||||
t.notThrows(() => m({unicorn: {value: '🦄'}}, m.object.hasAnyKeys('unicorn.value', 'rainbow')))
|
||||
t.notThrows(() => m({unicorn: '🦄', rainbow: '🌈'}, m.object.hasAnyKeys('unicorn')))
|
||||
t.throws(() => m({unicorn: '🦄'}, m.object.hasAnyKeys('foo')))
|
||||
t.throws(() => m({unicorn: '🦄'}, m.object.hasAnyKeys('unicorn.value')))
|
||||
})
|
||||
*/
|
||||
82
node_modules/ow-lite/test/string.js
generated
vendored
Normal file
82
node_modules/ow-lite/test/string.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
import test from 'ava'
|
||||
import m from '..'
|
||||
|
||||
test('string', t => {
|
||||
t.notThrows(() => m('foo', m.string))
|
||||
t.notThrows(() => m('foo', m.string))
|
||||
t.throws(() => m(12, m.string))
|
||||
t.throws(() => m(12, m.string))
|
||||
})
|
||||
|
||||
test('string.length', t => {
|
||||
t.notThrows(() => m('foo', m.string.length(3)))
|
||||
t.notThrows(() => m('foobar', m.string.length(6)))
|
||||
t.notThrows(() => m('bar', m.string.length(3)))
|
||||
t.notThrows(() => m('bar', m.string.length(3)))
|
||||
t.throws(() => m('foo', m.string.length(4)))
|
||||
t.throws(() => m('foo', m.string.length(4)))
|
||||
t.throws(() => m('foo', m.string.length(4)))
|
||||
})
|
||||
|
||||
test('string.minLength', t => {
|
||||
t.notThrows(() => m('foo', m.string.minLength(2)))
|
||||
t.notThrows(() => m('foo', m.string.minLength(3)))
|
||||
t.throws(() => m('foo', m.string.minLength(4)))
|
||||
})
|
||||
|
||||
test('string.maxLength', t => {
|
||||
t.notThrows(() => m('foo', m.string.maxLength(3)))
|
||||
t.notThrows(() => m('foo', m.string.maxLength(5)))
|
||||
t.throws(() => m('foo', m.string.maxLength(2)))
|
||||
})
|
||||
|
||||
test('string.matches', t => {
|
||||
t.notThrows(() => m('foo', m.string.matches(/^f.o$/)))
|
||||
t.notThrows(() => m('Foo', m.string.matches(/^f.o$/i)))
|
||||
t.throws(() => m('Foo', m.string.matches(/^f.o$/)))
|
||||
t.throws(() => m('bar', m.string.matches(/^f.o$/i)))
|
||||
})
|
||||
|
||||
test('string.startsWith', t => {
|
||||
t.notThrows(() => m('foo', m.string.startsWith('fo')))
|
||||
t.notThrows(() => m('foo', m.string.startsWith('f')))
|
||||
t.throws(() => m('foo', m.string.startsWith('oo')))
|
||||
t.throws(() => m('foo', m.string.startsWith('b')))
|
||||
})
|
||||
|
||||
test('string.endsWith', t => {
|
||||
t.notThrows(() => m('foo', m.string.endsWith('oo')))
|
||||
t.notThrows(() => m('foo', m.string.endsWith('o')))
|
||||
t.throws(() => m('foo', m.string.endsWith('fo')))
|
||||
t.throws(() => m('foo', m.string.endsWith('ar')))
|
||||
})
|
||||
|
||||
test('string.empty', t => {
|
||||
t.notThrows(() => m('', m.string.empty))
|
||||
t.throws(() => m('foo', m.string.empty))
|
||||
})
|
||||
|
||||
test('string.nonEmpty', t => {
|
||||
t.notThrows(() => m('foo', m.string.nonEmpty))
|
||||
t.throws(() => m('', m.string.nonEmpty))
|
||||
})
|
||||
|
||||
test('string.eq', t => {
|
||||
t.notThrows(() => m('foo', m.string.eq('foo')))
|
||||
t.throws(() => m('bar', m.string.eq('foo')))
|
||||
})
|
||||
|
||||
/*
|
||||
test('string.includes', t => {
|
||||
t.notThrows(() => m('foo', m.string.includes('fo')))
|
||||
t.throws(() => m('foo', m.string.includes('bar')))
|
||||
})
|
||||
|
||||
test('string.oneOf', t => {
|
||||
t.notThrows(() => m('foo', m.string.oneOf(['foo', 'bar'])))
|
||||
t.throws(() => m('foo', m.string.oneOf(['unicorn', 'rainbow'])))
|
||||
t.throws(() => m('foo', m.string.oneOf(['unicorn', 'rainbow'])))
|
||||
t.throws(() => m('foo', m.string.oneOf(['a', 'b', 'c', 'd', 'e'])))
|
||||
t.throws(() => m('foo', m.string.oneOf(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13'])))
|
||||
})
|
||||
*/
|
||||
Reference in New Issue
Block a user