@transferwise/neptune-validation 0.0.0-experimental-da992bd

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/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2019 Wise Ltd.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # Neptune Web Utilities: Validation
2
+
3
+ `@transferwise/neptune-validation` provides common validators. The package is part of [Neptune Web](https://github.com/transferwise/neptune-web) - the Web portion of Neptune, the Design System built by and used at [TransferWise](http://transferwise.com/).
4
+
5
+ Currently the package includes:
6
+
7
+ - rule validators to validate form input fields.
8
+ - type validators to validate javascript primitive types.
@@ -0,0 +1 @@
1
+ export var keyMap={SPACE:{key:[" ","Spacebar"],keyCode:32},ENTER:{key:"Enter",keyCode:13},TAB:{key:"Tab",keyCode:9},ESCAPE:{key:"Escape",keyCode:27}};
@@ -0,0 +1 @@
1
+ export{default}from"./isKey";
@@ -0,0 +1 @@
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;
@@ -0,0 +1 @@
1
+ export*from"./type-validators";export*from"./value-validators";export{default as isKey}from"./event-validators";
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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)})})});
@@ -0,0 +1,5 @@
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};
@@ -0,0 +1 @@
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)})})});
@@ -0,0 +1 @@
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})});
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@transferwise/neptune-validation",
3
+ "version": "0.0.0-experimental-da992bd",
4
+ "description": "Neptune Web validation",
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
+ "keywords": [
12
+ "wise",
13
+ "neptune-web-validation"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "fullname": "transferwise/neptune-web",
18
+ "url": "git+https://github.com/transferwise/neptune-web.git"
19
+ },
20
+ "dependencies": {
21
+ "@babel/runtime": "^7.18.3",
22
+ "core-js": "^3.8.0"
23
+ },
24
+ "devDependencies": {
25
+ "@rollup/plugin-babel": "^5.2.2",
26
+ "@rollup/plugin-commonjs": "^11.0.2",
27
+ "@rollup/plugin-node-resolve": "^7.1.3",
28
+ "@transferwise/eslint-config": "^7.4.0",
29
+ "@types/jest": "^27.5.2",
30
+ "jest": "^27.0.6",
31
+ "rollup": "^2.34.0",
32
+ "rollup-plugin-uglify": "^6.0.4"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "scripts": {
38
+ "test": "jest --env=node --maxWorkers=4",
39
+ "test:watch": "jest --watch --env=node",
40
+ "lint": "pnpm run lint:check",
41
+ "lint:check": "npm-run-all --parallel lint:check:*",
42
+ "lint:check:format": "prettier --check --ignore-path ../../.prettierignore .",
43
+ "lint:check:js+ts": "eslint --ext .js,.jsx,.mjs,.ts,.tsx,.mts --ignore-path ../../.gitignore .",
44
+ "lint:fix": "npm-run-all --serial lint:fix:*",
45
+ "lint:fix:format": "prettier --write --ignore-path ../../../.prettierignore .",
46
+ "lint:fix:js+ts": "pnpm run lint:check:js+ts --fix",
47
+ "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'"
51
+ }
52
+ }