@transferwise/neptune-validation 0.0.0-experimental-da992bd → 0.0.0-experimental-1214b25

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/index.js ADDED
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+
3
+ const isString = value => typeof value === 'string';
4
+ const isNumber = value => typeof value === 'number' && !Number.isNaN(value);
5
+ const isInteger = value => {
6
+ return isNumber(value) && Math.floor(value) === value;
7
+ };
8
+ const isBoolean = value => typeof value === 'boolean';
9
+ const isObject = value => !isNull(value) && !isUndefined(value) && value.constructor === Object;
10
+ const isArray = value => Array.isArray(value);
11
+ const isNull = value => value === null;
12
+ const isUndefined = value => typeof value === 'undefined';
13
+
14
+ /**
15
+ * Checks empty values for arrays,objects and strings.
16
+ *
17
+ * @param {object | Array | string} value
18
+ */
19
+ const isEmpty = value => isString(value) && value.length === 0 || (isObject(value) || isArray(value)) && Object.keys(value).length === 0;
20
+
21
+ const keyMap = {
22
+ SPACE: {
23
+ key: [' ', 'Spacebar'],
24
+ keyCode: 32
25
+ },
26
+ ENTER: {
27
+ key: 'Enter',
28
+ keyCode: 13
29
+ },
30
+ TAB: {
31
+ key: 'Tab',
32
+ keyCode: 9
33
+ },
34
+ ESCAPE: {
35
+ key: 'Escape',
36
+ keyCode: 27
37
+ }
38
+ };
39
+
40
+ const isKey = ({
41
+ keyType,
42
+ event
43
+ }) => {
44
+ if (!keyType || !event) {
45
+ return false;
46
+ }
47
+ const upperCaseKeyType = keyType.toUpperCase();
48
+ const keyDef = keyMap[upperCaseKeyType];
49
+ if (!keyDef) {
50
+ return false;
51
+ }
52
+ const {
53
+ key,
54
+ keyCode
55
+ } = event;
56
+ if (key) {
57
+ return isArray(keyDef.key) ? keyDef.key.includes(key) : key === keyDef.key;
58
+ }
59
+ return keyCode === keyDef.keyCode;
60
+ };
61
+ var isKey$1 = isKey;
62
+
63
+ exports.isArray = isArray;
64
+ exports.isBoolean = isBoolean;
65
+ exports.isEmpty = isEmpty;
66
+ exports.isInteger = isInteger;
67
+ exports.isKey = isKey$1;
68
+ exports.isNull = isNull;
69
+ exports.isNumber = isNumber;
70
+ exports.isObject = isObject;
71
+ exports.isString = isString;
72
+ exports.isUndefined = isUndefined;
73
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/type-validators/index.js","../src/value-validators/index.js","../src/common/keyMap.js","../src/event-validators/isKey.js"],"sourcesContent":["const isString = (value) => typeof value === 'string';\nconst isNumber = (value) => typeof value === 'number' && !Number.isNaN(value);\nconst isInteger = (value) => {\n return isNumber(value) && Math.floor(value) === value;\n};\nconst isBoolean = (value) => typeof value === 'boolean';\n\nconst isObject = (value) => !isNull(value) && !isUndefined(value) && value.constructor === Object;\nconst isArray = (value) => Array.isArray(value);\nconst isNull = (value) => value === null;\nconst isUndefined = (value) => typeof value === 'undefined';\n\nexport { isString, isNumber, isInteger, isBoolean, isObject, isArray, isNull, isUndefined };\n","import { isString, isObject, isArray } from '../type-validators';\n\n/**\n * Checks empty values for arrays,objects and strings.\n *\n * @param {object | Array | string} value\n */\nconst isEmpty = (value) =>\n (isString(value) && value.length === 0) ||\n ((isObject(value) || isArray(value)) && Object.keys(value).length === 0);\n\nexport { isEmpty };\n","export const keyMap = {\n SPACE: { key: [' ', 'Spacebar'], keyCode: 32 },\n ENTER: { key: 'Enter', keyCode: 13 },\n TAB: { key: 'Tab', keyCode: 9 },\n ESCAPE: { key: 'Escape', keyCode: 27 },\n};\n","import { keyMap } from '../common/keyMap';\nimport { isArray } from '../type-validators';\n\nconst isKey = ({ keyType, event }) => {\n if (!keyType || !event) {\n return false;\n }\n\n const upperCaseKeyType = keyType.toUpperCase();\n const keyDef = keyMap[upperCaseKeyType];\n if (!keyDef) {\n return false;\n }\n\n const { key, keyCode } = event;\n\n if (key) {\n return isArray(keyDef.key) ? keyDef.key.includes(key) : key === keyDef.key;\n }\n\n return keyCode === keyDef.keyCode;\n};\n\nexport default isKey;\n"],"names":["isString","value","isNumber","Number","isNaN","isInteger","Math","floor","isBoolean","isObject","isNull","isUndefined","constructor","Object","isArray","Array","isEmpty","length","keys","keyMap","SPACE","key","keyCode","ENTER","TAB","ESCAPE","isKey","keyType","event","upperCaseKeyType","toUpperCase","keyDef","includes"],"mappings":";;AAAA,MAAMA,QAAQ,GAAIC,KAAK,IAAK,OAAOA,KAAK,KAAK,SAAQ;AACrD,MAAMC,QAAQ,GAAID,KAAK,IAAK,OAAOA,KAAK,KAAK,QAAQ,IAAI,CAACE,MAAM,CAACC,KAAK,CAACH,KAAK,EAAC;AACvEI,MAAAA,SAAS,GAAIJ,KAAK,IAAK;AAC3B,EAAA,OAAOC,QAAQ,CAACD,KAAK,CAAC,IAAIK,IAAI,CAACC,KAAK,CAACN,KAAK,CAAC,KAAKA,KAAK,CAAA;AACvD,EAAC;AACD,MAAMO,SAAS,GAAIP,KAAK,IAAK,OAAOA,KAAK,KAAK,UAAS;AAEjDQ,MAAAA,QAAQ,GAAIR,KAAK,IAAK,CAACS,MAAM,CAACT,KAAK,CAAC,IAAI,CAACU,WAAW,CAACV,KAAK,CAAC,IAAIA,KAAK,CAACW,WAAW,KAAKC,OAAM;AAC3FC,MAAAA,OAAO,GAAIb,KAAK,IAAKc,KAAK,CAACD,OAAO,CAACb,KAAK,EAAC;AAC/C,MAAMS,MAAM,GAAIT,KAAK,IAAKA,KAAK,KAAK,KAAI;AACxC,MAAMU,WAAW,GAAIV,KAAK,IAAK,OAAOA,KAAK,KAAK;;ACRhD;AACA;AACA;AACA;AACA;AACA,MAAMe,OAAO,GAAIf,KAAK,IACnBD,QAAQ,CAACC,KAAK,CAAC,IAAIA,KAAK,CAACgB,MAAM,KAAK,CAAC,IACrC,CAACR,QAAQ,CAACR,KAAK,CAAC,IAAIa,OAAO,CAACb,KAAK,CAAC,KAAKY,MAAM,CAACK,IAAI,CAACjB,KAAK,CAAC,CAACgB,MAAM,KAAK;;ACTjE,MAAME,MAA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
@@ -0,0 +1,62 @@
1
+ const isString = value => typeof value === 'string';
2
+ const isNumber = value => typeof value === 'number' && !Number.isNaN(value);
3
+ const isInteger = value => {
4
+ return isNumber(value) && Math.floor(value) === value;
5
+ };
6
+ const isBoolean = value => typeof value === 'boolean';
7
+ const isObject = value => !isNull(value) && !isUndefined(value) && value.constructor === Object;
8
+ const isArray = value => Array.isArray(value);
9
+ const isNull = value => value === null;
10
+ const isUndefined = value => typeof value === 'undefined';
11
+
12
+ /**
13
+ * Checks empty values for arrays,objects and strings.
14
+ *
15
+ * @param {object | Array | string} value
16
+ */
17
+ const isEmpty = value => isString(value) && value.length === 0 || (isObject(value) || isArray(value)) && Object.keys(value).length === 0;
18
+
19
+ const keyMap = {
20
+ SPACE: {
21
+ key: [' ', 'Spacebar'],
22
+ keyCode: 32
23
+ },
24
+ ENTER: {
25
+ key: 'Enter',
26
+ keyCode: 13
27
+ },
28
+ TAB: {
29
+ key: 'Tab',
30
+ keyCode: 9
31
+ },
32
+ ESCAPE: {
33
+ key: 'Escape',
34
+ keyCode: 27
35
+ }
36
+ };
37
+
38
+ const isKey = ({
39
+ keyType,
40
+ event
41
+ }) => {
42
+ if (!keyType || !event) {
43
+ return false;
44
+ }
45
+ const upperCaseKeyType = keyType.toUpperCase();
46
+ const keyDef = keyMap[upperCaseKeyType];
47
+ if (!keyDef) {
48
+ return false;
49
+ }
50
+ const {
51
+ key,
52
+ keyCode
53
+ } = event;
54
+ if (key) {
55
+ return isArray(keyDef.key) ? keyDef.key.includes(key) : key === keyDef.key;
56
+ }
57
+ return keyCode === keyDef.keyCode;
58
+ };
59
+ var isKey$1 = isKey;
60
+
61
+ export { isArray, isBoolean, isEmpty, isInteger, isKey$1 as isKey, isNull, isNumber, isObject, isString, isUndefined };
62
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/type-validators/index.js","../src/value-validators/index.js","../src/common/keyMap.js","../src/event-validators/isKey.js"],"sourcesContent":["const isString = (value) => typeof value === 'string';\nconst isNumber = (value) => typeof value === 'number' && !Number.isNaN(value);\nconst isInteger = (value) => {\n return isNumber(value) && Math.floor(value) === value;\n};\nconst isBoolean = (value) => typeof value === 'boolean';\n\nconst isObject = (value) => !isNull(value) && !isUndefined(value) && value.constructor === Object;\nconst isArray = (value) => Array.isArray(value);\nconst isNull = (value) => value === null;\nconst isUndefined = (value) => typeof value === 'undefined';\n\nexport { isString, isNumber, isInteger, isBoolean, isObject, isArray, isNull, isUndefined };\n","import { isString, isObject, isArray } from '../type-validators';\n\n/**\n * Checks empty values for arrays,objects and strings.\n *\n * @param {object | Array | string} value\n */\nconst isEmpty = (value) =>\n (isString(value) && value.length === 0) ||\n ((isObject(value) || isArray(value)) && Object.keys(value).length === 0);\n\nexport { isEmpty };\n","export const keyMap = {\n SPACE: { key: [' ', 'Spacebar'], keyCode: 32 },\n ENTER: { key: 'Enter', keyCode: 13 },\n TAB: { key: 'Tab', keyCode: 9 },\n ESCAPE: { key: 'Escape', keyCode: 27 },\n};\n","import { keyMap } from '../common/keyMap';\nimport { isArray } from '../type-validators';\n\nconst isKey = ({ keyType, event }) => {\n if (!keyType || !event) {\n return false;\n }\n\n const upperCaseKeyType = keyType.toUpperCase();\n const keyDef = keyMap[upperCaseKeyType];\n if (!keyDef) {\n return false;\n }\n\n const { key, keyCode } = event;\n\n if (key) {\n return isArray(keyDef.key) ? keyDef.key.includes(key) : key === keyDef.key;\n }\n\n return keyCode === keyDef.keyCode;\n};\n\nexport default isKey;\n"],"names":["isString","value","isNumber","Number","isNaN","isInteger","Math","floor","isBoolean","isObject","isNull","isUndefined","constructor","Object","isArray","Array","isEmpty","length","keys","keyMap","SPACE","key","keyCode","ENTER","TAB","ESCAPE","isKey","keyType","event","upperCaseKeyType","toUpperCase","keyDef","includes"],"mappings":"AAAA,MAAMA,QAAQ,GAAIC,KAAK,IAAK,OAAOA,KAAK,KAAK,SAAQ;AACrD,MAAMC,QAAQ,GAAID,KAAK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AAO,EAAE,CAAA;GAAG;AAC/BG,EAAAA,MAAM,EAAE;AAAEJ,IAAAA,GAAG,EAAE,QAAQ;AAAEC,IAAAA,OAAO,EAAE,EAAA;AAAG,GAAA;AACvC,CAAC;;ACFD,MAAMI,KAAK,GAAGA,CAAC;EAAEC,OAAO;AAAEC,EAAAA,KAAAA;AAAM,CAAC,KAAK;AACpC,EAAA,IAAI,CAACD,OAAO,IAAI,CAACC,KAAK,EAAE;AACtB,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;AAEA,EAAA,MAAMC,gBAAgB,GAAGF,OAAO,CAACG,WAAW,EAAE,CAAA;AAC9C,EAAA,MAAMC,MAAM,GAAGZ,MAAM,CAACU,gBAAgB,CAAC,CAAA;EACvC,IAAI,CAACE,MAAM,EAAE;AACX,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;EAEA,MAAM;IAAEV,GAAG;AAAEC,IAAAA,OAAAA;AAAQ,GAAC,GAAGM,KAAK,CAAA;AAE9B,EAAA,IAAIP,GAAG,EAAE;IACP,OAAOP,OAAO,CAACiB,MAAM,CAACV,GAAG,CAAC,GAAGU,MAAM,CAACV,GAAG,CAACW,QAAQ,CAACX,GAAG,CAAC,GAAGA,GAAG,KAAKU,MAAM,CAACV,GAAG,CAAA;AAC5E,GAAA;AAEA,EAAA,OAAOC,OAAO,KAAKS,MAAM,CAACT,OAAO,CAAA;AACnC,CAAC,CAAA;AAED,cAAeI,KAAK;;;;"}
package/package.json CHANGED
@@ -1,13 +1,8 @@
1
1
  {
2
2
  "name": "@transferwise/neptune-validation",
3
- "version": "0.0.0-experimental-da992bd",
3
+ "version": "0.0.0-experimental-1214b25",
4
4
  "description": "Neptune Web validation",
5
5
  "license": "Apache-2.0",
6
- "main": "./build/umd/polyfill/main.js",
7
- "module": "./build/es/polyfill/index.js",
8
- "files": [
9
- "build"
10
- ],
11
6
  "keywords": [
12
7
  "wise",
13
8
  "neptune-web-validation"
@@ -17,19 +12,42 @@
17
12
  "fullname": "transferwise/neptune-web",
18
13
  "url": "git+https://github.com/transferwise/neptune-web.git"
19
14
  },
15
+ "author": "Wise Payments Ltd.",
16
+ "sideEffects": [
17
+ "**/*.css"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "import": "./dist/index.mjs",
22
+ "require": "./dist/index.js"
23
+ }
24
+ },
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "files": [
28
+ "dist/",
29
+ "src/",
30
+ "!**/*.tsbuildinfo"
31
+ ],
20
32
  "dependencies": {
21
- "@babel/runtime": "^7.18.3",
33
+ "@babel/runtime": "^7.22.15",
22
34
  "core-js": "^3.8.0"
23
35
  },
24
36
  "devDependencies": {
25
- "@rollup/plugin-babel": "^5.2.2",
26
- "@rollup/plugin-commonjs": "^11.0.2",
27
- "@rollup/plugin-node-resolve": "^7.1.3",
37
+ "@babel/core": "^7.22.15",
38
+ "@babel/plugin-transform-runtime": "^7.22.15",
39
+ "@babel/preset-env": "^7.22.15",
40
+ "@babel/preset-react": "^7.22.15",
41
+ "@babel/preset-typescript": "^7.22.15",
42
+ "@rollup/plugin-babel": "^6.0.3",
43
+ "@rollup/plugin-node-resolve": "^15.2.1",
44
+ "@rollup/plugin-typescript": "^11.1.3",
28
45
  "@transferwise/eslint-config": "^7.4.0",
46
+ "@tsconfig/recommended": "^1.0.2",
47
+ "@types/babel__core": "^7.20.1",
29
48
  "@types/jest": "^27.5.2",
30
49
  "jest": "^27.0.6",
31
- "rollup": "^2.34.0",
32
- "rollup-plugin-uglify": "^6.0.4"
50
+ "rollup": "^3.28.1"
33
51
  },
34
52
  "publishConfig": {
35
53
  "access": "public"
@@ -45,8 +63,7 @@
45
63
  "lint:fix:format": "prettier --write --ignore-path ../../../.prettierignore .",
46
64
  "lint:fix:js+ts": "pnpm run lint:check:js+ts --fix",
47
65
  "build": "npm-run-all build:*",
48
- "build:clean": "rm -rf build",
49
- "build:umd": "NODE_ENV=umd rollup -c",
50
- "build:es": "NODE_ENV=es babel src -d build/es/polyfill --ignore '**/*.spec.js','**/*.story.js'"
66
+ "build:clean": "rm -rf dist",
67
+ "build:js": "rollup --config --sourcemap"
51
68
  }
52
69
  }
@@ -0,0 +1,6 @@
1
+ export const keyMap = {
2
+ SPACE: { key: [' ', 'Spacebar'], keyCode: 32 },
3
+ ENTER: { key: 'Enter', keyCode: 13 },
4
+ TAB: { key: 'Tab', keyCode: 9 },
5
+ ESCAPE: { key: 'Escape', keyCode: 27 },
6
+ };
@@ -0,0 +1 @@
1
+ export { default } from './isKey';
@@ -0,0 +1,24 @@
1
+ import { keyMap } from '../common/keyMap';
2
+ import { isArray } from '../type-validators';
3
+
4
+ const isKey = ({ keyType, event }) => {
5
+ if (!keyType || !event) {
6
+ return false;
7
+ }
8
+
9
+ const upperCaseKeyType = keyType.toUpperCase();
10
+ const keyDef = keyMap[upperCaseKeyType];
11
+ if (!keyDef) {
12
+ return false;
13
+ }
14
+
15
+ const { key, keyCode } = event;
16
+
17
+ if (key) {
18
+ return isArray(keyDef.key) ? keyDef.key.includes(key) : key === keyDef.key;
19
+ }
20
+
21
+ return keyCode === keyDef.keyCode;
22
+ };
23
+
24
+ export default isKey;
@@ -0,0 +1,58 @@
1
+ /* eslint-disable no-console */
2
+ import { keyMap } from '../common/keyMap';
3
+
4
+ import isKey from '.';
5
+
6
+ const { TAB, ESCAPE } = keyMap;
7
+
8
+ describe('isKey', () => {
9
+ it('returns true if eventKey is equal to key', () => {
10
+ const event = { key: 'Tab', keyCode: TAB.keyCode };
11
+ expect(isKey({ keyType: TAB.key, event })).toBe(true);
12
+ });
13
+
14
+ it('returns true if eventKey is equal to empty key', () => {
15
+ const event = { key: ' ' };
16
+ expect(isKey({ keyType: 'Space', event })).toBe(true);
17
+ });
18
+
19
+ it('returns true if eventKey is equal to Spacebar', () => {
20
+ const event = { key: 'Spacebar' };
21
+ expect(isKey({ keyType: 'Space', event })).toBe(true);
22
+ });
23
+
24
+ it('returns true if eventKey is equal to Tab', () => {
25
+ const event = { key: 'Tab' };
26
+ expect(isKey({ keyType: TAB.key, event })).toBe(true);
27
+ });
28
+
29
+ it('returns true if eventKeyCode is equal to key', () => {
30
+ const event = { keyCode: TAB.keyCode };
31
+ expect(isKey({ keyType: TAB.key, event })).toBe(true);
32
+ });
33
+
34
+ it('returns false if key is not defined', () => {
35
+ const event = { keyCode: TAB.keyCode };
36
+ expect(isKey({ event })).toBe(false);
37
+ });
38
+
39
+ it('returns false if event is not defined', () => {
40
+ const event = null;
41
+ expect(isKey({ event })).toBe(false);
42
+ });
43
+
44
+ it('returns false if eventKey or eventKeyCode are not defined', () => {
45
+ const event = {};
46
+ expect(isKey({ keyType: TAB.key, event })).toBe(false);
47
+ });
48
+
49
+ it('returns false if eventKey is equal to key', () => {
50
+ const event = { key: 'Escape', keyCode: ESCAPE.keyCode };
51
+ expect(isKey({ keyType: TAB.key, event })).toBe(false);
52
+ });
53
+
54
+ it('returns false if eventKeyCode is equal to key', () => {
55
+ const event = { keyCode: ESCAPE.keyCode };
56
+ expect(isKey({ keyType: TAB.key, event })).toBe(false);
57
+ });
58
+ });
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './type-validators';
2
+ export * from './value-validators';
3
+ export { default as isKey } from './event-validators';
@@ -0,0 +1,13 @@
1
+ const isString = (value) => typeof value === 'string';
2
+ const isNumber = (value) => typeof value === 'number' && !Number.isNaN(value);
3
+ const isInteger = (value) => {
4
+ return isNumber(value) && Math.floor(value) === value;
5
+ };
6
+ const isBoolean = (value) => typeof value === 'boolean';
7
+
8
+ const isObject = (value) => !isNull(value) && !isUndefined(value) && value.constructor === Object;
9
+ const isArray = (value) => Array.isArray(value);
10
+ const isNull = (value) => value === null;
11
+ const isUndefined = (value) => typeof value === 'undefined';
12
+
13
+ export { isString, isNumber, isInteger, isBoolean, isObject, isArray, isNull, isUndefined };
@@ -0,0 +1,140 @@
1
+ import {
2
+ isString,
3
+ isNumber,
4
+ isInteger,
5
+ isBoolean,
6
+ isArray,
7
+ isObject,
8
+ isNull,
9
+ isUndefined,
10
+ } from '.';
11
+
12
+ describe('Given a library for validating data types', () => {
13
+ describe('when validating a string', () => {
14
+ it('should return true when the value is a string', () => {
15
+ expect(isString('a')).toBe(true);
16
+ expect(isString('')).toBe(true);
17
+ });
18
+ it('should return false when the value is not string', () => {
19
+ expect(isString(1)).toBe(false);
20
+ expect(isString(true)).toBe(false);
21
+ expect(isString([])).toBe(false);
22
+ expect(isString({})).toBe(false);
23
+ expect(isString(undefined)).toBe(false);
24
+ expect(isString(null)).toBe(false);
25
+ expect(isString(NaN)).toBe(false);
26
+ });
27
+ });
28
+
29
+ describe('when validating a number', () => {
30
+ it('should return true when the value is a number', () => {
31
+ expect(isNumber(1)).toBe(true);
32
+ expect(isNumber(0)).toBe(true);
33
+ expect(isNumber(1.23)).toBe(true);
34
+ expect(isNumber(-1)).toBe(true);
35
+ });
36
+ it('should return false when the value is not number', () => {
37
+ expect(isNumber('a')).toBe(false);
38
+ expect(isNumber(true)).toBe(false);
39
+ expect(isNumber([])).toBe(false);
40
+ expect(isNumber({})).toBe(false);
41
+ expect(isNumber(undefined)).toBe(false);
42
+ expect(isNumber(null)).toBe(false);
43
+ expect(isNumber(NaN)).toBe(false);
44
+ });
45
+ });
46
+
47
+ describe('when validating an integer', () => {
48
+ it('should return true when the value is a integer', () => {
49
+ expect(isInteger(1)).toBe(true);
50
+ expect(isInteger(0)).toBe(true);
51
+ expect(isInteger(-1)).toBe(true);
52
+ });
53
+ it('should return false when the value is not an integer', () => {
54
+ expect(isInteger(1.23)).toBe(false);
55
+ expect(isInteger('a')).toBe(false);
56
+ expect(isInteger(true)).toBe(false);
57
+ expect(isInteger([])).toBe(false);
58
+ expect(isInteger({})).toBe(false);
59
+ expect(isInteger(undefined)).toBe(false);
60
+ expect(isInteger(null)).toBe(false);
61
+ expect(isInteger(NaN)).toBe(false);
62
+ });
63
+ });
64
+
65
+ describe('when validating a boolean', () => {
66
+ it('should return true when the value is a boolean', () => {
67
+ expect(isBoolean(true)).toBe(true);
68
+ expect(isBoolean(false)).toBe(true);
69
+ });
70
+ it('should return false when the value is not a boolean', () => {
71
+ expect(isBoolean(1)).toBe(false);
72
+ expect(isBoolean('a')).toBe(false);
73
+ expect(isBoolean([])).toBe(false);
74
+ expect(isBoolean({})).toBe(false);
75
+ expect(isBoolean(undefined)).toBe(false);
76
+ expect(isBoolean(null)).toBe(false);
77
+ expect(isBoolean(NaN)).toBe(false);
78
+ });
79
+ });
80
+
81
+ describe('when validating an array', () => {
82
+ it('should return true when the value is an array', () => {
83
+ expect(isArray([1])).toBe(true);
84
+ expect(isArray([])).toBe(true);
85
+ });
86
+ it('should return false when the value is not an array', () => {
87
+ expect(isArray(1)).toBe(false);
88
+ expect(isArray('a')).toBe(false);
89
+ expect(isArray(true)).toBe(false);
90
+ expect(isArray({})).toBe(false);
91
+ expect(isArray(undefined)).toBe(false);
92
+ expect(isArray(null)).toBe(false);
93
+ expect(isArray(NaN)).toBe(false);
94
+ });
95
+ });
96
+
97
+ describe('when validating an object', () => {
98
+ it('should return true when the value is an object', () => {
99
+ expect(isObject({ a: 1 })).toBe(true);
100
+ expect(isObject({})).toBe(true);
101
+ });
102
+ it('should return false when the value is not an object', () => {
103
+ expect(isObject(1)).toBe(false);
104
+ expect(isObject('a')).toBe(false);
105
+ expect(isObject(true)).toBe(false);
106
+ expect(isObject([])).toBe(false);
107
+ expect(isObject(undefined)).toBe(false);
108
+ expect(isObject(null)).toBe(false);
109
+ expect(isObject(NaN)).toBe(false);
110
+ });
111
+ });
112
+
113
+ describe('when validating a null', () => {
114
+ it('should return true when the value is null', () => {
115
+ expect(isNull(null)).toBe(true);
116
+ });
117
+ it('should return false when the value is not null', () => {
118
+ expect(isNull(0)).toBe(false);
119
+ expect(isNull(false)).toBe(false);
120
+ expect(isNull([])).toBe(false);
121
+ expect(isNull({})).toBe(false);
122
+ expect(isNull(undefined)).toBe(false);
123
+ expect(isNull(NaN)).toBe(false);
124
+ });
125
+ });
126
+
127
+ describe('when validating an undefined', () => {
128
+ it('should return true when the value is undefined', () => {
129
+ expect(isUndefined(undefined)).toBe(true);
130
+ });
131
+ it('should return false when the value is not undefined', () => {
132
+ expect(isUndefined(0)).toBe(false);
133
+ expect(isUndefined(false)).toBe(false);
134
+ expect(isUndefined([])).toBe(false);
135
+ expect(isUndefined({})).toBe(false);
136
+ expect(isUndefined(null)).toBe(false);
137
+ expect(isUndefined(NaN)).toBe(false);
138
+ });
139
+ });
140
+ });
@@ -0,0 +1,12 @@
1
+ import { isString, isObject, isArray } from '../type-validators';
2
+
3
+ /**
4
+ * Checks empty values for arrays,objects and strings.
5
+ *
6
+ * @param {object | Array | string} value
7
+ */
8
+ const isEmpty = (value) =>
9
+ (isString(value) && value.length === 0) ||
10
+ ((isObject(value) || isArray(value)) && Object.keys(value).length === 0);
11
+
12
+ export { isEmpty };
@@ -0,0 +1,23 @@
1
+ import { isEmpty } from '.';
2
+
3
+ describe('Given a library for validating values', () => {
4
+ describe('when checking for empty values', () => {
5
+ it('should return true for empty strings', () => {
6
+ expect(isEmpty('')).toBe(true);
7
+ expect(isEmpty('a')).toBe(false);
8
+ });
9
+ it('should return true for empty array', () => {
10
+ expect(isEmpty([])).toBe(true);
11
+ expect(isEmpty(['a'])).toBe(false);
12
+ });
13
+ it('should return true for empty object', () => {
14
+ expect(isEmpty({})).toBe(true);
15
+ expect(isEmpty({ a: 'a' })).toBe(false);
16
+ });
17
+ it('should return false when the value is not a string, array, or object', () => {
18
+ expect(isEmpty(1)).toBe(false);
19
+ expect(isEmpty(null)).toBe(false);
20
+ expect(isEmpty(undefined)).toBe(false);
21
+ });
22
+ });
23
+ });
@@ -1 +0,0 @@
1
- export var keyMap={SPACE:{key:[" ","Spacebar"],keyCode:32},ENTER:{key:"Enter",keyCode:13},TAB:{key:"Tab",keyCode:9},ESCAPE:{key:"Escape",keyCode:27}};
@@ -1 +0,0 @@
1
- export{default}from"./isKey";
@@ -1 +0,0 @@
1
- import"core-js/modules/es.array.includes.js";import"core-js/modules/es.string.includes.js";import{keyMap}from"../common/keyMap";import{isArray}from"../type-validators";var isKey=function(a){var b=a.keyType,c=a.event;if(!b||!c)return!1;var d=b.toUpperCase(),e=keyMap[d];if(!e)return!1;var f=c.key,g=c.keyCode;return f?isArray(e.key)?e.key.includes(f):f===e.key:g===e.keyCode};export default isKey;
@@ -1 +0,0 @@
1
- export*from"./type-validators";export*from"./value-validators";export{default as isKey}from"./event-validators";
@@ -1 +0,0 @@
1
- import"core-js/modules/es.number.is-nan.js";import"core-js/modules/es.number.constructor.js";var isString=function(a){return"string"==typeof a},isNumber=function(a){return"number"==typeof a&&!Number.isNaN(a)},isInteger=function(a){return isNumber(a)&&Math.floor(a)===a},isBoolean=function(a){return"boolean"==typeof a},isObject=function(a){return!isNull(a)&&!isUndefined(a)&&a.constructor===Object},isArray=function(a){return Array.isArray(a)},isNull=function(a){return null===a},isUndefined=function(a){return"undefined"==typeof a};export{isString,isNumber,isInteger,isBoolean,isObject,isArray,isNull,isUndefined};
@@ -1 +0,0 @@
1
- import{isString,isNumber,isInteger,isBoolean,isArray,isObject,isNull,isUndefined}from".";describe("Given a library for validating data types",function(){describe("when validating a string",function(){it("should return true when the value is a string",function(){expect(isString("a")).toBe(!0),expect(isString("")).toBe(!0)}),it("should return false when the value is not string",function(){expect(isString(1)).toBe(!1),expect(isString(!0)).toBe(!1),expect(isString([])).toBe(!1),expect(isString({})).toBe(!1),expect(isString(void 0)).toBe(!1),expect(isString(null)).toBe(!1),expect(isString(NaN)).toBe(!1)})}),describe("when validating a number",function(){it("should return true when the value is a number",function(){expect(isNumber(1)).toBe(!0),expect(isNumber(0)).toBe(!0),expect(isNumber(1.23)).toBe(!0),expect(isNumber(-1)).toBe(!0)}),it("should return false when the value is not number",function(){expect(isNumber("a")).toBe(!1),expect(isNumber(!0)).toBe(!1),expect(isNumber([])).toBe(!1),expect(isNumber({})).toBe(!1),expect(isNumber(void 0)).toBe(!1),expect(isNumber(null)).toBe(!1),expect(isNumber(NaN)).toBe(!1)})}),describe("when validating an integer",function(){it("should return true when the value is a integer",function(){expect(isInteger(1)).toBe(!0),expect(isInteger(0)).toBe(!0),expect(isInteger(-1)).toBe(!0)}),it("should return false when the value is not an integer",function(){expect(isInteger(1.23)).toBe(!1),expect(isInteger("a")).toBe(!1),expect(isInteger(!0)).toBe(!1),expect(isInteger([])).toBe(!1),expect(isInteger({})).toBe(!1),expect(isInteger(void 0)).toBe(!1),expect(isInteger(null)).toBe(!1),expect(isInteger(NaN)).toBe(!1)})}),describe("when validating a boolean",function(){it("should return true when the value is a boolean",function(){expect(isBoolean(!0)).toBe(!0),expect(isBoolean(!1)).toBe(!0)}),it("should return false when the value is not a boolean",function(){expect(isBoolean(1)).toBe(!1),expect(isBoolean("a")).toBe(!1),expect(isBoolean([])).toBe(!1),expect(isBoolean({})).toBe(!1),expect(isBoolean(void 0)).toBe(!1),expect(isBoolean(null)).toBe(!1),expect(isBoolean(NaN)).toBe(!1)})}),describe("when validating an array",function(){it("should return true when the value is an array",function(){expect(isArray([1])).toBe(!0),expect(isArray([])).toBe(!0)}),it("should return false when the value is not an array",function(){expect(isArray(1)).toBe(!1),expect(isArray("a")).toBe(!1),expect(isArray(!0)).toBe(!1),expect(isArray({})).toBe(!1),expect(isArray(void 0)).toBe(!1),expect(isArray(null)).toBe(!1),expect(isArray(NaN)).toBe(!1)})}),describe("when validating an object",function(){it("should return true when the value is an object",function(){expect(isObject({a:1})).toBe(!0),expect(isObject({})).toBe(!0)}),it("should return false when the value is not an object",function(){expect(isObject(1)).toBe(!1),expect(isObject("a")).toBe(!1),expect(isObject(!0)).toBe(!1),expect(isObject([])).toBe(!1),expect(isObject(void 0)).toBe(!1),expect(isObject(null)).toBe(!1),expect(isObject(NaN)).toBe(!1)})}),describe("when validating a null",function(){it("should return true when the value is null",function(){expect(isNull(null)).toBe(!0)}),it("should return false when the value is not null",function(){expect(isNull(0)).toBe(!1),expect(isNull(!1)).toBe(!1),expect(isNull([])).toBe(!1),expect(isNull({})).toBe(!1),expect(isNull(void 0)).toBe(!1),expect(isNull(NaN)).toBe(!1)})}),describe("when validating an undefined",function(){it("should return true when the value is undefined",function(){expect(isUndefined(void 0)).toBe(!0)}),it("should return false when the value is not undefined",function(){expect(isUndefined(0)).toBe(!1),expect(isUndefined(!1)).toBe(!1),expect(isUndefined([])).toBe(!1),expect(isUndefined({})).toBe(!1),expect(isUndefined(null)).toBe(!1),expect(isUndefined(NaN)).toBe(!1)})})});
@@ -1,5 +0,0 @@
1
- import"core-js/modules/es.object.keys.js";import{isString,isObject,isArray}from"../type-validators";/**
2
- * Checks empty values for arrays,objects and strings.
3
- *
4
- * @param {object | Array | string} value
5
- */var isEmpty=function(a){return isString(a)&&0===a.length||(isObject(a)||isArray(a))&&0===Object.keys(a).length};export{isEmpty};
@@ -1 +0,0 @@
1
- import{isEmpty}from".";describe("Given a library for validating values",function(){describe("when checking for empty values",function(){it("should return true for empty strings",function(){expect(isEmpty("")).toBe(!0),expect(isEmpty("a")).toBe(!1)}),it("should return true for empty array",function(){expect(isEmpty([])).toBe(!0),expect(isEmpty(["a"])).toBe(!1)}),it("should return true for empty object",function(){expect(isEmpty({})).toBe(!0),expect(isEmpty({a:"a"})).toBe(!1)}),it("should return false when the value is not a string, array, or object",function(){expect(isEmpty(1)).toBe(!1),expect(isEmpty(null)).toBe(!1),expect(isEmpty(void 0)).toBe(!1)})})});
@@ -1 +0,0 @@
1
- !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("core-js/modules/es.number.is-nan.js"),require("core-js/modules/es.number.constructor.js"),require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.array.includes.js"),require("core-js/modules/es.string.includes.js")):"function"==typeof define&&define.amd?define(["exports","core-js/modules/es.number.is-nan.js","core-js/modules/es.number.constructor.js","core-js/modules/es.object.keys.js","core-js/modules/es.array.includes.js","core-js/modules/es.string.includes.js"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self)["@transferwise/neptune-validation"]={})}(this,function(e){"use strict";function r(e){return"string"==typeof e}function s(e){return"number"==typeof e&&!Number.isNaN(e)}function n(e){return!t(e)&&!u(e)&&e.constructor===Object}function o(e){return Array.isArray(e)}var t=function(e){return null===e},u=function(e){return void 0===e},i={SPACE:{key:[" ","Spacebar"],keyCode:32},ENTER:{key:"Enter",keyCode:13},TAB:{key:"Tab",keyCode:9},ESCAPE:{key:"Escape",keyCode:27}};e.isArray=o,e.isBoolean=function(e){return"boolean"==typeof e},e.isEmpty=function(e){return r(e)&&0===e.length||(n(e)||o(e))&&0===Object.keys(e).length},e.isInteger=function(e){return s(e)&&Math.floor(e)===e},e.isKey=function(e){var r=e.keyType,s=e.event;if(!r||!s)return!1;e=r.toUpperCase(),r=i[e];if(!r)return!1;e=s.key,s=s.keyCode;return e?o(r.key)?r.key.includes(e):e===r.key:s===r.keyCode},e.isNull=t,e.isNumber=s,e.isObject=n,e.isString=r,e.isUndefined=u,Object.defineProperty(e,"__esModule",{value:!0})});