jis 1.0.30 → 1.0.34

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 CHANGED
@@ -170,6 +170,48 @@ jis.$numeric( null ) // false
170
170
 
171
171
  ```
172
172
 
173
+ ##### $primitive
174
+
175
+ Check if the argument is primitive type
176
+
177
+ ```js
178
+
179
+ jis.$primitive(undefined) // true
180
+ jis.$primitive(null) // true
181
+ jis.$primitive("something") // true
182
+ jis.$primitive(true) // true
183
+ jis.$primitive(false) // true
184
+ jis.$primitive(12) // true
185
+ jis.$primitive(Symbol()) // true
186
+
187
+ jis.$primitive({}) // false
188
+ jis.$primitive([]) // false
189
+ jis.$primitive(new Date()) // false
190
+
191
+ ```
192
+
193
+ ##### $empty
194
+
195
+ ```js
196
+
197
+ jis.$empty(null) // true
198
+ jis.$empty(undefined) // true
199
+ jis.$empty(false) // true
200
+ jis.$empty(0) // true
201
+ jis.$empty(0.0) // true
202
+ jis.$empty("") // true
203
+ jis.$empty("0") // true
204
+ jis.$empty([]) // true
205
+
206
+ jis.$empty(true) // false
207
+ jis.$empty(12) // false
208
+ jis.$empty(12.0) // false
209
+ jis.$empty("something") // false
210
+ jis.$empty("012") // false
211
+ jis.$empty([1, 2, 3]) // false
212
+
213
+ ```
214
+
173
215
  ##### is
174
216
 
175
217
  This method is the library core. Have more options.
package/dist/jis.js ADDED
@@ -0,0 +1,160 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define("jis", [], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["jis"] = factory();
8
+ else
9
+ root["jis"] = factory();
10
+ })(this, function() {
11
+ return /******/ (() => { // webpackBootstrap
12
+ /******/ "use strict";
13
+ /******/ var __webpack_modules__ = ({
14
+
15
+ /***/ 138:
16
+ /***/ ((__unused_webpack_module, exports) => {
17
+
18
+
19
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
20
+ var Is = /** @class */ (function () {
21
+ function Is() {
22
+ }
23
+ Is.callToString = function (arg) {
24
+ return Object.prototype.toString.call(arg);
25
+ };
26
+ Is.$string = function (arg) {
27
+ return Is.callToString(arg) === '[object String]';
28
+ };
29
+ Is.is = function (arg, type) {
30
+ if (Is.$function(type)) {
31
+ return arg instanceof type;
32
+ }
33
+ if (Is.$string(type)) {
34
+ return Is.callToString(arg) === "[object " + type + "]";
35
+ }
36
+ return arg === type;
37
+ };
38
+ Is.$array = function (arg) {
39
+ return Is.is(arg, 'Array');
40
+ };
41
+ Is.$null = function (arg) {
42
+ return Is.is(arg, 'Null');
43
+ };
44
+ Is.$number = function (arg) {
45
+ return Is.is(arg, 'Number');
46
+ };
47
+ Is.$object = function (arg) {
48
+ return Is.is(arg, 'Object');
49
+ };
50
+ Is.$undefined = function (arg) {
51
+ return Is.is(arg, 'Undefined');
52
+ };
53
+ Is.$boolean = function (arg) {
54
+ return Is.is(arg, 'Boolean');
55
+ };
56
+ Is.$function = function (arg) {
57
+ return Is.callToString(arg) === '[object Function]';
58
+ };
59
+ Is.objectIsValid = function (data, rules) {
60
+ if (!Is.$object(data))
61
+ throw new Error('The data parameter must be an Object');
62
+ if (!Is.$object(rules))
63
+ throw new Error('The rules parameter must be an Object');
64
+ var $response = true;
65
+ var $keys = Object.getOwnPropertyNames(rules);
66
+ $keys.forEach(function (key) {
67
+ var rule = rules[key];
68
+ if (Is.$array(rule)) {
69
+ if (rule.length < 1)
70
+ return;
71
+ var parcial_1 = false;
72
+ rule.forEach(function (_rule) {
73
+ parcial_1 = parcial_1 || Is.is(data[key], _rule);
74
+ });
75
+ return $response = $response && parcial_1;
76
+ }
77
+ $response = $response && Is.is(data[key], rule);
78
+ });
79
+ return $response;
80
+ };
81
+ Is.$numeric = function (arg) {
82
+ if (Is.$number(arg)) {
83
+ return true;
84
+ }
85
+ var $arg = String(arg || '');
86
+ var regex = /^[-+]?(([0-9]+)|([0-9]*(\.[0-9]+))|([0-9]+\.))([Ee]([-+]?[0-9]+))?$/g;
87
+ return regex.test($arg);
88
+ };
89
+ Is.$primitive = function (arg) {
90
+ var validations = [
91
+ Is.$undefined,
92
+ Is.$null,
93
+ Is.$boolean,
94
+ Is.$number,
95
+ Is.$string,
96
+ function (arg) { return Is.is(arg, 'Symbol'); }
97
+ ];
98
+ return validations.some(function (item) { return item(arg); });
99
+ };
100
+ Is.$empty = function (arg) {
101
+ var validations = [
102
+ Is.$undefined,
103
+ Is.$null,
104
+ function (arg) { return Is.$boolean(arg) && !arg; },
105
+ function (arg) { return Is.$number(arg) && arg === 0; },
106
+ function (arg) { return (Is.$array(arg) || Is.$string(arg)) && (arg === "0" || arg.length === 0); }
107
+ ];
108
+ return validations.some(function (item) { return item(arg); });
109
+ };
110
+ return Is;
111
+ }());
112
+ exports.default = Is;
113
+
114
+
115
+ /***/ })
116
+
117
+ /******/ });
118
+ /************************************************************************/
119
+ /******/ // The module cache
120
+ /******/ var __webpack_module_cache__ = {};
121
+ /******/
122
+ /******/ // The require function
123
+ /******/ function __webpack_require__(moduleId) {
124
+ /******/ // Check if module is in cache
125
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
126
+ /******/ if (cachedModule !== undefined) {
127
+ /******/ return cachedModule.exports;
128
+ /******/ }
129
+ /******/ // Create a new module (and put it into the cache)
130
+ /******/ var module = __webpack_module_cache__[moduleId] = {
131
+ /******/ // no module.id needed
132
+ /******/ // no module.loaded needed
133
+ /******/ exports: {}
134
+ /******/ };
135
+ /******/
136
+ /******/ // Execute the module function
137
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
138
+ /******/
139
+ /******/ // Return the exports of the module
140
+ /******/ return module.exports;
141
+ /******/ }
142
+ /******/
143
+ /************************************************************************/
144
+ var __webpack_exports__ = {};
145
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
146
+ (() => {
147
+ var exports = __webpack_exports__;
148
+ var __webpack_unused_export__;
149
+
150
+ __webpack_unused_export__ = ({ value: true });
151
+ var Is_1 = __webpack_require__(138);
152
+ exports.default = Is_1.default;
153
+
154
+ })();
155
+
156
+ __webpack_exports__ = __webpack_exports__.default;
157
+ /******/ return __webpack_exports__;
158
+ /******/ })()
159
+ ;
160
+ });
@@ -0,0 +1 @@
1
+ !function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("jis",[],t):"object"==typeof exports?exports.jis=t():n.jis=t()}(this,function(){return(()=>{"use strict";var e={138:(n,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var e=(i.callToString=function(n){return Object.prototype.toString.call(n)},i.$string=function(n){return"[object String]"===i.callToString(n)},i.is=function(n,t){return i.$function(t)?n instanceof t:i.$string(t)?i.callToString(n)==="[object "+t+"]":n===t},i.$array=function(n){return i.is(n,"Array")},i.$null=function(n){return i.is(n,"Null")},i.$number=function(n){return i.is(n,"Number")},i.$object=function(n){return i.is(n,"Object")},i.$undefined=function(n){return i.is(n,"Undefined")},i.$boolean=function(n){return i.is(n,"Boolean")},i.$function=function(n){return"[object Function]"===i.callToString(n)},i.objectIsValid=function(r,o){if(!i.$object(r))throw new Error("The data parameter must be an Object");if(!i.$object(o))throw new Error("The rules parameter must be an Object");var u=!0;return Object.getOwnPropertyNames(o).forEach(function(t){var n=o[t];if(i.$array(n)){if(n.length<1)return;var e=!1;return n.forEach(function(n){e=e||i.is(r[t],n)}),u=u&&e}u=u&&i.is(r[t],n)}),u},i.$numeric=function(n){if(i.$number(n))return!0;n=String(n||"");return/^[-+]?(([0-9]+)|([0-9]*(\.[0-9]+))|([0-9]+\.))([Ee]([-+]?[0-9]+))?$/g.test(n)},i.$primitive=function(t){return[i.$undefined,i.$null,i.$boolean,i.$number,i.$string,function(n){return i.is(n,"Symbol")}].some(function(n){return n(t)})},i.$empty=function(t){return[i.$undefined,i.$null,function(n){return i.$boolean(n)&&!n},function(n){return i.$number(n)&&0===n},function(n){return(i.$array(n)||i.$string(n))&&("0"===n||0===n.length)}].some(function(n){return n(t)})},i);function i(){}t.default=e}},r={};function o(n){var t=r[n];if(void 0!==t)return t.exports;t=r[n]={exports:{}};return e[n](t,t.exports,o),t.exports}var n,t,u={};return n=u,t=o(138),n.default=t.default,u.default})()});
package/index.html ADDED
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Title</title>
6
+ </head>
7
+ <body>
8
+ <script src="dist/jis.min.js"></script>
9
+ </body>
10
+ </html>
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "jis",
3
- "version": "1.0.30",
3
+ "version": "1.0.34",
4
4
  "description": "When you need validate the variable data type",
5
- "main": "index.js",
5
+ "main": "dist/jis.js",
6
6
  "types": "types/index.d.ts",
7
7
  "scripts": {
8
8
  "test": "mocha test.js",
9
- "build": "tsc src/*.ts --outDir build/"
9
+ "build": "webpack"
10
10
  },
11
11
  "keywords": [
12
12
  "Is",
@@ -27,8 +27,13 @@
27
27
  "devDependencies": {
28
28
  "chai": "^4.2.0",
29
29
  "mocha": "^8.2.1",
30
+ "ts-loader": "^9.2.2",
30
31
  "tsc": "^1.20150623.0",
31
- "typescript": "^4.0.5"
32
+ "typescript": "^4.0.5",
33
+ "webpack-cli": "^4.7.0"
32
34
  },
33
- "dependencies": {}
35
+ "dependencies": {
36
+ "uglifyjs-webpack-plugin": "^2.2.0",
37
+ "webpack": "^5.37.1"
38
+ }
34
39
  }
package/src/Is.ts CHANGED
@@ -83,4 +83,32 @@ export default class Is{
83
83
 
84
84
  return regex.test( $arg );
85
85
  }
86
+
87
+ static $primitive(arg: any)
88
+ {
89
+ let validations = [
90
+ Is.$undefined,
91
+ Is.$null,
92
+ Is.$boolean,
93
+ Is.$number,
94
+ Is.$string,
95
+ (arg) => Is.is(arg, 'Symbol')
96
+ ]
97
+
98
+ return validations.some(item => item(arg))
99
+ }
100
+
101
+ static $empty(arg: any)
102
+ {
103
+ let validations = [
104
+ Is.$undefined,
105
+ Is.$null,
106
+
107
+ (arg) => Is.$boolean(arg) && !arg,
108
+ (arg) => Is.$number(arg) && arg === 0,
109
+ (arg) => (Is.$array(arg) || Is.$string(arg)) && (arg === "0" || (arg as any[]|string).length === 0)
110
+ ]
111
+
112
+ return validations.some(item => item(arg))
113
+ }
86
114
  }
package/src/main.ts ADDED
@@ -0,0 +1,3 @@
1
+ import Is from './Is';
2
+
3
+ export default Is;
package/test.js CHANGED
@@ -84,6 +84,42 @@ describe('Jis types test', () => {
84
84
 
85
85
  });
86
86
 
87
+ it('$primitive method', function () {
88
+
89
+ assert.equal(jis.$primitive(undefined), true, '$primitive(undefined) must be true')
90
+ assert.equal(jis.$primitive(null), true, '$primitive(null) must be true')
91
+ assert.equal(jis.$primitive("something"), true, '$primitive("something") must be true')
92
+ assert.equal(jis.$primitive(true), true, '$primitive(true) must be true')
93
+ assert.equal(jis.$primitive(false), true, '$primitive(false) must be true')
94
+ assert.equal(jis.$primitive(12), true, '$primitive(12) must be true')
95
+ assert.equal(jis.$primitive(Symbol()), true, '$primitive(Symbol()) must be true')
96
+
97
+ assert.equal(jis.$primitive({}), false, '$primitive({}) must be true')
98
+ assert.equal(jis.$primitive([]), false, '$primitive([]) must be true')
99
+ assert.equal(jis.$primitive(new Date()), false, '$primitive(new Date()) must be true')
100
+
101
+ });
102
+
103
+ it('$empty method', function () {
104
+
105
+ assert.equal(jis.$empty(null), true, '$empty(null) must be true')
106
+ assert.equal(jis.$empty(undefined), true, '$empty(undefined) must be true')
107
+ assert.equal(jis.$empty(false), true, '$empty(false) must be true')
108
+ assert.equal(jis.$empty(0), true, '$empty(0) must be true')
109
+ assert.equal(jis.$empty(0.0), true, '$empty(0.0) must be true')
110
+ assert.equal(jis.$empty(""), true, '$empty("") must be true')
111
+ assert.equal(jis.$empty("0"), true, '$empty("0") must be true')
112
+ assert.equal(jis.$empty([]), true, '$empty([]) must be true')
113
+
114
+ assert.equal(jis.$empty(true), false, '$empty(true) must be true')
115
+ assert.equal(jis.$empty(12), false, '$empty(12) must be true')
116
+ assert.equal(jis.$empty(12.0), false, '$empty(12.0) must be true')
117
+ assert.equal(jis.$empty("something"), false, '$empty("something") must be true')
118
+ assert.equal(jis.$empty("012"), false, '$empty("012") must be true')
119
+ assert.equal(jis.$empty([1, 2, 3]), false, '$empty([1, 2, 3]) must be true')
120
+
121
+ });
122
+
87
123
  it('"is" method', function () {
88
124
  assert.equal(jis.is( [], 'Array' ) , true)
89
125
  assert.equal(jis.is( false, 'Boolean' ) , true)
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "sourceMap": false,
4
+ "module": "commonjs",
5
+ "target": "es5",
6
+ "lib": [ "es2015", "dom" ],
7
+ "outDir": "build"
8
+ },
9
+ "exclude": [
10
+ "node_modules"
11
+ ],
12
+ "include": [
13
+ "src/*.ts"
14
+ ]
15
+ }
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import * as jis from './../'
2
- export default jis;
1
+ import Is from '../src/Is'
2
+ export default Is;
@@ -0,0 +1,45 @@
1
+ const path = require('path')
2
+ const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
3
+
4
+ module.exports = {
5
+ mode: 'production',
6
+ entry: {
7
+ 'jis': './src/main.ts',
8
+ 'jis.min': './src/main.ts'
9
+ },
10
+ output: {
11
+ path: path.resolve(__dirname, 'dist'),
12
+ filename: '[name].js',
13
+ libraryTarget: 'umd',
14
+ library: {
15
+ name: 'jis',
16
+ type: 'global'
17
+ },
18
+ umdNamedDefine: true,
19
+ globalObject: "this",
20
+ libraryExport: "default"
21
+ },
22
+ resolve: {
23
+ extensions: ['.ts', '.tsx', '.js']
24
+ },
25
+ // devtool: 'source-map',
26
+ module: {
27
+ rules: [{
28
+ test: /\.tsx?$/,
29
+ loader: 'ts-loader',
30
+ exclude: /node_modules/
31
+ }]
32
+ },
33
+ optimization: {
34
+ minimizer: [
35
+ new UglifyJsPlugin({
36
+ include: /\.min\.js$/,
37
+ uglifyOptions: {
38
+ output: {
39
+ comments: false
40
+ }
41
+ }
42
+ })
43
+ ]
44
+ }
45
+ }
package/build/Is.js DELETED
@@ -1,74 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- var Is = /** @class */ (function () {
4
- function Is() {
5
- }
6
- Is.callToString = function (arg) {
7
- return Object.prototype.toString.call(arg);
8
- };
9
- Is.$string = function (arg) {
10
- return Is.callToString(arg) === '[object String]';
11
- };
12
- Is.is = function (arg, type) {
13
- if (Is.$function(type)) {
14
- return arg instanceof type;
15
- }
16
- if (Is.$string(type)) {
17
- return Is.callToString(arg) === "[object " + type + "]";
18
- }
19
- return arg === type;
20
- };
21
- Is.$array = function (arg) {
22
- return Is.is(arg, 'Array');
23
- };
24
- Is.$null = function (arg) {
25
- return Is.is(arg, 'Null');
26
- };
27
- Is.$number = function (arg) {
28
- return Is.is(arg, 'Number');
29
- };
30
- Is.$object = function (arg) {
31
- return Is.is(arg, 'Object');
32
- };
33
- Is.$undefined = function (arg) {
34
- return Is.is(arg, 'Undefined');
35
- };
36
- Is.$boolean = function (arg) {
37
- return Is.is(arg, 'Boolean');
38
- };
39
- Is.$function = function (arg) {
40
- return Is.callToString(arg) === '[object Function]';
41
- };
42
- Is.objectIsValid = function (data, rules) {
43
- if (!Is.$object(data))
44
- throw new Error('The data parameter must be an Object');
45
- if (!Is.$object(rules))
46
- throw new Error('The rules parameter must be an Object');
47
- var $response = true;
48
- var $keys = Object.getOwnPropertyNames(rules);
49
- $keys.forEach(function (key) {
50
- var rule = rules[key];
51
- if (Is.$array(rule)) {
52
- if (rule.length < 1)
53
- return;
54
- var parcial_1 = false;
55
- rule.forEach(function (_rule) {
56
- parcial_1 = parcial_1 || Is.is(data[key], _rule);
57
- });
58
- return $response = $response && parcial_1;
59
- }
60
- $response = $response && Is.is(data[key], rule);
61
- });
62
- return $response;
63
- };
64
- Is.$numeric = function (arg) {
65
- if (Is.$number(arg)) {
66
- return true;
67
- }
68
- var $arg = String(arg || '');
69
- var regex = /^[-+]?(([0-9]+)|([0-9]*(\.[0-9]+))|([0-9]+\.))([Ee]([-+]?[0-9]+))?$/g;
70
- return regex.test($arg);
71
- };
72
- return Is;
73
- }());
74
- exports["default"] = Is;
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./build/Is').default;