@transferwise/neptune-validation 3.1.0 → 3.2.0
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/common/keyMap.d.ts +19 -0
- package/dist/common/keyMap.d.ts.map +1 -0
- package/dist/event-validators/index.d.ts +2 -0
- package/dist/event-validators/index.d.ts.map +1 -0
- package/dist/event-validators/isKey.d.ts +6 -0
- package/dist/event-validators/isKey.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +5 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +5 -8
- package/dist/index.js.map +1 -1
- package/dist/type-validators/index.d.ts +9 -0
- package/dist/type-validators/index.d.ts.map +1 -0
- package/dist/value-validators/index.d.ts +5 -0
- package/dist/value-validators/index.d.ts.map +1 -0
- package/package.json +1 -2
- package/src/common/{keyMap.js → keyMap.ts} +1 -1
- package/src/event-validators/{isKey.js → isKey.ts} +3 -3
- package/src/type-validators/index.ts +13 -0
- package/src/value-validators/{index.js → index.ts} +2 -6
- package/src/type-validators/index.js +0 -13
- /package/src/event-validators/{index.js → index.ts} +0 -0
- /package/src/event-validators/{isKey.spec.js → isKey.spec.ts} +0 -0
- /package/src/{index.js → index.ts} +0 -0
- /package/src/type-validators/{spec.js → index.spec.ts} +0 -0
- /package/src/value-validators/{spec.js → index.spec.ts} +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const keyMap: {
|
|
2
|
+
readonly SPACE: {
|
|
3
|
+
readonly key: readonly [" ", "Spacebar"];
|
|
4
|
+
readonly keyCode: 32;
|
|
5
|
+
};
|
|
6
|
+
readonly ENTER: {
|
|
7
|
+
readonly key: "Enter";
|
|
8
|
+
readonly keyCode: 13;
|
|
9
|
+
};
|
|
10
|
+
readonly TAB: {
|
|
11
|
+
readonly key: "Tab";
|
|
12
|
+
readonly keyCode: 9;
|
|
13
|
+
};
|
|
14
|
+
readonly ESCAPE: {
|
|
15
|
+
readonly key: "Escape";
|
|
16
|
+
readonly keyCode: 27;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=keyMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyMap.d.ts","sourceRoot":"","sources":["../../src/common/keyMap.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;CAKT,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/event-validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isKey.d.ts","sourceRoot":"","sources":["../../src/event-validators/isKey.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,KAAK;;;aAkBV,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.esm.js
CHANGED
|
@@ -4,15 +4,13 @@ const isInteger = value => {
|
|
|
4
4
|
return isNumber(value) && Math.floor(value) === value;
|
|
5
5
|
};
|
|
6
6
|
const isBoolean = value => typeof value === 'boolean';
|
|
7
|
-
const isObject = value =>
|
|
7
|
+
const isObject = value => typeof value === 'object' && !isNull(value) && value.constructor === Object;
|
|
8
8
|
const isArray = value => Array.isArray(value);
|
|
9
9
|
const isNull = value => value === null;
|
|
10
10
|
const isUndefined = value => typeof value === 'undefined';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Checks empty values for arrays,objects and strings.
|
|
14
|
-
*
|
|
15
|
-
* @param {object | Array | string} value
|
|
13
|
+
* Checks empty values for arrays, objects and strings.
|
|
16
14
|
*/
|
|
17
15
|
const isEmpty = value => isString(value) && value.length === 0 || (isObject(value) || isArray(value)) && Object.keys(value).length === 0;
|
|
18
16
|
|
|
@@ -43,10 +41,10 @@ const isKey = ({
|
|
|
43
41
|
return false;
|
|
44
42
|
}
|
|
45
43
|
const upperCaseKeyType = keyType.toUpperCase();
|
|
46
|
-
|
|
47
|
-
if (!keyDef) {
|
|
44
|
+
if (!Object.hasOwn(keyMap, upperCaseKeyType)) {
|
|
48
45
|
return false;
|
|
49
46
|
}
|
|
47
|
+
const keyDef = keyMap[upperCaseKeyType];
|
|
50
48
|
const {
|
|
51
49
|
key,
|
|
52
50
|
keyCode
|
|
@@ -56,7 +54,6 @@ const isKey = ({
|
|
|
56
54
|
}
|
|
57
55
|
return keyCode === keyDef.keyCode;
|
|
58
56
|
};
|
|
59
|
-
var isKey$1 = isKey;
|
|
60
57
|
|
|
61
|
-
export { isArray, isBoolean, isEmpty, isInteger, isKey
|
|
58
|
+
export { isArray, isBoolean, isEmpty, isInteger, isKey, isNull, isNumber, isObject, isString, isUndefined };
|
|
62
59
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/type-validators/index.
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/type-validators/index.ts","../src/value-validators/index.ts","../src/common/keyMap.ts","../src/event-validators/isKey.ts"],"sourcesContent":[null,null,null,null],"names":["isString","value","isNumber","isNaN","isInteger","Math","floor","isBoolean","isObject","isNull","constructor","Object","isArray","Array","keyMap","event"],"mappings":"AAAA,MAAAA,QAAa,GAAAC,KAAmB,IAAA,OAAAA;MAChCC,QAAa,GAAAD,KAAmB,IAAA,OAAAA,6BACoB,CAAAE,KAAA,CAAAF,KAAA,EAAA;AACpDG,MAAAA,SAAa,GAAAH,KAAoB,IAAA;AAGjC,EAAA,OAAAC,QAAa,CAAAD,KAAA,CAAA,IAASI,IAAW,CAAAC,KAAA,CAAAL,KAAA,CAAO;AAExC,EAAA;AAEA,MAAAM,SAAa,GAAAN,KAAkB,IAAA,OAAAA;AAC/B,MAAAO,QAAa,GAAAP,KAAiB,IAAA,OAAAA,sBAA0C,CAAAQ,MAAA,CAAAR,KAAA,CAAA,IAAAA,KAAA,CAAAS,WAAA,KAAAC,OAAA;AACxE,MAAAC,OAAa,GAAAX,KAAA,IAAsBY,KAAA,CAAAD,OAAA,CAAAX;;;;;ACRhC;AACH;;;ACLA,MAAAa,SAAmB;;;;;;;;;;;;;;;;;;;;;;;cCqBjB,IAAA,CAAAC,KAAA,EAAA;AAEF,IAAA,OAAe,KAAK,CAAA;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -6,15 +6,13 @@ const isInteger = value => {
|
|
|
6
6
|
return isNumber(value) && Math.floor(value) === value;
|
|
7
7
|
};
|
|
8
8
|
const isBoolean = value => typeof value === 'boolean';
|
|
9
|
-
const isObject = value =>
|
|
9
|
+
const isObject = value => typeof value === 'object' && !isNull(value) && value.constructor === Object;
|
|
10
10
|
const isArray = value => Array.isArray(value);
|
|
11
11
|
const isNull = value => value === null;
|
|
12
12
|
const isUndefined = value => typeof value === 'undefined';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Checks empty values for arrays,objects and strings.
|
|
16
|
-
*
|
|
17
|
-
* @param {object | Array | string} value
|
|
15
|
+
* Checks empty values for arrays, objects and strings.
|
|
18
16
|
*/
|
|
19
17
|
const isEmpty = value => isString(value) && value.length === 0 || (isObject(value) || isArray(value)) && Object.keys(value).length === 0;
|
|
20
18
|
|
|
@@ -45,10 +43,10 @@ const isKey = ({
|
|
|
45
43
|
return false;
|
|
46
44
|
}
|
|
47
45
|
const upperCaseKeyType = keyType.toUpperCase();
|
|
48
|
-
|
|
49
|
-
if (!keyDef) {
|
|
46
|
+
if (!Object.hasOwn(keyMap, upperCaseKeyType)) {
|
|
50
47
|
return false;
|
|
51
48
|
}
|
|
49
|
+
const keyDef = keyMap[upperCaseKeyType];
|
|
52
50
|
const {
|
|
53
51
|
key,
|
|
54
52
|
keyCode
|
|
@@ -58,13 +56,12 @@ const isKey = ({
|
|
|
58
56
|
}
|
|
59
57
|
return keyCode === keyDef.keyCode;
|
|
60
58
|
};
|
|
61
|
-
var isKey$1 = isKey;
|
|
62
59
|
|
|
63
60
|
exports.isArray = isArray;
|
|
64
61
|
exports.isBoolean = isBoolean;
|
|
65
62
|
exports.isEmpty = isEmpty;
|
|
66
63
|
exports.isInteger = isInteger;
|
|
67
|
-
exports.isKey = isKey
|
|
64
|
+
exports.isKey = isKey;
|
|
68
65
|
exports.isNull = isNull;
|
|
69
66
|
exports.isNumber = isNumber;
|
|
70
67
|
exports.isObject = isObject;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/type-validators/index.
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/type-validators/index.ts","../src/value-validators/index.ts","../src/common/keyMap.ts","../src/event-validators/isKey.ts"],"sourcesContent":[null,null,null,null],"names":["isString","value","isNumber","isNaN","isInteger","Math","floor","isBoolean","isObject","isNull","constructor","Object","isArray","Array","keyMap","event"],"mappings":";;AAAA,MAAAA,QAAa,GAAAC,KAAmB,IAAA,OAAAA;MAChCC,QAAa,GAAAD,KAAmB,IAAA,OAAAA,6BACoB,CAAAE,KAAA,CAAAF,KAAA,EAAA;AACpDG,MAAAA,SAAa,GAAAH,KAAoB,IAAA;AAGjC,EAAA,OAAAC,QAAa,CAAAD,KAAA,CAAA,IAASI,IAAW,CAAAC,KAAA,CAAAL,KAAA,CAAO;AAExC,EAAA;AAEA,MAAAM,SAAa,GAAAN,KAAkB,IAAA,OAAAA;AAC/B,MAAAO,QAAa,GAAAP,KAAiB,IAAA,OAAAA,sBAA0C,CAAAQ,MAAA,CAAAR,KAAA,CAAA,IAAAA,KAAA,CAAAS,WAAA,KAAAC,OAAA;AACxE,MAAAC,OAAa,GAAAX,KAAA,IAAsBY,KAAA,CAAAD,OAAA,CAAAX;;;;;ACRhC;AACH;;;ACLA,MAAAa,SAAmB;;;;;;;;;;;;;;;;;;;;;;;cCqBjB,IAAA,CAAAC,KAAA,EAAA;AAEF,IAAA,OAAe,KAAK,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const isString: (value: unknown) => value is string;
|
|
2
|
+
export declare const isNumber: (value: unknown) => value is number;
|
|
3
|
+
export declare const isInteger: (value: unknown) => value is number;
|
|
4
|
+
export declare const isBoolean: (value: unknown) => value is boolean;
|
|
5
|
+
export declare const isObject: (value: unknown) => value is Record<string, unknown>;
|
|
6
|
+
export declare const isArray: (value: unknown) => value is unknown[];
|
|
7
|
+
export declare const isNull: (value: unknown) => value is null;
|
|
8
|
+
export declare const isUndefined: (value: unknown) => value is undefined;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/type-validators/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,UAAW,OAAO,oBAA+C,CAAC;AACvF,eAAO,MAAM,QAAQ,UAAW,OAAO,oBACY,CAAC;AACpD,eAAO,MAAM,SAAS,UAAW,OAAO,oBAEvC,CAAC;AACF,eAAO,MAAM,SAAS,UAAW,OAAO,qBAAiD,CAAC;AAE1F,eAAO,MAAM,QAAQ,UAAW,OAAO,qCACsC,CAAC;AAC9E,eAAO,MAAM,OAAO,UAAW,OAAO,uBAA6C,CAAC;AACpF,eAAO,MAAM,MAAM,UAAW,OAAO,kBAAkC,CAAC;AACxE,eAAO,MAAM,WAAW,UAAW,OAAO,uBAAqD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/value-validators/index.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,OAAO,UAAW,OAAO,YAEoC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/neptune-validation",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Neptune Web validation",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"@babel/core": "^7.22.15",
|
|
33
33
|
"@babel/plugin-transform-runtime": "^7.22.15",
|
|
34
34
|
"@babel/preset-env": "^7.22.15",
|
|
35
|
-
"@babel/preset-react": "^7.22.15",
|
|
36
35
|
"@babel/preset-typescript": "^7.22.15",
|
|
37
36
|
"@rollup/plugin-babel": "^6.0.3",
|
|
38
37
|
"@rollup/plugin-node-resolve": "^15.2.1",
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { keyMap } from '../common/keyMap';
|
|
2
2
|
import { isArray } from '../type-validators';
|
|
3
3
|
|
|
4
|
-
const isKey = ({ keyType, event }) => {
|
|
4
|
+
const isKey = ({ keyType, event }: { keyType?: string; event?: Partial<KeyboardEvent> | null }) => {
|
|
5
5
|
if (!keyType || !event) {
|
|
6
6
|
return false;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const upperCaseKeyType = keyType.toUpperCase();
|
|
10
|
-
|
|
11
|
-
if (!keyDef) {
|
|
10
|
+
if (!Object.hasOwn(keyMap, upperCaseKeyType)) {
|
|
12
11
|
return false;
|
|
13
12
|
}
|
|
13
|
+
const keyDef = keyMap[upperCaseKeyType as keyof typeof keyMap];
|
|
14
14
|
|
|
15
15
|
const { key, keyCode } = event;
|
|
16
16
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const isString = (value: unknown): value is string => typeof value === 'string';
|
|
2
|
+
export const isNumber = (value: unknown): value is number =>
|
|
3
|
+
typeof value === 'number' && !Number.isNaN(value);
|
|
4
|
+
export const isInteger = (value: unknown): value is number => {
|
|
5
|
+
return isNumber(value) && Math.floor(value) === value;
|
|
6
|
+
};
|
|
7
|
+
export const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean';
|
|
8
|
+
|
|
9
|
+
export const isObject = (value: unknown): value is Record<string, unknown> =>
|
|
10
|
+
typeof value === 'object' && !isNull(value) && value.constructor === Object;
|
|
11
|
+
export const isArray = (value: unknown): value is unknown[] => Array.isArray(value);
|
|
12
|
+
export const isNull = (value: unknown): value is null => value === null;
|
|
13
|
+
export const isUndefined = (value: unknown): value is undefined => typeof value === 'undefined';
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { isString, isObject, isArray } from '../type-validators';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Checks empty values for arrays,objects and strings.
|
|
5
|
-
*
|
|
6
|
-
* @param {object | Array | string} value
|
|
4
|
+
* Checks empty values for arrays, objects and strings.
|
|
7
5
|
*/
|
|
8
|
-
const isEmpty = (value) =>
|
|
6
|
+
export const isEmpty = (value: unknown) =>
|
|
9
7
|
(isString(value) && value.length === 0) ||
|
|
10
8
|
((isObject(value) || isArray(value)) && Object.keys(value).length === 0);
|
|
11
|
-
|
|
12
|
-
export { isEmpty };
|
|
@@ -1,13 +0,0 @@
|
|
|
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 };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|