vest-utils 0.0.1-rc → 0.0.4-dev-afe5de
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/vest-utils.development.js +348 -0
- package/dist/cjs/vest-utils.production.js +1 -1
- package/dist/es/vest-utils.development.js +305 -0
- package/dist/es/vest-utils.production.js +1 -1
- package/dist/umd/vest-utils.development.js +352 -4
- package/dist/umd/vest-utils.production.js +1 -1
- package/package.json +4 -662
- package/src/{exports/__tests__ → __tests__}/bindNot.test.ts +1 -1
- package/src/{exports/__tests__ → __tests__}/bus.test.ts +0 -0
- package/src/{exports/__tests__ → __tests__}/cache.test.ts +1 -1
- package/src/{exports/__tests__ → __tests__}/defaultTo.test.ts +1 -1
- package/src/{exports/__tests__ → __tests__}/genId.test.ts +0 -0
- package/src/__tests__/greaterThan.test.ts +59 -0
- package/src/{exports/__tests__ → __tests__}/invariant.test.ts +1 -1
- package/src/__tests__/isArray.test.ts +15 -0
- package/src/__tests__/isNull.test.ts +25 -0
- package/src/__tests__/isNumeric.test.ts +26 -0
- package/src/__tests__/isUndefined.test.ts +26 -0
- package/src/__tests__/lengthEquals.test.ts +56 -0
- package/src/__tests__/longerThan.test.ts +56 -0
- package/src/{exports/__tests__ → __tests__}/mapFirst.test.ts +1 -1
- package/src/__tests__/numberEquals.test.ts +59 -0
- package/src/{exports/__tests__ → __tests__}/optionalFunctionValue.test.ts +1 -1
- package/src/{exports/__tests__ → __tests__}/partition.test.ts +1 -1
- package/src/{exports/__tests__ → __tests__}/throwError.test.ts +1 -1
- package/src/{exports/asArray.ts → asArray.ts} +0 -0
- package/src/{exports/assign.ts → assign.ts} +0 -0
- package/src/{exports/bindNot.ts → bindNot.ts} +0 -0
- package/src/{exports/bus.ts → bus.ts} +0 -0
- package/src/{exports/cache.ts → cache.ts} +0 -0
- package/src/{exports/callEach.ts → callEach.ts} +0 -0
- package/src/{exports/defaultTo.ts → defaultTo.ts} +0 -0
- package/src/{exports/throwError.ts → deferThrow.ts} +1 -1
- package/src/{exports/either.ts → either.ts} +0 -0
- package/src/{exports/genId.ts → genId.ts} +0 -0
- package/src/globals.d.ts +3 -3
- package/src/greaterThan.ts +8 -0
- package/src/{exports/hasOwnProperty.ts → hasOwnProperty.ts} +0 -0
- package/src/{exports/invariant.ts → invariant.ts} +0 -0
- package/src/isArrayValue.ts +11 -0
- package/src/isBooleanValue.ts +3 -0
- package/src/isEmpty.ts +17 -0
- package/src/{exports/isFunction.ts → isFunction.ts} +0 -0
- package/src/isNull.ts +7 -0
- package/src/{exports/isNullish.ts → isNullish.ts} +1 -2
- package/src/isNumeric.ts +11 -0
- package/src/isPositive.ts +5 -0
- package/src/{exports/isPromise.ts → isPromise.ts} +0 -0
- package/src/isStringValue.ts +3 -0
- package/src/isUndefined.ts +7 -0
- package/src/{exports/last.ts → last.ts} +0 -0
- package/src/lengthEquals.ts +11 -0
- package/src/longerThan.ts +8 -0
- package/src/{exports/mapFirst.ts → mapFirst.ts} +0 -0
- package/src/{exports/nestedArray.ts → nestedArray.ts} +2 -3
- package/src/numberEquals.ts +11 -0
- package/src/{exports/optionalFunctionValue.ts → optionalFunctionValue.ts} +1 -1
- package/src/{exports/partition.ts → partition.ts} +0 -0
- package/src/vest-utils.ts +32 -0
- package/types/vest-utils.d.ts +96 -1
- package/asArray/package.json +0 -9
- package/assign/package.json +0 -9
- package/bindNot/package.json +0 -9
- package/bus/package.json +0 -9
- package/cache/package.json +0 -9
- package/callEach/package.json +0 -9
- package/defaultTo/package.json +0 -9
- package/dist/cjs/asArray.development.js +0 -7
- package/dist/cjs/asArray.js +0 -7
- package/dist/cjs/asArray.production.js +0 -1
- package/dist/cjs/assign.development.js +0 -5
- package/dist/cjs/assign.js +0 -7
- package/dist/cjs/assign.production.js +0 -1
- package/dist/cjs/bindNot.development.js +0 -13
- package/dist/cjs/bindNot.js +0 -7
- package/dist/cjs/bindNot.production.js +0 -1
- package/dist/cjs/bus.development.js +0 -27
- package/dist/cjs/bus.js +0 -7
- package/dist/cjs/bus.production.js +0 -1
- package/dist/cjs/cache.development.js +0 -72
- package/dist/cjs/cache.js +0 -7
- package/dist/cjs/cache.production.js +0 -1
- package/dist/cjs/callEach.development.js +0 -7
- package/dist/cjs/callEach.js +0 -7
- package/dist/cjs/callEach.production.js +0 -1
- package/dist/cjs/defaultTo.development.js +0 -20
- package/dist/cjs/defaultTo.js +0 -7
- package/dist/cjs/defaultTo.production.js +0 -1
- package/dist/cjs/either.development.js +0 -7
- package/dist/cjs/either.js +0 -7
- package/dist/cjs/either.production.js +0 -1
- package/dist/cjs/genId.development.js +0 -10
- package/dist/cjs/genId.js +0 -7
- package/dist/cjs/genId.production.js +0 -1
- package/dist/cjs/hasOwnProperty.development.js +0 -10
- package/dist/cjs/hasOwnProperty.js +0 -7
- package/dist/cjs/hasOwnProperty.production.js +0 -1
- package/dist/cjs/invariant.development.js +0 -36
- package/dist/cjs/invariant.js +0 -7
- package/dist/cjs/invariant.production.js +0 -1
- package/dist/cjs/isBooleanValue.development.js +0 -9
- package/dist/cjs/isBooleanValue.js +0 -7
- package/dist/cjs/isBooleanValue.production.js +0 -1
- package/dist/cjs/isFunction.development.js +0 -7
- package/dist/cjs/isFunction.js +0 -7
- package/dist/cjs/isFunction.production.js +0 -1
- package/dist/cjs/isNullish.development.js +0 -37
- package/dist/cjs/isNullish.js +0 -7
- package/dist/cjs/isNullish.production.js +0 -1
- package/dist/cjs/isPromise.development.js +0 -11
- package/dist/cjs/isPromise.js +0 -7
- package/dist/cjs/isPromise.production.js +0 -1
- package/dist/cjs/isStringValue.development.js +0 -9
- package/dist/cjs/isStringValue.js +0 -7
- package/dist/cjs/isStringValue.production.js +0 -1
- package/dist/cjs/last.development.js +0 -12
- package/dist/cjs/last.js +0 -7
- package/dist/cjs/last.production.js +0 -1
- package/dist/cjs/mapFirst.development.js +0 -20
- package/dist/cjs/mapFirst.js +0 -7
- package/dist/cjs/mapFirst.production.js +0 -1
- package/dist/cjs/nestedArray.development.js +0 -99
- package/dist/cjs/nestedArray.js +0 -7
- package/dist/cjs/nestedArray.production.js +0 -1
- package/dist/cjs/optionalFunctionValue.development.js +0 -15
- package/dist/cjs/optionalFunctionValue.js +0 -7
- package/dist/cjs/optionalFunctionValue.production.js +0 -1
- package/dist/cjs/partition.development.js +0 -10
- package/dist/cjs/partition.js +0 -7
- package/dist/cjs/partition.production.js +0 -1
- package/dist/cjs/throwError.development.js +0 -11
- package/dist/cjs/throwError.js +0 -7
- package/dist/cjs/throwError.production.js +0 -1
- package/dist/es/asArray.development.js +0 -5
- package/dist/es/asArray.production.js +0 -1
- package/dist/es/assign.development.js +0 -3
- package/dist/es/assign.production.js +0 -1
- package/dist/es/bindNot.development.js +0 -11
- package/dist/es/bindNot.production.js +0 -1
- package/dist/es/bus.development.js +0 -23
- package/dist/es/bus.production.js +0 -1
- package/dist/es/cache.development.js +0 -66
- package/dist/es/cache.production.js +0 -1
- package/dist/es/callEach.development.js +0 -5
- package/dist/es/callEach.production.js +0 -1
- package/dist/es/defaultTo.development.js +0 -18
- package/dist/es/defaultTo.production.js +0 -1
- package/dist/es/either.development.js +0 -5
- package/dist/es/either.production.js +0 -1
- package/dist/es/genId.development.js +0 -8
- package/dist/es/genId.production.js +0 -1
- package/dist/es/hasOwnProperty.development.js +0 -8
- package/dist/es/hasOwnProperty.production.js +0 -1
- package/dist/es/invariant.development.js +0 -32
- package/dist/es/invariant.production.js +0 -1
- package/dist/es/isBooleanValue.development.js +0 -5
- package/dist/es/isBooleanValue.production.js +0 -1
- package/dist/es/isFunction.development.js +0 -5
- package/dist/es/isFunction.production.js +0 -1
- package/dist/es/isNullish.development.js +0 -28
- package/dist/es/isNullish.production.js +0 -1
- package/dist/es/isPromise.development.js +0 -9
- package/dist/es/isPromise.production.js +0 -1
- package/dist/es/isStringValue.development.js +0 -5
- package/dist/es/isStringValue.production.js +0 -1
- package/dist/es/last.development.js +0 -10
- package/dist/es/last.production.js +0 -1
- package/dist/es/mapFirst.development.js +0 -18
- package/dist/es/mapFirst.production.js +0 -1
- package/dist/es/nestedArray.development.js +0 -87
- package/dist/es/nestedArray.production.js +0 -1
- package/dist/es/optionalFunctionValue.development.js +0 -13
- package/dist/es/optionalFunctionValue.production.js +0 -1
- package/dist/es/partition.development.js +0 -8
- package/dist/es/partition.production.js +0 -1
- package/dist/es/throwError.development.js +0 -7
- package/dist/es/throwError.production.js +0 -1
- package/dist/umd/asArray.development.js +0 -13
- package/dist/umd/asArray.production.js +0 -1
- package/dist/umd/assign.development.js +0 -11
- package/dist/umd/assign.production.js +0 -1
- package/dist/umd/bindNot.development.js +0 -19
- package/dist/umd/bindNot.production.js +0 -1
- package/dist/umd/bus.development.js +0 -33
- package/dist/umd/bus.production.js +0 -1
- package/dist/umd/cache.development.js +0 -76
- package/dist/umd/cache.production.js +0 -1
- package/dist/umd/callEach.development.js +0 -13
- package/dist/umd/callEach.production.js +0 -1
- package/dist/umd/defaultTo.development.js +0 -26
- package/dist/umd/defaultTo.production.js +0 -1
- package/dist/umd/either.development.js +0 -13
- package/dist/umd/either.production.js +0 -1
- package/dist/umd/genId.development.js +0 -16
- package/dist/umd/genId.production.js +0 -1
- package/dist/umd/hasOwnProperty.development.js +0 -16
- package/dist/umd/hasOwnProperty.production.js +0 -1
- package/dist/umd/invariant.development.js +0 -42
- package/dist/umd/invariant.production.js +0 -1
- package/dist/umd/isBooleanValue.development.js +0 -15
- package/dist/umd/isBooleanValue.production.js +0 -1
- package/dist/umd/isFunction.development.js +0 -13
- package/dist/umd/isFunction.production.js +0 -1
- package/dist/umd/isNullish.development.js +0 -41
- package/dist/umd/isNullish.production.js +0 -1
- package/dist/umd/isPromise.development.js +0 -17
- package/dist/umd/isPromise.production.js +0 -1
- package/dist/umd/isStringValue.development.js +0 -15
- package/dist/umd/isStringValue.production.js +0 -1
- package/dist/umd/last.development.js +0 -18
- package/dist/umd/last.production.js +0 -1
- package/dist/umd/mapFirst.development.js +0 -26
- package/dist/umd/mapFirst.production.js +0 -1
- package/dist/umd/nestedArray.development.js +0 -103
- package/dist/umd/nestedArray.production.js +0 -1
- package/dist/umd/optionalFunctionValue.development.js +0 -21
- package/dist/umd/optionalFunctionValue.production.js +0 -1
- package/dist/umd/partition.development.js +0 -16
- package/dist/umd/partition.production.js +0 -1
- package/dist/umd/throwError.development.js +0 -17
- package/dist/umd/throwError.production.js +0 -1
- package/either/package.json +0 -9
- package/genId/package.json +0 -9
- package/hasOwnProperty/package.json +0 -9
- package/invariant/package.json +0 -9
- package/isBooleanValue/package.json +0 -9
- package/isFunction/package.json +0 -9
- package/isNullish/package.json +0 -9
- package/isPromise/package.json +0 -9
- package/isStringValue/package.json +0 -9
- package/last/package.json +0 -9
- package/mapFirst/package.json +0 -9
- package/nestedArray/package.json +0 -9
- package/optionalFunctionValue/package.json +0 -9
- package/partition/package.json +0 -9
- package/src/exports/isBooleanValue.ts +0 -3
- package/src/exports/isStringValue.ts +0 -3
- package/throwError/package.json +0 -9
- package/tsconfig.json +0 -6
- package/types/asArray.d.ts +0 -2
- package/types/assign.d.ts +0 -7
- package/types/bindNot.d.ts +0 -2
- package/types/bus.d.ts +0 -9
- package/types/cache.d.ts +0 -9
- package/types/callEach.d.ts +0 -2
- package/types/defaultTo.d.ts +0 -2
- package/types/either.d.ts +0 -2
- package/types/genId.d.ts +0 -5
- package/types/hasOwnProperty.d.ts +0 -5
- package/types/invariant.d.ts +0 -4
- package/types/isBooleanValue.d.ts +0 -2
- package/types/isFunction.d.ts +0 -2
- package/types/isNullish.d.ts +0 -3
- package/types/isPromise.d.ts +0 -2
- package/types/isStringValue.d.ts +0 -2
- package/types/last.d.ts +0 -2
- package/types/mapFirst.d.ts +0 -2
- package/types/nestedArray.d.ts +0 -7
- package/types/optionalFunctionValue.d.ts +0 -2
- package/types/partition.d.ts +0 -5
- package/types/throwError.d.ts +0 -2
- package/types/utilityTypes.d.ts +0 -8
- package/types/vest-utilities.d.ts +0 -1
- package/utilityTypes/package.json +0 -9
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { random, datatype } from 'faker';
|
|
2
|
+
|
|
3
|
+
import { greaterThan } from 'greaterThan';
|
|
4
|
+
|
|
5
|
+
describe('Tests greaterThan rule', () => {
|
|
6
|
+
let arg0;
|
|
7
|
+
|
|
8
|
+
describe('Arguments are numbers', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
arg0 = datatype.number();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('When first argument is larger', () => {
|
|
14
|
+
it('Should return true', () => {
|
|
15
|
+
expect(greaterThan(arg0, arg0 - 1)).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('When first argument is smaller', () => {
|
|
20
|
+
it('Should return true', () => {
|
|
21
|
+
expect(greaterThan(arg0, arg0 + 1)).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('When values are equal', () => {
|
|
26
|
+
it('Should return false', () => {
|
|
27
|
+
expect(greaterThan(arg0, arg0)).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('Arguments are numeric strings', () => {
|
|
33
|
+
describe('When first argument is larger', () => {
|
|
34
|
+
it('Should return true', () => {
|
|
35
|
+
expect(greaterThan(`${arg0}`, `${arg0 - 1}`)).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('When first argument is smaller', () => {
|
|
40
|
+
it('Should return true', () => {
|
|
41
|
+
expect(greaterThan(`${arg0}`, `${arg0 + 1}`)).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('When values are equal', () => {
|
|
46
|
+
it('Should return false', () => {
|
|
47
|
+
expect(greaterThan(arg0, arg0)).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('Arguments are non numeric', () => {
|
|
53
|
+
[random.word(), `${datatype.number()}`.split(''), {}].forEach(element => {
|
|
54
|
+
it('Should return false', () => {
|
|
55
|
+
expect(greaterThan(element, 0)).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isArray } from 'isArrayValue';
|
|
2
|
+
|
|
3
|
+
describe('Tests isArray rule', () => {
|
|
4
|
+
it('Should return true for an empty array', () => {
|
|
5
|
+
expect(isArray([])).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('Should return true for an array with elements', () => {
|
|
9
|
+
expect(isArray([1, 2, 3])).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('Should return false a string', () => {
|
|
13
|
+
expect(isArray('1')).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isNull } from 'isNull';
|
|
2
|
+
|
|
3
|
+
describe('Tests isNull rule', () => {
|
|
4
|
+
it('Should return true for `null` value', () => {
|
|
5
|
+
expect(isNull(null)).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it.each([
|
|
9
|
+
undefined,
|
|
10
|
+
NaN,
|
|
11
|
+
false,
|
|
12
|
+
true,
|
|
13
|
+
Object,
|
|
14
|
+
Array(0),
|
|
15
|
+
'',
|
|
16
|
+
' ',
|
|
17
|
+
0,
|
|
18
|
+
1,
|
|
19
|
+
'0',
|
|
20
|
+
'1',
|
|
21
|
+
Function.prototype,
|
|
22
|
+
])('Should return false for %s value', v => {
|
|
23
|
+
expect(isNull(v)).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isNumeric } from 'isNumeric';
|
|
2
|
+
|
|
3
|
+
const NUMERICS = ['-10', '0', 0xff, '0xFF', '8e5', '3.1415', +10, '0144'];
|
|
4
|
+
|
|
5
|
+
const NON_NUMERICS = [
|
|
6
|
+
'-0x42',
|
|
7
|
+
'7.2acdgs',
|
|
8
|
+
'',
|
|
9
|
+
{},
|
|
10
|
+
NaN,
|
|
11
|
+
null,
|
|
12
|
+
true,
|
|
13
|
+
Infinity,
|
|
14
|
+
undefined,
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
describe('Tests isNumeric rule', () => {
|
|
18
|
+
it('Should return true for numeric values', () => {
|
|
19
|
+
NUMERICS.forEach(value => expect(isNumeric(value)).toBe(true));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('Should return false for non numeric values', () => {
|
|
23
|
+
// @ts-expect-error - testing bad usage
|
|
24
|
+
NON_NUMERICS.forEach(value => expect(isNumeric(value)).toBe(false));
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isUndefined } from 'isUndefined';
|
|
2
|
+
|
|
3
|
+
describe('Tests isUndefined rule', () => {
|
|
4
|
+
it('Should return true for `undefined` value', () => {
|
|
5
|
+
expect(isUndefined(undefined)).toBe(true);
|
|
6
|
+
expect(isUndefined()).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it.each([
|
|
10
|
+
null,
|
|
11
|
+
NaN,
|
|
12
|
+
false,
|
|
13
|
+
true,
|
|
14
|
+
Object,
|
|
15
|
+
Array(0),
|
|
16
|
+
'',
|
|
17
|
+
' ',
|
|
18
|
+
0,
|
|
19
|
+
1,
|
|
20
|
+
'0',
|
|
21
|
+
'1',
|
|
22
|
+
() => undefined,
|
|
23
|
+
])('Should return false for %s value', v => {
|
|
24
|
+
expect(isUndefined(v)).toBe(false);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import faker from 'faker';
|
|
2
|
+
|
|
3
|
+
import { lengthEquals } from 'lengthEquals';
|
|
4
|
+
|
|
5
|
+
describe('Tests lengthEquals rule', () => {
|
|
6
|
+
const length = faker.datatype.number();
|
|
7
|
+
const word = faker.random.word();
|
|
8
|
+
const boolean = faker.datatype.boolean();
|
|
9
|
+
|
|
10
|
+
describe('First argument is array or string', () => {
|
|
11
|
+
describe('When first argument is equal to a given value', () => {
|
|
12
|
+
it('Should return true for an array equal to length', () => {
|
|
13
|
+
expect(lengthEquals(new Array(length), length)).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('Should return true for a string equal to word length', () => {
|
|
17
|
+
expect(lengthEquals(word, word.length)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('When first argument is shorter', () => {
|
|
22
|
+
it('Should return false for an array shorter than length', () => {
|
|
23
|
+
expect(lengthEquals(new Array(length), length + 1)).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('Should return false for a string shorter than word length', () => {
|
|
27
|
+
expect(lengthEquals(word, word.length + 1)).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('When first argument is longer', () => {
|
|
32
|
+
it('Should return false for an array longer than length', () => {
|
|
33
|
+
expect(lengthEquals(new Array(length), length - 1)).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('Should return false for a string longer than word length', () => {
|
|
37
|
+
expect(lengthEquals(word, word.length - 1)).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("First argument isn't array or string", () => {
|
|
43
|
+
it('Should throw error', () => {
|
|
44
|
+
// @ts-expect-error - testing wrong input
|
|
45
|
+
expect(() => lengthEquals(undefined, 0)).toThrow(TypeError);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('Should return false for number argument', () => {
|
|
49
|
+
expect(lengthEquals(length, 0)).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('Should return false for boolean argument', () => {
|
|
53
|
+
expect(lengthEquals(boolean, 0)).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import faker from 'faker';
|
|
2
|
+
|
|
3
|
+
import { longerThan } from 'longerThan';
|
|
4
|
+
|
|
5
|
+
describe('Tests longerThan rule', () => {
|
|
6
|
+
const length = faker.datatype.number();
|
|
7
|
+
const word = faker.random.word();
|
|
8
|
+
const boolean = faker.datatype.boolean();
|
|
9
|
+
|
|
10
|
+
describe('First argument is array or string', () => {
|
|
11
|
+
describe('When first argument is longer', () => {
|
|
12
|
+
it('Should return true for an array longer than length', () => {
|
|
13
|
+
expect(longerThan(new Array(length), length - 1)).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('Should return true for a string longer than word length', () => {
|
|
17
|
+
expect(longerThan(word, word.length - 1)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('When first argument is shorter', () => {
|
|
22
|
+
it('Should return false for an array shorter than length', () => {
|
|
23
|
+
expect(longerThan(new Array(length), length + 1)).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('Should return false for a string shorter than word length', () => {
|
|
27
|
+
expect(longerThan(word, word.length + 1)).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('When first argument is equal to a given value', () => {
|
|
32
|
+
it('Should return false for an array equal to length', () => {
|
|
33
|
+
expect(longerThan(new Array(length), length)).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('Should return false for a string equal to word length', () => {
|
|
37
|
+
expect(longerThan(word, word.length)).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("First argument isn't array or string", () => {
|
|
43
|
+
it('Should throw error', () => {
|
|
44
|
+
// @ts-expect-error - testing wrong input
|
|
45
|
+
expect(() => longerThan(undefined, 0)).toThrow(TypeError);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('Should return false for number argument', () => {
|
|
49
|
+
expect(longerThan(length, 0)).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('Should return false for boolean argument', () => {
|
|
53
|
+
expect(longerThan(boolean, 0)).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { random, datatype } from 'faker';
|
|
2
|
+
|
|
3
|
+
import { numberEquals } from 'numberEquals';
|
|
4
|
+
|
|
5
|
+
describe('Tests numberEquals rule', () => {
|
|
6
|
+
let arg0;
|
|
7
|
+
|
|
8
|
+
describe('Arguments are numbers', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
arg0 = datatype.number();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('When first argument is larger', () => {
|
|
14
|
+
it('Should return false', () => {
|
|
15
|
+
expect(numberEquals(arg0, arg0 - 1)).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('When first argument is smaller', () => {
|
|
20
|
+
it('Should return false', () => {
|
|
21
|
+
expect(numberEquals(arg0, arg0 + 1)).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('When values are equal', () => {
|
|
26
|
+
it('Should return true', () => {
|
|
27
|
+
expect(numberEquals(arg0, arg0)).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('Arguments are numeric strings', () => {
|
|
33
|
+
describe('When first argument is larger', () => {
|
|
34
|
+
it('Should return false', () => {
|
|
35
|
+
expect(numberEquals(`${arg0}`, `${arg0 - 1}`)).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('When first argument is smaller', () => {
|
|
40
|
+
it('Should return false', () => {
|
|
41
|
+
expect(numberEquals(`${arg0}`, `${arg0 + 1}`)).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('When values are equal', () => {
|
|
46
|
+
it('Should return true', () => {
|
|
47
|
+
expect(numberEquals(arg0, arg0)).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('Arguments are non numeric', () => {
|
|
53
|
+
[random.word(), `${datatype.number()}`.split(''), {}].forEach(element => {
|
|
54
|
+
it('Should return false', () => {
|
|
55
|
+
expect(numberEquals(element, 0)).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/globals.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare
|
|
2
|
-
declare
|
|
3
|
-
declare
|
|
1
|
+
declare let __DEV__: boolean;
|
|
2
|
+
declare let __LIB_VERSION__: string;
|
|
3
|
+
declare let LIBRARY_NAME: string;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import bindNot from 'bindNot';
|
|
2
|
+
|
|
3
|
+
// The module is named "isArrayValue" since it
|
|
4
|
+
// is conflicting with a nested npm dependency.
|
|
5
|
+
// We may need to revisit this in the future.
|
|
6
|
+
|
|
7
|
+
export function isArray(value: unknown): value is Array<unknown> {
|
|
8
|
+
return Boolean(Array.isArray(value));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const isNotArray = bindNot(isArray);
|
package/src/isEmpty.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import bindNot from 'bindNot';
|
|
2
|
+
import hasOwnProperty from 'hasOwnProperty';
|
|
3
|
+
import { lengthEquals } from 'lengthEquals';
|
|
4
|
+
|
|
5
|
+
export function isEmpty(value: unknown): boolean {
|
|
6
|
+
if (!value) {
|
|
7
|
+
return true;
|
|
8
|
+
} else if (hasOwnProperty(value, 'length')) {
|
|
9
|
+
return lengthEquals(value as string | unknown[], 0);
|
|
10
|
+
} else if (typeof value === 'object') {
|
|
11
|
+
return lengthEquals(Object.keys(value as Record<string, unknown>), 0);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const isNotEmpty = bindNot(isEmpty);
|
|
File without changes
|
package/src/isNull.ts
ADDED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import bindNot from 'bindNot';
|
|
1
2
|
import { isNull } from 'isNull';
|
|
2
3
|
import { isUndefined } from 'isUndefined';
|
|
3
4
|
|
|
4
|
-
import bindNot from 'bindNot';
|
|
5
|
-
|
|
6
5
|
export function isNullish(value: any): value is null | undefined {
|
|
7
6
|
return isNull(value) || isUndefined(value);
|
|
8
7
|
}
|
package/src/isNumeric.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import bindNot from 'bindNot';
|
|
2
|
+
|
|
3
|
+
export function isNumeric(value: string | number): boolean {
|
|
4
|
+
const str = String(value);
|
|
5
|
+
const num = Number(value);
|
|
6
|
+
const result =
|
|
7
|
+
!isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
8
|
+
return Boolean(result);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const isNotNumeric = bindNot(isNumeric);
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import bindNot from 'bindNot';
|
|
2
|
+
import { numberEquals } from 'numberEquals';
|
|
3
|
+
|
|
4
|
+
export function lengthEquals(
|
|
5
|
+
value: string | unknown[],
|
|
6
|
+
arg1: string | number
|
|
7
|
+
): boolean {
|
|
8
|
+
return numberEquals(value.length, arg1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const lengthNotEquals = bindNot(lengthEquals);
|
|
File without changes
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { isArray } from 'isArrayValue';
|
|
2
|
-
import { isNotNull } from 'isNull';
|
|
3
|
-
|
|
4
1
|
import asArray from 'asArray';
|
|
5
2
|
import defaultTo from 'defaultTo';
|
|
3
|
+
import { isArray } from 'isArrayValue';
|
|
4
|
+
import { isNotNull } from 'isNull';
|
|
6
5
|
import last from 'last';
|
|
7
6
|
|
|
8
7
|
export type NestedArray<T> = Array<NestedArray<T> | T>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import bindNot from 'bindNot';
|
|
2
|
+
import { isNumeric } from 'isNumeric';
|
|
3
|
+
|
|
4
|
+
export function numberEquals(
|
|
5
|
+
value: string | number,
|
|
6
|
+
eq: string | number
|
|
7
|
+
): boolean {
|
|
8
|
+
return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const numberNotEquals = bindNot(numberEquals);
|
|
File without changes
|
package/src/vest-utils.ts
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { default as cache } from 'cache';
|
|
2
|
+
export { isNullish, isNotNullish } from 'isNullish';
|
|
3
|
+
export * as nestedArray from 'nestedArray';
|
|
4
|
+
export { default as asArray } from 'asArray';
|
|
5
|
+
export { default as callEach } from 'callEach';
|
|
6
|
+
export { default as hasOwnProperty } from 'hasOwnProperty';
|
|
7
|
+
export { default as isPromise } from 'isPromise';
|
|
8
|
+
export { default as optionalFunctionValue } from 'optionalFunctionValue';
|
|
9
|
+
export { default as assign } from 'assign';
|
|
10
|
+
export { default as defaultTo } from 'defaultTo';
|
|
11
|
+
export { default as invariant, StringObject } from 'invariant';
|
|
12
|
+
export { default as isStringValue } from 'isStringValue';
|
|
13
|
+
export { default as partition } from 'partition';
|
|
14
|
+
export { default as bindNot } from 'bindNot';
|
|
15
|
+
export { default as either } from 'either';
|
|
16
|
+
export { default as isBoolean } from 'isBooleanValue';
|
|
17
|
+
export { default as last } from 'last';
|
|
18
|
+
export { default as deferThrow } from 'deferThrow';
|
|
19
|
+
export * as bus from 'bus';
|
|
20
|
+
export { default as genId } from 'genId';
|
|
21
|
+
export { default as isFunction } from 'isFunction';
|
|
22
|
+
export { default as mapFirst } from 'mapFirst';
|
|
23
|
+
export { greaterThan } from 'greaterThan';
|
|
24
|
+
export { longerThan } from 'longerThan';
|
|
25
|
+
export { isNumeric, isNotNumeric } from 'isNumeric';
|
|
26
|
+
export { lengthEquals, lengthNotEquals } from 'lengthEquals';
|
|
27
|
+
export { numberEquals, numberNotEquals } from 'numberEquals';
|
|
28
|
+
export { isNull, isNotNull } from 'isNull';
|
|
29
|
+
export { isUndefined, isNotUndefined } from 'isUndefined';
|
|
30
|
+
export { isArray, isNotArray } from 'isArrayValue';
|
|
31
|
+
export { isEmpty, isNotEmpty } from 'isEmpty';
|
|
32
|
+
export { isPositive } from 'isPositive';
|