vest-utils 0.0.1-rc → 0.0.2-dev-9b46fb

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.
Files changed (269) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/cjs/vest-utils.development.js +340 -0
  4. package/dist/cjs/vest-utils.production.js +1 -1
  5. package/dist/es/vest-utils.development.js +298 -0
  6. package/dist/es/vest-utils.production.js +1 -1
  7. package/dist/umd/vest-utils.development.js +344 -4
  8. package/dist/umd/vest-utils.production.js +1 -1
  9. package/package.json +4 -662
  10. package/src/{exports/__tests__ → __tests__}/bindNot.test.ts +1 -1
  11. package/src/{exports/__tests__ → __tests__}/bus.test.ts +0 -0
  12. package/src/{exports/__tests__ → __tests__}/cache.test.ts +1 -1
  13. package/src/{exports/__tests__ → __tests__}/defaultTo.test.ts +1 -1
  14. package/src/{exports/__tests__/throwError.test.ts → __tests__/deferThrow.test.ts} +1 -1
  15. package/src/__tests__/greaterThan.test.ts +59 -0
  16. package/src/{exports/__tests__ → __tests__}/invariant.test.ts +1 -1
  17. package/src/__tests__/isArray.test.ts +15 -0
  18. package/src/__tests__/isNull.test.ts +25 -0
  19. package/src/__tests__/isNumeric.test.ts +26 -0
  20. package/src/__tests__/isUndefined.test.ts +26 -0
  21. package/src/__tests__/lengthEquals.test.ts +56 -0
  22. package/src/__tests__/longerThan.test.ts +56 -0
  23. package/src/{exports/__tests__ → __tests__}/mapFirst.test.ts +1 -1
  24. package/src/__tests__/numberEquals.test.ts +59 -0
  25. package/src/{exports/__tests__ → __tests__}/optionalFunctionValue.test.ts +1 -1
  26. package/src/__tests__/seq.test.ts +12 -0
  27. package/src/{exports/asArray.ts → asArray.ts} +0 -0
  28. package/src/{exports/assign.ts → assign.ts} +0 -0
  29. package/src/{exports/bindNot.ts → bindNot.ts} +0 -0
  30. package/src/{exports/bus.ts → bus.ts} +0 -0
  31. package/src/{exports/cache.ts → cache.ts} +0 -0
  32. package/src/callEach.ts +5 -0
  33. package/src/{exports/defaultTo.ts → defaultTo.ts} +0 -0
  34. package/src/{exports/throwError.ts → deferThrow.ts} +1 -1
  35. package/src/{exports/either.ts → either.ts} +0 -0
  36. package/src/globals.d.ts +3 -3
  37. package/src/greaterThan.ts +8 -0
  38. package/src/{exports/hasOwnProperty.ts → hasOwnProperty.ts} +0 -0
  39. package/src/{exports/invariant.ts → invariant.ts} +0 -0
  40. package/src/isArrayValue.ts +11 -0
  41. package/src/isBooleanValue.ts +3 -0
  42. package/src/isEmpty.ts +17 -0
  43. package/src/{exports/isFunction.ts → isFunction.ts} +0 -0
  44. package/src/isNull.ts +7 -0
  45. package/src/{exports/isNullish.ts → isNullish.ts} +1 -2
  46. package/src/isNumeric.ts +11 -0
  47. package/src/isPositive.ts +5 -0
  48. package/src/{exports/isPromise.ts → isPromise.ts} +0 -0
  49. package/src/isStringValue.ts +3 -0
  50. package/src/isUndefined.ts +7 -0
  51. package/src/{exports/last.ts → last.ts} +0 -0
  52. package/src/lengthEquals.ts +11 -0
  53. package/src/longerThan.ts +8 -0
  54. package/src/{exports/mapFirst.ts → mapFirst.ts} +0 -0
  55. package/src/{exports/nestedArray.ts → nestedArray.ts} +2 -3
  56. package/src/numberEquals.ts +11 -0
  57. package/src/{exports/optionalFunctionValue.ts → optionalFunctionValue.ts} +1 -1
  58. package/src/{exports/genId.ts → seq.ts} +2 -2
  59. package/src/utilityTypes.ts +1 -1
  60. package/src/vest-utils.ts +31 -0
  61. package/tsconfig.json +3 -1
  62. package/types/vest-utils.d.ts +92 -1
  63. package/asArray/package.json +0 -9
  64. package/assign/package.json +0 -9
  65. package/bindNot/package.json +0 -9
  66. package/bus/package.json +0 -9
  67. package/cache/package.json +0 -9
  68. package/callEach/package.json +0 -9
  69. package/defaultTo/package.json +0 -9
  70. package/dist/cjs/asArray.development.js +0 -7
  71. package/dist/cjs/asArray.js +0 -7
  72. package/dist/cjs/asArray.production.js +0 -1
  73. package/dist/cjs/assign.development.js +0 -5
  74. package/dist/cjs/assign.js +0 -7
  75. package/dist/cjs/assign.production.js +0 -1
  76. package/dist/cjs/bindNot.development.js +0 -13
  77. package/dist/cjs/bindNot.js +0 -7
  78. package/dist/cjs/bindNot.production.js +0 -1
  79. package/dist/cjs/bus.development.js +0 -27
  80. package/dist/cjs/bus.js +0 -7
  81. package/dist/cjs/bus.production.js +0 -1
  82. package/dist/cjs/cache.development.js +0 -72
  83. package/dist/cjs/cache.js +0 -7
  84. package/dist/cjs/cache.production.js +0 -1
  85. package/dist/cjs/callEach.development.js +0 -7
  86. package/dist/cjs/callEach.js +0 -7
  87. package/dist/cjs/callEach.production.js +0 -1
  88. package/dist/cjs/defaultTo.development.js +0 -20
  89. package/dist/cjs/defaultTo.js +0 -7
  90. package/dist/cjs/defaultTo.production.js +0 -1
  91. package/dist/cjs/either.development.js +0 -7
  92. package/dist/cjs/either.js +0 -7
  93. package/dist/cjs/either.production.js +0 -1
  94. package/dist/cjs/genId.development.js +0 -10
  95. package/dist/cjs/genId.js +0 -7
  96. package/dist/cjs/genId.production.js +0 -1
  97. package/dist/cjs/hasOwnProperty.development.js +0 -10
  98. package/dist/cjs/hasOwnProperty.js +0 -7
  99. package/dist/cjs/hasOwnProperty.production.js +0 -1
  100. package/dist/cjs/invariant.development.js +0 -36
  101. package/dist/cjs/invariant.js +0 -7
  102. package/dist/cjs/invariant.production.js +0 -1
  103. package/dist/cjs/isBooleanValue.development.js +0 -9
  104. package/dist/cjs/isBooleanValue.js +0 -7
  105. package/dist/cjs/isBooleanValue.production.js +0 -1
  106. package/dist/cjs/isFunction.development.js +0 -7
  107. package/dist/cjs/isFunction.js +0 -7
  108. package/dist/cjs/isFunction.production.js +0 -1
  109. package/dist/cjs/isNullish.development.js +0 -37
  110. package/dist/cjs/isNullish.js +0 -7
  111. package/dist/cjs/isNullish.production.js +0 -1
  112. package/dist/cjs/isPromise.development.js +0 -11
  113. package/dist/cjs/isPromise.js +0 -7
  114. package/dist/cjs/isPromise.production.js +0 -1
  115. package/dist/cjs/isStringValue.development.js +0 -9
  116. package/dist/cjs/isStringValue.js +0 -7
  117. package/dist/cjs/isStringValue.production.js +0 -1
  118. package/dist/cjs/last.development.js +0 -12
  119. package/dist/cjs/last.js +0 -7
  120. package/dist/cjs/last.production.js +0 -1
  121. package/dist/cjs/mapFirst.development.js +0 -20
  122. package/dist/cjs/mapFirst.js +0 -7
  123. package/dist/cjs/mapFirst.production.js +0 -1
  124. package/dist/cjs/nestedArray.development.js +0 -99
  125. package/dist/cjs/nestedArray.js +0 -7
  126. package/dist/cjs/nestedArray.production.js +0 -1
  127. package/dist/cjs/optionalFunctionValue.development.js +0 -15
  128. package/dist/cjs/optionalFunctionValue.js +0 -7
  129. package/dist/cjs/optionalFunctionValue.production.js +0 -1
  130. package/dist/cjs/partition.development.js +0 -10
  131. package/dist/cjs/partition.js +0 -7
  132. package/dist/cjs/partition.production.js +0 -1
  133. package/dist/cjs/throwError.development.js +0 -11
  134. package/dist/cjs/throwError.js +0 -7
  135. package/dist/cjs/throwError.production.js +0 -1
  136. package/dist/es/asArray.development.js +0 -5
  137. package/dist/es/asArray.production.js +0 -1
  138. package/dist/es/assign.development.js +0 -3
  139. package/dist/es/assign.production.js +0 -1
  140. package/dist/es/bindNot.development.js +0 -11
  141. package/dist/es/bindNot.production.js +0 -1
  142. package/dist/es/bus.development.js +0 -23
  143. package/dist/es/bus.production.js +0 -1
  144. package/dist/es/cache.development.js +0 -66
  145. package/dist/es/cache.production.js +0 -1
  146. package/dist/es/callEach.development.js +0 -5
  147. package/dist/es/callEach.production.js +0 -1
  148. package/dist/es/defaultTo.development.js +0 -18
  149. package/dist/es/defaultTo.production.js +0 -1
  150. package/dist/es/either.development.js +0 -5
  151. package/dist/es/either.production.js +0 -1
  152. package/dist/es/genId.development.js +0 -8
  153. package/dist/es/genId.production.js +0 -1
  154. package/dist/es/hasOwnProperty.development.js +0 -8
  155. package/dist/es/hasOwnProperty.production.js +0 -1
  156. package/dist/es/invariant.development.js +0 -32
  157. package/dist/es/invariant.production.js +0 -1
  158. package/dist/es/isBooleanValue.development.js +0 -5
  159. package/dist/es/isBooleanValue.production.js +0 -1
  160. package/dist/es/isFunction.development.js +0 -5
  161. package/dist/es/isFunction.production.js +0 -1
  162. package/dist/es/isNullish.development.js +0 -28
  163. package/dist/es/isNullish.production.js +0 -1
  164. package/dist/es/isPromise.development.js +0 -9
  165. package/dist/es/isPromise.production.js +0 -1
  166. package/dist/es/isStringValue.development.js +0 -5
  167. package/dist/es/isStringValue.production.js +0 -1
  168. package/dist/es/last.development.js +0 -10
  169. package/dist/es/last.production.js +0 -1
  170. package/dist/es/mapFirst.development.js +0 -18
  171. package/dist/es/mapFirst.production.js +0 -1
  172. package/dist/es/nestedArray.development.js +0 -87
  173. package/dist/es/nestedArray.production.js +0 -1
  174. package/dist/es/optionalFunctionValue.development.js +0 -13
  175. package/dist/es/optionalFunctionValue.production.js +0 -1
  176. package/dist/es/partition.development.js +0 -8
  177. package/dist/es/partition.production.js +0 -1
  178. package/dist/es/throwError.development.js +0 -7
  179. package/dist/es/throwError.production.js +0 -1
  180. package/dist/umd/asArray.development.js +0 -13
  181. package/dist/umd/asArray.production.js +0 -1
  182. package/dist/umd/assign.development.js +0 -11
  183. package/dist/umd/assign.production.js +0 -1
  184. package/dist/umd/bindNot.development.js +0 -19
  185. package/dist/umd/bindNot.production.js +0 -1
  186. package/dist/umd/bus.development.js +0 -33
  187. package/dist/umd/bus.production.js +0 -1
  188. package/dist/umd/cache.development.js +0 -76
  189. package/dist/umd/cache.production.js +0 -1
  190. package/dist/umd/callEach.development.js +0 -13
  191. package/dist/umd/callEach.production.js +0 -1
  192. package/dist/umd/defaultTo.development.js +0 -26
  193. package/dist/umd/defaultTo.production.js +0 -1
  194. package/dist/umd/either.development.js +0 -13
  195. package/dist/umd/either.production.js +0 -1
  196. package/dist/umd/genId.development.js +0 -16
  197. package/dist/umd/genId.production.js +0 -1
  198. package/dist/umd/hasOwnProperty.development.js +0 -16
  199. package/dist/umd/hasOwnProperty.production.js +0 -1
  200. package/dist/umd/invariant.development.js +0 -42
  201. package/dist/umd/invariant.production.js +0 -1
  202. package/dist/umd/isBooleanValue.development.js +0 -15
  203. package/dist/umd/isBooleanValue.production.js +0 -1
  204. package/dist/umd/isFunction.development.js +0 -13
  205. package/dist/umd/isFunction.production.js +0 -1
  206. package/dist/umd/isNullish.development.js +0 -41
  207. package/dist/umd/isNullish.production.js +0 -1
  208. package/dist/umd/isPromise.development.js +0 -17
  209. package/dist/umd/isPromise.production.js +0 -1
  210. package/dist/umd/isStringValue.development.js +0 -15
  211. package/dist/umd/isStringValue.production.js +0 -1
  212. package/dist/umd/last.development.js +0 -18
  213. package/dist/umd/last.production.js +0 -1
  214. package/dist/umd/mapFirst.development.js +0 -26
  215. package/dist/umd/mapFirst.production.js +0 -1
  216. package/dist/umd/nestedArray.development.js +0 -103
  217. package/dist/umd/nestedArray.production.js +0 -1
  218. package/dist/umd/optionalFunctionValue.development.js +0 -21
  219. package/dist/umd/optionalFunctionValue.production.js +0 -1
  220. package/dist/umd/partition.development.js +0 -16
  221. package/dist/umd/partition.production.js +0 -1
  222. package/dist/umd/throwError.development.js +0 -17
  223. package/dist/umd/throwError.production.js +0 -1
  224. package/either/package.json +0 -9
  225. package/genId/package.json +0 -9
  226. package/hasOwnProperty/package.json +0 -9
  227. package/invariant/package.json +0 -9
  228. package/isBooleanValue/package.json +0 -9
  229. package/isFunction/package.json +0 -9
  230. package/isNullish/package.json +0 -9
  231. package/isPromise/package.json +0 -9
  232. package/isStringValue/package.json +0 -9
  233. package/last/package.json +0 -9
  234. package/mapFirst/package.json +0 -9
  235. package/nestedArray/package.json +0 -9
  236. package/optionalFunctionValue/package.json +0 -9
  237. package/partition/package.json +0 -9
  238. package/src/exports/__tests__/genId.test.ts +0 -12
  239. package/src/exports/__tests__/partition.test.ts +0 -21
  240. package/src/exports/callEach.ts +0 -3
  241. package/src/exports/isBooleanValue.ts +0 -3
  242. package/src/exports/isStringValue.ts +0 -3
  243. package/src/exports/partition.ts +0 -12
  244. package/throwError/package.json +0 -9
  245. package/types/asArray.d.ts +0 -2
  246. package/types/assign.d.ts +0 -7
  247. package/types/bindNot.d.ts +0 -2
  248. package/types/bus.d.ts +0 -9
  249. package/types/cache.d.ts +0 -9
  250. package/types/callEach.d.ts +0 -2
  251. package/types/defaultTo.d.ts +0 -2
  252. package/types/either.d.ts +0 -2
  253. package/types/genId.d.ts +0 -5
  254. package/types/hasOwnProperty.d.ts +0 -5
  255. package/types/invariant.d.ts +0 -4
  256. package/types/isBooleanValue.d.ts +0 -2
  257. package/types/isFunction.d.ts +0 -2
  258. package/types/isNullish.d.ts +0 -3
  259. package/types/isPromise.d.ts +0 -2
  260. package/types/isStringValue.d.ts +0 -2
  261. package/types/last.d.ts +0 -2
  262. package/types/mapFirst.d.ts +0 -2
  263. package/types/nestedArray.d.ts +0 -7
  264. package/types/optionalFunctionValue.d.ts +0 -2
  265. package/types/partition.d.ts +0 -5
  266. package/types/throwError.d.ts +0 -2
  267. package/types/utilityTypes.d.ts +0 -8
  268. package/types/vest-utilities.d.ts +0 -1
  269. package/utilityTypes/package.json +0 -9
@@ -1,4 +1,4 @@
1
- import bindNot from 'bindNot';
1
+ import { bindNot } from 'vest-utils';
2
2
 
3
3
  describe('bindNot', () => {
4
4
  it('Should return return a function', () => {
File without changes
@@ -1,6 +1,6 @@
1
1
  import _ from 'lodash';
2
2
 
3
- import cache from 'cache';
3
+ import { cache } from 'vest-utils';
4
4
 
5
5
  describe('lib: cache', () => {
6
6
  let c: ReturnType<typeof cache>;
@@ -1,4 +1,4 @@
1
- import defaultTo from 'defaultTo';
1
+ import { defaultTo } from 'vest-utils';
2
2
 
3
3
  describe('defaultTo', () => {
4
4
  describe('When value is a function', () => {
@@ -1,4 +1,4 @@
1
- import { deferThrow } from 'throwError';
1
+ import { deferThrow } from 'vest-utils';
2
2
 
3
3
  // @ts-ignore
4
4
  const _to = global.setTimeout;
@@ -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
+ });
@@ -1,4 +1,4 @@
1
- import invariant from 'invariant';
1
+ import { invariant } from 'vest-utils';
2
2
 
3
3
  describe('invariant', () => {
4
4
  it('should throw an error when condition is false', () => {
@@ -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
+ });
@@ -1,4 +1,4 @@
1
- import mapFirst from 'mapFirst';
1
+ import { mapFirst } from 'vest-utils';
2
2
 
3
3
  describe('mapFirst', () => {
4
4
  it('should return the broken out result', () => {
@@ -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
+ });
@@ -1,4 +1,4 @@
1
- import optionalFunctionValue from 'optionalFunctionValue';
1
+ import { optionalFunctionValue } from 'vest-utils';
2
2
 
3
3
  describe('optionalFunctionValue', () => {
4
4
  describe('When not a function', () => {
@@ -0,0 +1,12 @@
1
+ import seq from 'seq';
2
+
3
+ describe('lib:seq', () => {
4
+ it('Should return a new id on each run', () => {
5
+ Array.from({ length: 100 }, () => seq()).reduce((existing, seq) => {
6
+ expect(existing).not.toHaveProperty(seq.toString());
7
+ Object.assign(existing, { [seq]: true });
8
+ expect(existing).toHaveProperty(seq.toString());
9
+ return existing;
10
+ }, {});
11
+ });
12
+ });
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ import { CB } from 'utilityTypes';
2
+
3
+ export default function callEach(arr: CB[]): void {
4
+ return arr.forEach(fn => fn());
5
+ }
File without changes
@@ -1,4 +1,4 @@
1
- export function deferThrow(message?: string): void {
1
+ export default function deferThrow(message?: string): void {
2
2
  setTimeout(() => {
3
3
  throw new Error(message);
4
4
  }, 0);
File without changes
package/src/globals.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare var __DEV__: boolean;
2
- declare var __LIB_VERSION__: string;
3
- declare var LIBRARY_NAME: string;
1
+ declare const __DEV__: boolean;
2
+ declare const __LIB_VERSION__: string;
3
+ declare const LIBRARY_NAME: string;
@@ -0,0 +1,8 @@
1
+ import { isNumeric } from 'isNumeric';
2
+
3
+ export function greaterThan(
4
+ value: number | string,
5
+ gt: number | string
6
+ ): boolean {
7
+ return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
8
+ }
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);
@@ -0,0 +1,3 @@
1
+ export default function isBoolean(value: unknown): value is boolean {
2
+ return !!value === value;
3
+ }
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
@@ -0,0 +1,7 @@
1
+ import bindNot from 'bindNot';
2
+
3
+ export function isNull(value: unknown): value is null {
4
+ return value === null;
5
+ }
6
+
7
+ export const isNotNull = bindNot(isNull);
@@ -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
  }
@@ -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);
@@ -0,0 +1,5 @@
1
+ import { greaterThan } from 'greaterThan';
2
+
3
+ export function isPositive(value: number | string): boolean {
4
+ return greaterThan(value, 0);
5
+ }
File without changes
@@ -0,0 +1,3 @@
1
+ export default function isStringValue(v: unknown): v is string {
2
+ return String(v) === v;
3
+ }
@@ -0,0 +1,7 @@
1
+ import bindNot from 'bindNot';
2
+
3
+ export function isUndefined(value?: unknown): value is undefined {
4
+ return value === undefined;
5
+ }
6
+
7
+ export const isNotUndefined = bindNot(isUndefined);
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);
@@ -0,0 +1,8 @@
1
+ import { greaterThan } from 'greaterThan';
2
+
3
+ export function longerThan(
4
+ value: string | unknown[],
5
+ arg1: string | number
6
+ ): boolean {
7
+ return greaterThan(value.length, arg1);
8
+ }
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);
@@ -1,4 +1,4 @@
1
- import isFunction from './isFunction';
1
+ import isFunction from 'isFunction';
2
2
 
3
3
  export default function optionalFunctionValue<T>(
4
4
  value: T | ((...args: any[]) => T),
@@ -2,9 +2,9 @@
2
2
  * @returns a unique numeric id.
3
3
  */
4
4
 
5
- const genId: () => string = (
5
+ const seq: () => string = (
6
6
  (n: number) => (): string =>
7
7
  `${n++}`
8
8
  )(0);
9
9
 
10
- export default genId;
10
+ export default seq;
@@ -4,6 +4,6 @@ export type DropFirst<T extends unknown[]> = T extends [unknown, ...infer U]
4
4
 
5
5
  export type Stringable = string | ((...args: any[]) => string);
6
6
 
7
- export type CB = (...args: any[]) => void;
7
+ export type CB = (...args: any[]) => any;
8
8
 
9
9
  export type ValueOf<T> = T[keyof T];