Skip to content

Commit

Permalink
Merge branch 'latest' into n4s-endsWith
Browse files Browse the repository at this point in the history
  • Loading branch information
syncush committed Sep 23, 2020
2 parents 7677fea + a424282 commit e26d0eb
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

# Vest 🦺 Declarative Validation Testing

![Github Stars](https://githubbadges.com/star.svg?user=ealush&repo=vest&style=flat)
![Npm downloads](https://img.shields.io/npm/dt/vest?label=Downloads&logo=npm)

[![npm version](https://badge.fury.io/js/vest.svg)](https://badge.fury.io/js/vest) [![Build Status](https://travis-ci.org/ealush/vest.svg?branch=latest)](https://travis-ci.org/ealush/vest) [![Known Vulnerabilities](https://snyk.io/test/npm/vest/badge.svg)](https://snyk.io/test/npm/vest)
![minifiedSize](https://img.shields.io/bundlephobia/min/vest?color=blue&logo=npm)

![Join discord](https://img.shields.io/discord/757686103292641312?label=Join%20Discord&logo=discord&logoColor=green)

- [Documentation homepage](https://ealush.github.io/vest)
- **Try vest live**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"onchange": "^7.0.2",
"prettier": "2.1.2",
"pretty-quick": "^3.0.2",
"rollup": "^2.27.1",
"rollup": "^2.28.1",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
Expand Down
62 changes: 62 additions & 0 deletions packages/n4s/docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ Enforce rules are functions that allow you to test your data against different c
- [isNotNumber](#isnotnumber)
- [isNaN](#isNaN)
- [isNotNaN](#isNotNaN)
- [isNull](#isnull)
- [isNotNull](#isnotnull)
- [isString](#isstring)
- [isNotString](#isnotstring)
- [isUndefined](#isundefined)
- [isOdd](#isodd)
- [isEven](#iseven)

Expand Down Expand Up @@ -885,6 +888,45 @@ enforce('A' / 'B').isNaN();
// throws
```


## isNull

### Description

Enforces that a specified value is `null`.

### Usage examples:

```js
enforce(null).isNull();
// passes
```

```js
enforce(undefined).isNull();
enforce(true).isNull();
// throws
```

## isNotNull

### Description

Reverse implementation of `isNull`. Checks that a value is not null.

### Usage examples:

```js
enforce("hello").isNull();
enforce(200).isNull();
// passes
```

```js
enforce(null).isNull();
// throws
```

## isString

### Description
Expand Down Expand Up @@ -923,6 +965,26 @@ enforce(['hello']).isNotString();
// passes
```

## isUndefined

### Description

Enforces that a given value is (`===`) undefined.

### Usage examples:

```js
enforce().isUndefined();
enforce(undefined).isUndefined();
// passes
```

```js
enforce(null).isUndefined();
enforce(true).isUndefined();
// throws
```

## isOdd

### Description
Expand Down
4 changes: 4 additions & 0 deletions packages/n4s/src/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import isArray from './isArray';
import isEmpty from './isEmpty';
import isEven from './isEven';
import isNaN from './isNaN';
import isNull from './isNull';
import isNumber from './isNumber';
import isNumeric from './isNumeric';
import isOdd from './isOdd';
import isString from './isString';
import isTruthy from './isTruthy';
import isUndefined from './isUndefined';
import lengthEquals from './lengthEquals';
import lessThan from './lessThan';
import lessThanOrEquals from './lessThanOrEquals';
Expand All @@ -32,11 +34,13 @@ const rules = {
isEmpty,
isEven,
isNaN,
isNull,
isNumber,
isNumeric,
isOdd,
isString,
isTruthy,
isUndefined,
lengthEquals,
lessThan,
lessThanOrEquals,
Expand Down
7 changes: 7 additions & 0 deletions packages/n4s/src/rules/isNull/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function isNull(value) {
return value === null;
}

isNull.negativeForm = 'isNotNull';

export default isNull;
29 changes: 29 additions & 0 deletions packages/n4s/src/rules/isNull/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import isNull from '.';

describe('Tests isNull rule', () => {
it('Should return true for `null` value', () => {
expect(isNull(null)).toBe(true);
});

it.each([
undefined,
NaN,
false,
true,
Object,
Array(0),
'',
' ',
0,
1,
'0',
'1',
() => {},
])('Should return false for %s value', v => {
expect(isNull(v)).toBe(false);
});

it('Should expose negativeForm property', () => {
expect(isNull.negativeForm).toBe('isNotNull');
});
});
7 changes: 7 additions & 0 deletions packages/n4s/src/rules/isUndefined/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function isUndefined(value) {
return value === undefined;
}

isUndefined.negativeForm = 'isNotUndefined';

export default isUndefined;
30 changes: 30 additions & 0 deletions packages/n4s/src/rules/isUndefined/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import isUndefined from '.';

describe('Tests isUndefined rule', () => {
it('Should return true for `undefined` value', () => {
expect(isUndefined(undefined)).toBe(true);
expect(isUndefined()).toBe(true);
});

it.each([
null,
NaN,
false,
true,
Object,
Array(0),
'',
' ',
0,
1,
'0',
'1',
() => {},
])('Should return false for %s value', v => {
expect(isUndefined(v)).toBe(false);
});

it('Should expose negativeForm property', () => {
expect(isUndefined.negativeForm).toBe('isNotUndefined');
});
});
4 changes: 4 additions & 0 deletions packages/n4s/src/rules/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ const negativeRules = [
'isNotNumber',
'isNotNumeric',
'isNotString',
'isNotUndefined',
'lengthNotEquals',
'notEquals',
'notInside',
'notMatches',
'doesNotEndWith',
'numberNotEquals',
'isNotNull',
];

const positiveRules = [
Expand All @@ -44,6 +46,7 @@ const positiveRules = [
'isTruthy',
'isFalsy',
'isString',
'isUndefined',
'lengthEquals',
'lessThan',
'lessThanOrEquals',
Expand All @@ -55,6 +58,7 @@ const positiveRules = [
'numberEquals',
'shorterThan',
'shorterThanOrEquals',
'isNull',
'endsWith'
];

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5130,10 +5130,10 @@ rollup-pluginutils@^2.6.0, rollup-pluginutils@^2.8.1:
dependencies:
estree-walker "^0.6.1"

rollup@^2.27.1:
version "2.27.1"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.27.1.tgz#372744e1d36eba0fd942d997600c2fc2ca266305"
integrity sha512-GiWHQvnmMgBktSpY/1+nrGpwPsTw4b9P28og2uedfeq4JZ16rzAmnQ5Pm/E0/BEmDNia1ZbY7+qu3nBgNa19Hg==
rollup@^2.28.1:
version "2.28.1"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.28.1.tgz#ceedca3cdb013c2fa8f22f958a29c203368159ea"
integrity sha512-DOtVoqOZt3+FjPJWLU8hDIvBjUylc9s6IZvy76XklxzcLvAQLtVAG/bbhsMhcWnYxC0TKKcf1QQ/tg29zeID0Q==
optionalDependencies:
fsevents "~2.1.2"

Expand Down

0 comments on commit e26d0eb

Please sign in to comment.