@punch-in/buffet-modern-utils 3.3.10

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/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Buffet.js Utils
2
+
3
+ ## Getting Started
4
+
5
+ ### Installation
6
+
7
+ Using yarn
8
+
9
+ ```bash
10
+ yarn add @punch-in/buffet-modern-utils
11
+ ```
12
+
13
+ or npm
14
+
15
+ ```bash
16
+ npm install @punch-in/buffet-modern-utils --save
17
+
18
+ ```
19
+
20
+ ### Available commands
21
+
22
+ - **build**<br/>
23
+ Builds the library for production
24
+ - **build:analyze**<br/>
25
+ Analyse the generated build
26
+ - **build:watch**<br/>
27
+ Whatch the files with webpack
28
+ - **build:watch:esm**<br/>
29
+ Whatch the files with babel
30
+ - **create:index**<br/>
31
+ Create the `build/index.js` file
32
+ - **test**<br/>
33
+ Runs the entire set of test: lint, style and jest
34
+ - **test:jest**<br/>
35
+ Runs the unit tests
36
+ - **test:jest:watch**<br/>
37
+ Runs the unit tests in watch mode
38
+ - **test:lint**<br/>
39
+ Runs the lint tests
40
+ - **test:lint:quiet**<br/>
41
+ Runs the lint tests without displaying the warnings
42
+ - **lint:fix**<br/>
43
+ Fixes the lint
@@ -0,0 +1,18 @@
1
+ const defaultPresets = [
2
+ [
3
+ '@babel/preset-env',
4
+ {
5
+ modules: process.env.BABEL_ENV === 'esm' ? false : 'auto',
6
+ },
7
+ ],
8
+ ];
9
+
10
+ module.exports = {
11
+ presets: defaultPresets.concat(['@babel/preset-react', '@babel/preset-flow']),
12
+ plugins: [
13
+ '@babel/plugin-proposal-class-properties',
14
+ '@babel/plugin-proposal-export-default-from',
15
+ '@babel/plugin-proposal-export-namespace-from',
16
+ '@babel/plugin-proposal-function-bind',
17
+ ],
18
+ };
@@ -0,0 +1,158 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory(require("lodash"), require("yup"));
4
+ else if(typeof define === 'function' && define.amd)
5
+ define("@punch-in/buffet-modern-utils", ["lodash", "yup"], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["@punch-in/buffet-modern-utils"] = factory(require("lodash"), require("yup"));
8
+ else
9
+ root["@punch-in/buffet-modern-utils"] = factory(root["lodash"], root["yup"]);
10
+ })(window, function(__WEBPACK_EXTERNAL_MODULE_lodash__, __WEBPACK_EXTERNAL_MODULE_yup__) {
11
+ return /******/ (function(modules) { // webpackBootstrap
12
+ /******/ // The module cache
13
+ /******/ var installedModules = {};
14
+ /******/
15
+ /******/ // The require function
16
+ /******/ function __webpack_require__(moduleId) {
17
+ /******/
18
+ /******/ // Check if module is in cache
19
+ /******/ if(installedModules[moduleId]) {
20
+ /******/ return installedModules[moduleId].exports;
21
+ /******/ }
22
+ /******/ // Create a new module (and put it into the cache)
23
+ /******/ var module = installedModules[moduleId] = {
24
+ /******/ i: moduleId,
25
+ /******/ l: false,
26
+ /******/ exports: {}
27
+ /******/ };
28
+ /******/
29
+ /******/ // Execute the module function
30
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
+ /******/
32
+ /******/ // Flag the module as loaded
33
+ /******/ module.l = true;
34
+ /******/
35
+ /******/ // Return the exports of the module
36
+ /******/ return module.exports;
37
+ /******/ }
38
+ /******/
39
+ /******/
40
+ /******/ // expose the modules object (__webpack_modules__)
41
+ /******/ __webpack_require__.m = modules;
42
+ /******/
43
+ /******/ // expose the module cache
44
+ /******/ __webpack_require__.c = installedModules;
45
+ /******/
46
+ /******/ // define getter function for harmony exports
47
+ /******/ __webpack_require__.d = function(exports, name, getter) {
48
+ /******/ if(!__webpack_require__.o(exports, name)) {
49
+ /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
50
+ /******/ }
51
+ /******/ };
52
+ /******/
53
+ /******/ // define __esModule on exports
54
+ /******/ __webpack_require__.r = function(exports) {
55
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
56
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
57
+ /******/ }
58
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
59
+ /******/ };
60
+ /******/
61
+ /******/ // create a fake namespace object
62
+ /******/ // mode & 1: value is a module id, require it
63
+ /******/ // mode & 2: merge all properties of value into the ns
64
+ /******/ // mode & 4: return value when already ns object
65
+ /******/ // mode & 8|1: behave like require
66
+ /******/ __webpack_require__.t = function(value, mode) {
67
+ /******/ if(mode & 1) value = __webpack_require__(value);
68
+ /******/ if(mode & 8) return value;
69
+ /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
70
+ /******/ var ns = Object.create(null);
71
+ /******/ __webpack_require__.r(ns);
72
+ /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
73
+ /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
74
+ /******/ return ns;
75
+ /******/ };
76
+ /******/
77
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
78
+ /******/ __webpack_require__.n = function(module) {
79
+ /******/ var getter = module && module.__esModule ?
80
+ /******/ function getDefault() { return module['default']; } :
81
+ /******/ function getModuleExports() { return module; };
82
+ /******/ __webpack_require__.d(getter, 'a', getter);
83
+ /******/ return getter;
84
+ /******/ };
85
+ /******/
86
+ /******/ // Object.prototype.hasOwnProperty.call
87
+ /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
88
+ /******/
89
+ /******/ // __webpack_public_path__
90
+ /******/ __webpack_require__.p = "";
91
+ /******/
92
+ /******/
93
+ /******/ // Load entry module and return exports
94
+ /******/ return __webpack_require__(__webpack_require__.s = "./src/index.js");
95
+ /******/ })
96
+ /************************************************************************/
97
+ /******/ ({
98
+
99
+ /***/ "./src/createYupSchema.js":
100
+ /*!********************************!*\
101
+ !*** ./src/createYupSchema.js ***!
102
+ \********************************/
103
+ /*! exports provided: default */
104
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
105
+
106
+ "use strict";
107
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ \"lodash\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var yup__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! yup */ \"yup\");\n/* harmony import */ var yup__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(yup__WEBPACK_IMPORTED_MODULE_1__);\n\n\nconst createYupSchema = (type, validations, translatedErrors = {}) => {\n let schema = yup__WEBPACK_IMPORTED_MODULE_1__[\"mixed\"]();\n if (['text', 'textarea', 'email', 'password', 'select'].includes(type)) {\n schema = yup__WEBPACK_IMPORTED_MODULE_1__[\"string\"](translatedErrors.string);\n }\n if (type === 'email') {\n schema = schema.email(translatedErrors.email);\n }\n if (type === 'number') {\n schema = yup__WEBPACK_IMPORTED_MODULE_1__[\"number\"]().transform(cv => Object(lodash__WEBPACK_IMPORTED_MODULE_0__[\"isNaN\"])(cv) ? undefined : cv).typeError(translatedErrors.number);\n }\n if (['date', 'datetime'].includes(type)) {\n schema = schema.date().typeError(translatedErrors.date);\n }\n Object.keys(validations).forEach(validation => {\n const validationValue = validations[validation];\n if (!!validationValue || !Object(lodash__WEBPACK_IMPORTED_MODULE_0__[\"isBoolean\"])(validationValue) && Number.isInteger(Math.floor(validationValue)) || validationValue === 0) {\n switch (validation) {\n case 'required':\n schema = schema.required(translatedErrors.required);\n break;\n case 'max':\n schema = schema.max(validationValue, translatedErrors.max);\n break;\n case 'maxLength':\n schema = schema.max(validationValue, translatedErrors.maxLength);\n break;\n case 'min':\n schema = schema.min(validationValue, translatedErrors.min);\n break;\n case 'minLength':\n schema = schema.min(validationValue, translatedErrors.minLength);\n break;\n case 'regex':\n schema = schema.matches(validationValue, translatedErrors.regex);\n break;\n case 'lowercase':\n if (['text', 'textarea', 'email', 'string'].includes(type)) {\n schema = schema.strict().lowercase();\n }\n break;\n case 'uppercase':\n if (['text', 'textarea', 'email', 'string'].includes(type)) {\n schema = schema.strict().uppercase(translatedErrors.uppercase);\n }\n break;\n case 'positive':\n if (['number', 'integer', 'bigint', 'float', 'decimal'].includes(type)) {\n schema = schema.positive();\n }\n break;\n case 'negative':\n if (['number', 'integer', 'bigint', 'float', 'decimal'].includes(type)) {\n schema = schema.negative();\n }\n break;\n default:\n }\n }\n });\n return schema;\n};\n/* harmony default export */ __webpack_exports__[\"default\"] = (createYupSchema);\n\n//# sourceURL=webpack://@punch-in/buffet-modern-utils/./src/createYupSchema.js?");
108
+
109
+ /***/ }),
110
+
111
+ /***/ "./src/gradient.js":
112
+ /*!*************************!*\
113
+ !*** ./src/gradient.js ***!
114
+ \*************************/
115
+ /*! exports provided: default */
116
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
117
+
118
+ "use strict";
119
+ eval("__webpack_require__.r(__webpack_exports__);\nconst subtractLight = (color, amount) => {\n const cc = parseInt(color, 16) - amount;\n let c = cc < 0 ? 0 : cc;\n c = c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`;\n return c;\n};\nconst gradient = (colour, amount) => {\n let color = colour.indexOf('#') >= 0 ? colour.substring(1, colour.length) : colour;\n const percentage = parseInt(255 * amount / 100, 10);\n color = `#${subtractLight(color.substring(0, 2), percentage)}${subtractLight(color.substring(2, 4), percentage)}${subtractLight(color.substring(4, 6), percentage)}`;\n return color;\n};\n/* harmony default export */ __webpack_exports__[\"default\"] = (gradient);\n\n//# sourceURL=webpack://@punch-in/buffet-modern-utils/./src/gradient.js?");
120
+
121
+ /***/ }),
122
+
123
+ /***/ "./src/index.js":
124
+ /*!**********************!*\
125
+ !*** ./src/index.js ***!
126
+ \**********************/
127
+ /*! exports provided: createYupSchema, gradient */
128
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
129
+
130
+ "use strict";
131
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _createYupSchema__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./createYupSchema */ \"./src/createYupSchema.js\");\n/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, \"createYupSchema\", function() { return _createYupSchema__WEBPACK_IMPORTED_MODULE_0__[\"default\"]; });\n\n/* harmony import */ var _gradient__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./gradient */ \"./src/gradient.js\");\n/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, \"gradient\", function() { return _gradient__WEBPACK_IMPORTED_MODULE_1__[\"default\"]; });\n\n// Utils\n\n\n\n//# sourceURL=webpack://@punch-in/buffet-modern-utils/./src/index.js?");
132
+
133
+ /***/ }),
134
+
135
+ /***/ "lodash":
136
+ /*!*************************!*\
137
+ !*** external "lodash" ***!
138
+ \*************************/
139
+ /*! no static exports found */
140
+ /***/ (function(module, exports) {
141
+
142
+ eval("module.exports = __WEBPACK_EXTERNAL_MODULE_lodash__;\n\n//# sourceURL=webpack://@punch-in/buffet-modern-utils/external_%22lodash%22?");
143
+
144
+ /***/ }),
145
+
146
+ /***/ "yup":
147
+ /*!**********************!*\
148
+ !*** external "yup" ***!
149
+ \**********************/
150
+ /*! no static exports found */
151
+ /***/ (function(module, exports) {
152
+
153
+ eval("module.exports = __WEBPACK_EXTERNAL_MODULE_yup__;\n\n//# sourceURL=webpack://@punch-in/buffet-modern-utils/external_%22yup%22?");
154
+
155
+ /***/ })
156
+
157
+ /******/ });
158
+ });
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("yup"),require("lodash")):"function"==typeof define&&define.amd?define("@punch-in/buffet-modern-utils",["yup","lodash"],t):"object"==typeof exports?exports["@punch-in/buffet-modern-utils"]=t(require("yup"),require("lodash")):e["@punch-in/buffet-modern-utils"]=t(e.yup,e.lodash)}(window,(function(e,t){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(t,r){t.exports=e},function(e,r){e.exports=t},function(e,t,r){"use strict";r.r(t),r.d(t,"createYupSchema",(function(){return o})),r.d(t,"gradient",(function(){return a}));var n=r(1),i=r(0);var o=(e,t,r={})=>{let o=i.mixed();return["text","textarea","email","password","select"].includes(e)&&(o=i.string(r.string)),"email"===e&&(o=o.email(r.email)),"number"===e&&(o=i.number().transform(e=>Object(n.isNaN)(e)?void 0:e).typeError(r.number)),["date","datetime"].includes(e)&&(o=o.date().typeError(r.date)),Object.keys(t).forEach(i=>{const u=t[i];if(u||!Object(n.isBoolean)(u)&&Number.isInteger(Math.floor(u))||0===u)switch(i){case"required":o=o.required(r.required);break;case"max":o=o.max(u,r.max);break;case"maxLength":o=o.max(u,r.maxLength);break;case"min":o=o.min(u,r.min);break;case"minLength":o=o.min(u,r.minLength);break;case"regex":o=o.matches(u,r.regex);break;case"lowercase":["text","textarea","email","string"].includes(e)&&(o=o.strict().lowercase());break;case"uppercase":["text","textarea","email","string"].includes(e)&&(o=o.strict().uppercase(r.uppercase));break;case"positive":["number","integer","bigint","float","decimal"].includes(e)&&(o=o.positive());break;case"negative":["number","integer","bigint","float","decimal"].includes(e)&&(o=o.negative())}}),o};const u=(e,t)=>{const r=parseInt(e,16)-t;let n=r<0?0:r;return n=n.toString(16).length>1?n.toString(16):"0"+n.toString(16),n};var a=(e,t)=>{let r=e.indexOf("#")>=0?e.substring(1,e.length):e;const n=parseInt(255*t/100,10);return r=`#${u(r.substring(0,2),n)}${u(r.substring(2,4),n)}${u(r.substring(4,6),n)}`,r}}])}));
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _lodash = require("lodash");
8
+ var yup = _interopRequireWildcard(require("yup"));
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ const createYupSchema = (type, validations, translatedErrors = {}) => {
12
+ let schema = yup.mixed();
13
+ if (['text', 'textarea', 'email', 'password', 'select'].includes(type)) {
14
+ schema = yup.string(translatedErrors.string);
15
+ }
16
+ if (type === 'email') {
17
+ schema = schema.email(translatedErrors.email);
18
+ }
19
+ if (type === 'number') {
20
+ schema = yup.number().transform(cv => (0, _lodash.isNaN)(cv) ? undefined : cv).typeError(translatedErrors.number);
21
+ }
22
+ if (['date', 'datetime'].includes(type)) {
23
+ schema = schema.date().typeError(translatedErrors.date);
24
+ }
25
+ Object.keys(validations).forEach(validation => {
26
+ const validationValue = validations[validation];
27
+ if (!!validationValue || !(0, _lodash.isBoolean)(validationValue) && Number.isInteger(Math.floor(validationValue)) || validationValue === 0) {
28
+ switch (validation) {
29
+ case 'required':
30
+ schema = schema.required(translatedErrors.required);
31
+ break;
32
+ case 'max':
33
+ schema = schema.max(validationValue, translatedErrors.max);
34
+ break;
35
+ case 'maxLength':
36
+ schema = schema.max(validationValue, translatedErrors.maxLength);
37
+ break;
38
+ case 'min':
39
+ schema = schema.min(validationValue, translatedErrors.min);
40
+ break;
41
+ case 'minLength':
42
+ schema = schema.min(validationValue, translatedErrors.minLength);
43
+ break;
44
+ case 'regex':
45
+ schema = schema.matches(validationValue, translatedErrors.regex);
46
+ break;
47
+ case 'lowercase':
48
+ if (['text', 'textarea', 'email', 'string'].includes(type)) {
49
+ schema = schema.strict().lowercase();
50
+ }
51
+ break;
52
+ case 'uppercase':
53
+ if (['text', 'textarea', 'email', 'string'].includes(type)) {
54
+ schema = schema.strict().uppercase(translatedErrors.uppercase);
55
+ }
56
+ break;
57
+ case 'positive':
58
+ if (['number', 'integer', 'bigint', 'float', 'decimal'].includes(type)) {
59
+ schema = schema.positive();
60
+ }
61
+ break;
62
+ case 'negative':
63
+ if (['number', 'integer', 'bigint', 'float', 'decimal'].includes(type)) {
64
+ schema = schema.negative();
65
+ }
66
+ break;
67
+ default:
68
+ }
69
+ }
70
+ });
71
+ return schema;
72
+ };
73
+ var _default = exports.default = createYupSchema;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const subtractLight = (color, amount) => {
8
+ const cc = parseInt(color, 16) - amount;
9
+ let c = cc < 0 ? 0 : cc;
10
+ c = c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`;
11
+ return c;
12
+ };
13
+ const gradient = (colour, amount) => {
14
+ let color = colour.indexOf('#') >= 0 ? colour.substring(1, colour.length) : colour;
15
+ const percentage = parseInt(255 * amount / 100, 10);
16
+ color = `#${subtractLight(color.substring(0, 2), percentage)}${subtractLight(color.substring(2, 4), percentage)}${subtractLight(color.substring(4, 6), percentage)}`;
17
+ return color;
18
+ };
19
+ var _default = exports.default = gradient;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "createYupSchema", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _createYupSchema.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "gradient", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _gradient.default;
16
+ }
17
+ });
18
+ var _createYupSchema = _interopRequireDefault(require("./createYupSchema"));
19
+ var _gradient = _interopRequireDefault(require("./gradient"));
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
package/build/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict';
3
+
4
+ if (process.env.NODE_ENV === "production") {
5
+ module.exports = require("./bundle.production.js");
6
+ } else {
7
+ module.exports = require("./bundle.development.js");
8
+ }
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@punch-in/buffet-modern-utils",
3
+ "version": "3.3.10",
4
+ "description": "Buffetjs Utils",
5
+ "main": "build",
6
+ "module": "build/esm/index.js",
7
+ "bundlesize": [
8
+ {
9
+ "path": "build/bundle.production.js"
10
+ }
11
+ ],
12
+ "scripts": {
13
+ "prebuild": "rimraf build",
14
+ "build": "npm run build:development && npm run build:production && npm run build:esm && npm run create:index",
15
+ "build:analyze": "cross-env NODE_ENV=production webpack-cli --json > build/stats.production.json && webpack-bundle-analyzer build/stats.production.json",
16
+ "build:development": "cross-env NODE_ENV=development webpack-cli",
17
+ "build:esm": "cross-env BABEL_ENV=esm babel ./src --out-dir ./build/esm --ignore \"**/*.test.js\" --ignore \"**/test.js\"",
18
+ "build:production": "cross-env NODE_ENV=production webpack-cli",
19
+ "build:watch": "npm run create:index && cross-env NODE_ENV=development webpack-cli -w",
20
+ "build:watch:esm": "cross-env BABEL_ENV=esm babel ./src --out-dir ./build/esm --ignore \"**/*.test.js\" --ignore \"**/test.js\" --watch",
21
+ "create:index": "node ./createBuildIndex.js",
22
+ "test": "npm run test:lint",
23
+ "test:lint": "eslint .",
24
+ "test:lint:quiet": "eslint . --quiet",
25
+ "lint:fix": "eslint . --fix",
26
+ "prepublishOnly": "npm run build"
27
+ },
28
+ "author": "Strapi team",
29
+ "license": "MIT",
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "dependencies": {
34
+ "lodash": "4.17.21",
35
+ "yup": "^0.32.9"
36
+ },
37
+ "devDependencies": {
38
+ "@babel/cli": "^7.1.5",
39
+ "@babel/core": "^7.1.6",
40
+ "@babel/eslint-parser": "^7.22.0",
41
+ "@babel/plugin-proposal-export-default-from": "^7.0.0",
42
+ "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
43
+ "@babel/plugin-proposal-function-bind": "^7.0.0",
44
+ "@babel/plugin-transform-class-properties": "^7.1.0",
45
+ "@babel/plugin-transform-flow-strip-types": "^7.1.6",
46
+ "@babel/preset-env": "^7.1.6",
47
+ "@babel/preset-flow": "^7.0.0",
48
+ "@babel/preset-react": "^7.0.0",
49
+ "babel-jest": "^23.6.0",
50
+ "babel-loader": "^8.0.4",
51
+ "babel-plugin-module-resolver": "3.0.0",
52
+ "bundlesize": "^0.17.0",
53
+ "cross-env": "^5.1.4",
54
+ "eslint": "^7.5.0",
55
+ "eslint-config-airbnb": "^18.2.0",
56
+ "eslint-config-prettier": "^6.11.0",
57
+ "eslint-import-resolver-lerna": "^1.1.0",
58
+ "eslint-import-resolver-webpack": "^0.12.2",
59
+ "eslint-plugin-import": "^2.22.0",
60
+ "eslint-plugin-jest": "^23.19.0",
61
+ "eslint-plugin-jsx-a11y": "^6.3.1",
62
+ "eslint-plugin-react": "^7.20.5",
63
+ "rimraf": "^3.0.2",
64
+ "url-loader": "^1.0.1",
65
+ "webpack": "~4.44.0",
66
+ "webpack-bundle-analyzer": "^3.8.0",
67
+ "webpack-cli": "~3.3.12"
68
+ },
69
+ "peerDependencies": {
70
+ "lodash": "4.17.21",
71
+ "yup": "^0.32.9"
72
+ },
73
+ "repository": {
74
+ "type": "git",
75
+ "url": "https://github.com/strapi/buffet"
76
+ },
77
+ "gitHead": "c81129423fe7c1a0f5bdfeff023d157ab1ee4767"
78
+ }
@@ -0,0 +1,86 @@
1
+ import { isBoolean, isNaN } from 'lodash';
2
+ import * as yup from 'yup';
3
+
4
+ const createYupSchema = (type, validations, translatedErrors = {}) => {
5
+ let schema = yup.mixed();
6
+
7
+ if (['text', 'textarea', 'email', 'password', 'select'].includes(type)) {
8
+ schema = yup.string(translatedErrors.string);
9
+ }
10
+
11
+ if (type === 'email') {
12
+ schema = schema.email(translatedErrors.email);
13
+ }
14
+
15
+ if (type === 'number') {
16
+ schema = yup
17
+ .number()
18
+ .transform(cv => (isNaN(cv) ? undefined : cv))
19
+ .typeError(translatedErrors.number);
20
+ }
21
+
22
+ if (['date', 'datetime'].includes(type)) {
23
+ schema = schema.date().typeError(translatedErrors.date);
24
+ }
25
+
26
+ Object.keys(validations).forEach(validation => {
27
+ const validationValue = validations[validation];
28
+
29
+ if (
30
+ !!validationValue ||
31
+ (!isBoolean(validationValue) &&
32
+ Number.isInteger(Math.floor(validationValue))) ||
33
+ validationValue === 0
34
+ ) {
35
+ switch (validation) {
36
+ case 'required':
37
+ schema = schema.required(translatedErrors.required);
38
+ break;
39
+ case 'max':
40
+ schema = schema.max(validationValue, translatedErrors.max);
41
+ break;
42
+ case 'maxLength':
43
+ schema = schema.max(validationValue, translatedErrors.maxLength);
44
+ break;
45
+ case 'min':
46
+ schema = schema.min(validationValue, translatedErrors.min);
47
+ break;
48
+ case 'minLength':
49
+ schema = schema.min(validationValue, translatedErrors.minLength);
50
+ break;
51
+ case 'regex':
52
+ schema = schema.matches(validationValue, translatedErrors.regex);
53
+ break;
54
+ case 'lowercase':
55
+ if (['text', 'textarea', 'email', 'string'].includes(type)) {
56
+ schema = schema.strict().lowercase();
57
+ }
58
+ break;
59
+ case 'uppercase':
60
+ if (['text', 'textarea', 'email', 'string'].includes(type)) {
61
+ schema = schema.strict().uppercase(translatedErrors.uppercase);
62
+ }
63
+ break;
64
+ case 'positive':
65
+ if (
66
+ ['number', 'integer', 'bigint', 'float', 'decimal'].includes(type)
67
+ ) {
68
+ schema = schema.positive();
69
+ }
70
+ break;
71
+ case 'negative':
72
+ if (
73
+ ['number', 'integer', 'bigint', 'float', 'decimal'].includes(type)
74
+ ) {
75
+ schema = schema.negative();
76
+ }
77
+ break;
78
+ default:
79
+ }
80
+ }
81
+ });
82
+
83
+ return schema;
84
+ };
85
+
86
+ export default createYupSchema;
@@ -0,0 +1,21 @@
1
+ const subtractLight = (color, amount) => {
2
+ const cc = parseInt(color, 16) - amount;
3
+ let c = cc < 0 ? 0 : cc;
4
+ c = c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`;
5
+
6
+ return c;
7
+ };
8
+
9
+ const gradient = (colour, amount) => {
10
+ let color =
11
+ colour.indexOf('#') >= 0 ? colour.substring(1, colour.length) : colour;
12
+ const percentage = parseInt((255 * amount) / 100, 10);
13
+ color = `#${subtractLight(color.substring(0, 2), percentage)}${subtractLight(
14
+ color.substring(2, 4),
15
+ percentage
16
+ )}${subtractLight(color.substring(4, 6), percentage)}`;
17
+
18
+ return color;
19
+ };
20
+
21
+ export default gradient;
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ // Utils
2
+ export { default as createYupSchema } from './createYupSchema';
3
+ export { default as gradient } from './gradient';