jis 2.0.3-preview.1 → 2.2.0-preview.1
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/CHANGELOG.md +27 -0
- package/README.md +176 -133
- package/dist/jis.browser.js +195 -0
- package/dist/jis.browser.js.map +1 -0
- package/dist/jis.browser.min.js +2 -0
- package/dist/jis.browser.min.js.map +1 -0
- package/dist/jis.js +92 -56
- package/dist/jis.js.map +1 -0
- package/dist/jis.umd.cjs +2 -1
- package/dist/jis.umd.cjs.map +1 -0
- package/dist/{Is.d.ts → types/Is.d.ts} +2 -5
- package/dist/types/Semantic.d.ts +5 -0
- package/dist/types/interfaces/IApi.d.ts +6 -0
- package/dist/types/interfaces/ILegacyApi.d.ts +28 -0
- package/dist/types/interfaces/main.d.ts +3 -0
- package/dist/types/main.d.ts +4 -0
- package/package.json +17 -5
- package/dist/interfaces/main.d.ts +0 -3
- package/dist/main.d.ts +0 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
### Deprecated
|
|
6
|
+
- Accessing type checks directly via `jis.is` and `jis.$*` is deprecated.
|
|
7
|
+
These APIs will be removed in v3.0.0.
|
|
8
|
+
Use `jis.types.*` and `jis.semantic.*` instead.
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Introduced new namespaces: `jis.types` and `jis.semantic`
|
|
12
|
+
- Browser-ready build for direct usage via `<script>` tag
|
|
13
|
+
(no imports, no modules, no modern syntax)
|
|
14
|
+
|
|
15
|
+
## [2.0.2]
|
|
16
|
+
### Fixed
|
|
17
|
+
- Fixed CI configuration to run `build` and `test` jobs only on merge requests to `dev` and `master`
|
|
18
|
+
- Fixed package publishing issue where the `dist/` folder was not included
|
|
19
|
+
|
|
20
|
+
## [2.0.1]
|
|
21
|
+
### Changed
|
|
22
|
+
- Migrated build system from webpack to Vite
|
|
23
|
+
- Integrated Vitest
|
|
24
|
+
- Integrated CI/CD (build, test, and deploy)
|
|
25
|
+
|
|
26
|
+
### Notes
|
|
27
|
+
- Previous versions (< 2.0.1) were early iterations and did not follow a formal changelog.
|
package/README.md
CHANGED
|
@@ -15,240 +15,283 @@ Static types disappear after transpilation, and runtime type checks are often li
|
|
|
15
15
|
`jis` focuses on providing simple, reliable runtime `is` checks using the most stable and widely supported mechanisms in JavaScript.
|
|
16
16
|
|
|
17
17
|
### Installation
|
|
18
|
-
|
|
19
|
-
```shell script
|
|
20
|
-
npm install jis
|
|
21
|
-
```
|
|
22
18
|
|
|
23
|
-
You can install this library with
|
|
19
|
+
You can install this library with npm or yarn.
|
|
24
20
|
|
|
25
|
-
```shell script
|
|
26
|
-
npm install jis
|
|
21
|
+
```shell script
|
|
22
|
+
npm install jis
|
|
27
23
|
```
|
|
28
24
|
|
|
29
25
|
### Usage
|
|
30
26
|
|
|
31
|
-
|
|
27
|
+
#### Import in ES5 or higher
|
|
32
28
|
|
|
33
29
|
```js
|
|
34
|
-
|
|
30
|
+
const jis = require('jis')
|
|
35
31
|
```
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
#### Import in TS
|
|
38
34
|
|
|
39
35
|
```ts
|
|
40
36
|
import jis from 'jis'
|
|
41
37
|
```
|
|
42
38
|
|
|
43
|
-
|
|
39
|
+
### ⚠️ Backward compatibility
|
|
44
40
|
|
|
45
|
-
|
|
41
|
+
In `v2.x`, legacy access via `jis.is` and `jis.$*` **still works for compatibility reasons**, but it is **deprecated** and will be removed in `v3.0.0`.
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
jis.$array( [] ) // true
|
|
50
|
-
|
|
51
|
-
jis.$array( true ) //false
|
|
52
|
-
jis.$array( function() {} ) // false
|
|
53
|
-
jis.$array( null ) // false
|
|
54
|
-
jis.$array( 12 ) // false
|
|
55
|
-
jis.$array( {} ) // false
|
|
56
|
-
jis.$array( '' ) // false
|
|
57
|
-
jis.$array( undefined ) // false
|
|
43
|
+
If you are starting a new project or updating existing code, **use the new namespaces shown below**.
|
|
58
44
|
|
|
45
|
+
```js
|
|
46
|
+
// Deprecated
|
|
47
|
+
jis.is(arg, type);
|
|
48
|
+
jis.$object(arg);
|
|
49
|
+
jis.$array(arg);
|
|
50
|
+
jis.$number(arg);
|
|
51
|
+
jis.$string(arg);
|
|
52
|
+
jis.$boolean(arg);
|
|
53
|
+
jis.$undefined(arg);
|
|
54
|
+
jis.$function(arg);
|
|
55
|
+
jis.$null(arg);
|
|
56
|
+
|
|
57
|
+
jis.$empty(arg);
|
|
58
|
+
jis.$numeric(arg);
|
|
59
|
+
jis.$primitive(arg);
|
|
59
60
|
```
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
Use the new namespaces instead:
|
|
62
63
|
|
|
63
64
|
```js
|
|
65
|
+
jis.types.is(arg, type);
|
|
66
|
+
jis.types.$object(arg);
|
|
67
|
+
jis.types.$array(arg);
|
|
68
|
+
jis.types.$number(arg);
|
|
69
|
+
jis.types.$string(arg);
|
|
70
|
+
jis.types.$boolean(arg);
|
|
71
|
+
jis.types.$undefined(arg);
|
|
72
|
+
jis.types.$function(arg);
|
|
73
|
+
jis.types.$null(arg);
|
|
74
|
+
|
|
75
|
+
jis.semantic.$empty(arg);
|
|
76
|
+
jis.semantic.$numeric(arg);
|
|
77
|
+
jis.semantic.$primitive(arg);
|
|
78
|
+
```
|
|
64
79
|
|
|
65
|
-
|
|
66
|
-
jis.$boolean( false ) // true
|
|
80
|
+
## API
|
|
67
81
|
|
|
68
|
-
|
|
69
|
-
|
|
82
|
+
### Type checks (`jis.types`)
|
|
83
|
+
#### $array
|
|
70
84
|
|
|
71
|
-
|
|
85
|
+
```js
|
|
86
|
+
const { $array } = jis.types // jis.types.$array
|
|
87
|
+
|
|
88
|
+
$array( [] ) // true
|
|
72
89
|
|
|
90
|
+
$array( true ) // false
|
|
91
|
+
$array( function() {} ) // false
|
|
92
|
+
$array( null ) // false
|
|
93
|
+
$array( 12 ) // false
|
|
94
|
+
$array( {} ) // false
|
|
95
|
+
$array( '' ) // false
|
|
96
|
+
$array( undefined ) // false
|
|
73
97
|
```
|
|
74
98
|
|
|
75
|
-
|
|
99
|
+
#### $boolean
|
|
76
100
|
|
|
77
101
|
```js
|
|
102
|
+
const { $boolean } = jis.types
|
|
78
103
|
|
|
79
|
-
|
|
104
|
+
$boolean( true ) // true
|
|
105
|
+
$boolean( false ) // true
|
|
80
106
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
jis.$function( '' ) // false
|
|
107
|
+
$boolean( [] ) // false
|
|
108
|
+
$boolean( function() {} ) // false
|
|
84
109
|
|
|
85
110
|
// ...
|
|
86
|
-
|
|
87
111
|
```
|
|
88
112
|
|
|
89
|
-
|
|
113
|
+
#### $function
|
|
90
114
|
|
|
91
115
|
```js
|
|
116
|
+
const { $function } = jis.types
|
|
92
117
|
|
|
93
|
-
|
|
118
|
+
$function( function() {} ) // true
|
|
94
119
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
120
|
+
$function( 12 ) // false
|
|
121
|
+
$function( {} ) // false
|
|
122
|
+
$function( '' ) // false
|
|
98
123
|
|
|
99
124
|
// ...
|
|
100
|
-
|
|
101
125
|
```
|
|
102
126
|
|
|
103
|
-
|
|
127
|
+
#### $null
|
|
104
128
|
|
|
105
129
|
```js
|
|
130
|
+
const { $null } = jis.types
|
|
106
131
|
|
|
107
|
-
|
|
132
|
+
$null( null ) // true
|
|
108
133
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
134
|
+
$null( {} ) // false
|
|
135
|
+
$null( '' ) // false
|
|
136
|
+
$null( undefined ) // false
|
|
112
137
|
|
|
113
138
|
// ...
|
|
114
|
-
|
|
115
139
|
```
|
|
116
140
|
|
|
117
|
-
|
|
141
|
+
#### $number
|
|
118
142
|
|
|
119
143
|
```js
|
|
144
|
+
const { $number } = jis.types
|
|
120
145
|
|
|
121
|
-
|
|
146
|
+
$number( 12 ) // true
|
|
122
147
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
148
|
+
$number( function() {} ) // false
|
|
149
|
+
$number( null ) // false
|
|
150
|
+
$number( undefined ) // false
|
|
126
151
|
|
|
127
152
|
// ...
|
|
128
|
-
|
|
129
153
|
```
|
|
130
154
|
|
|
131
|
-
|
|
155
|
+
#### $object
|
|
132
156
|
|
|
133
157
|
```js
|
|
158
|
+
const { $object } = jis.types
|
|
134
159
|
|
|
135
|
-
|
|
160
|
+
$object( {} ) // true
|
|
136
161
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
162
|
+
$object( [] ) // false
|
|
163
|
+
$object( true ) // false
|
|
164
|
+
$object( 12 ) // false
|
|
140
165
|
|
|
141
166
|
// ...
|
|
142
|
-
|
|
143
167
|
```
|
|
144
168
|
|
|
145
|
-
|
|
169
|
+
#### $string
|
|
146
170
|
|
|
147
171
|
```js
|
|
172
|
+
const { $string } = jis.types
|
|
148
173
|
|
|
149
|
-
|
|
174
|
+
$string( 'Some text' ) // true
|
|
150
175
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
176
|
+
$string( [] ) // false
|
|
177
|
+
$string( true ) // false
|
|
178
|
+
$string( undefined ) // false
|
|
154
179
|
|
|
155
180
|
// ...
|
|
156
|
-
|
|
157
181
|
```
|
|
158
182
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
Check if the argument is a number or number string (including exponential)
|
|
183
|
+
#### $undefined
|
|
162
184
|
|
|
163
185
|
```js
|
|
186
|
+
const { $undefined } = jis.types
|
|
164
187
|
|
|
165
|
-
|
|
166
|
-
jis.$numeric( '12' ) // true
|
|
167
|
-
jis.$numeric( '-12' ) // true
|
|
168
|
-
jis.$numeric( '+12' ) // true
|
|
169
|
-
jis.$numeric( '12.' ) // true
|
|
170
|
-
jis.$numeric( '12.e5' ) // true
|
|
171
|
-
jis.$numeric( '12.E5' ) // true
|
|
172
|
-
jis.$numeric( '12.E-5' ) // true
|
|
173
|
-
jis.$numeric( '-12.E-5' ) // true
|
|
174
|
-
jis.$numeric( '+12.E-5' ) // true
|
|
188
|
+
$undefined( undefined ) // true
|
|
175
189
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
jis.$numeric( null ) // false
|
|
190
|
+
$undefined( [] ) // false
|
|
191
|
+
$undefined( {} ) // false
|
|
192
|
+
$undefined( '' ) // false
|
|
180
193
|
|
|
194
|
+
// ...
|
|
181
195
|
```
|
|
182
196
|
|
|
183
|
-
|
|
197
|
+
#### is
|
|
184
198
|
|
|
185
|
-
|
|
199
|
+
This method is the core of the library and provides more flexible and advanced type checks.
|
|
186
200
|
|
|
187
201
|
```js
|
|
202
|
+
const { is } = jis.types
|
|
203
|
+
|
|
204
|
+
is( [], 'Array' ) // true
|
|
205
|
+
is( false, 'Boolean' ) // true
|
|
206
|
+
is( true, 'Boolean' ) // true
|
|
207
|
+
is( function(){}, 'Function' ) // true
|
|
208
|
+
is( null, 'Null' ) // true
|
|
209
|
+
is( 12, 'Number' ) // true
|
|
210
|
+
is( {}, 'Object' ) // true
|
|
211
|
+
is( 'Text', 'String' ) // true
|
|
212
|
+
is( undefined, 'Undefined' ) // true
|
|
213
|
+
|
|
214
|
+
let date = new Date();
|
|
215
|
+
is(date, Date) // true
|
|
188
216
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
jis.$primitive("something") // true
|
|
192
|
-
jis.$primitive(true) // true
|
|
193
|
-
jis.$primitive(false) // true
|
|
194
|
-
jis.$primitive(12) // true
|
|
195
|
-
jis.$primitive(Symbol()) // true
|
|
217
|
+
is(/^$/g, RegExp) // true
|
|
218
|
+
is(/^$/g, 'RegExp') // true
|
|
196
219
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
jis.$primitive(new Date()) // false
|
|
220
|
+
is(12, 12) // true
|
|
221
|
+
is(12, 13) // false
|
|
200
222
|
|
|
223
|
+
// ... experiment with this method :D
|
|
201
224
|
```
|
|
202
225
|
|
|
203
|
-
|
|
226
|
+
### Semantic checks (`jis.semantic`)
|
|
227
|
+
#### $numeric
|
|
204
228
|
|
|
205
|
-
|
|
229
|
+
Check if the argument is a number or number string (including exponential)
|
|
206
230
|
|
|
207
231
|
```js
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
232
|
+
const { $numeric } = jis.semantic // jis.semantic.$numeric
|
|
233
|
+
|
|
234
|
+
$numeric( 12 ) // true
|
|
235
|
+
$numeric( '12' ) // true
|
|
236
|
+
$numeric( '-12' ) // true
|
|
237
|
+
$numeric( '+12' ) // true
|
|
238
|
+
$numeric( '12.' ) // true
|
|
239
|
+
$numeric( '12.e5' ) // true
|
|
240
|
+
$numeric( '12.E5' ) // true
|
|
241
|
+
$numeric( '12.E-5' ) // true
|
|
242
|
+
$numeric( '-12.E-5' ) // true
|
|
243
|
+
$numeric( '+12.E-5' ) // true
|
|
244
|
+
|
|
245
|
+
$numeric( '12.E-' ) // false
|
|
246
|
+
$numeric( 'A3B' ) // false
|
|
247
|
+
$numeric( undefined ) // false
|
|
248
|
+
$numeric( null ) // false
|
|
225
249
|
```
|
|
226
250
|
|
|
227
|
-
|
|
251
|
+
#### $primitive
|
|
228
252
|
|
|
229
|
-
|
|
253
|
+
Check if the argument is a primitive value
|
|
230
254
|
|
|
231
255
|
```js
|
|
256
|
+
const { $primitive } = jis.semantic
|
|
257
|
+
|
|
258
|
+
$primitive(undefined) // true
|
|
259
|
+
$primitive(null) // true
|
|
260
|
+
$primitive("something") // true
|
|
261
|
+
$primitive(true) // true
|
|
262
|
+
$primitive(false) // true
|
|
263
|
+
$primitive(12) // true
|
|
264
|
+
$primitive(Symbol()) // true
|
|
265
|
+
|
|
266
|
+
$primitive({}) // false
|
|
267
|
+
$primitive([]) // false
|
|
268
|
+
$primitive(new Date()) // false
|
|
269
|
+
```
|
|
232
270
|
|
|
233
|
-
|
|
234
|
-
jis.is( false, 'Boolean' ) // true
|
|
235
|
-
jis.is( true, 'Boolean' ) // true
|
|
236
|
-
jis.is( function(){}, 'Function' ) // true
|
|
237
|
-
jis.is( null, 'Null' ) // true
|
|
238
|
-
jis.is( 12, 'Number' ) // true
|
|
239
|
-
jis.is( {}, 'Object' ) // true
|
|
240
|
-
jis.is( 'Text', 'String' ) // true
|
|
241
|
-
jis.is( undefined, 'Undefined' ) // true
|
|
242
|
-
|
|
243
|
-
let date = new Date();
|
|
244
|
-
jis.is(date, Date) // true
|
|
271
|
+
#### $empty
|
|
245
272
|
|
|
246
|
-
|
|
247
|
-
jis.is(/^$/g, 'RegExp') // true
|
|
273
|
+
$empty follows a semantic definition of emptiness, where certain falsy or zero-like values are intentionally considered empty.
|
|
248
274
|
|
|
249
|
-
|
|
250
|
-
|
|
275
|
+
```js
|
|
276
|
+
const { $empty } = jis.semantic
|
|
277
|
+
|
|
278
|
+
$empty(null) // true
|
|
279
|
+
$empty(undefined) // true
|
|
280
|
+
$empty(false) // true
|
|
281
|
+
$empty(0) // true
|
|
282
|
+
$empty(0.0) // true
|
|
283
|
+
$empty("") // true
|
|
284
|
+
$empty("0") // true
|
|
285
|
+
$empty([]) // true
|
|
286
|
+
|
|
287
|
+
$empty(true) // false
|
|
288
|
+
$empty(12) // false
|
|
289
|
+
$empty(12.0) // false
|
|
290
|
+
$empty("something") // false
|
|
291
|
+
$empty("012") // false
|
|
292
|
+
$empty([1, 2, 3]) // false
|
|
293
|
+
```
|
|
251
294
|
|
|
252
|
-
|
|
295
|
+
## Changelog
|
|
253
296
|
|
|
254
|
-
|
|
297
|
+
See [CHANGELOG.md](./CHANGELOG.md) for version history and breaking changes.
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.jis = factory());
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
|
+
|
|
7
|
+
function _classCallCheck(a, n) {
|
|
8
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
9
|
+
}
|
|
10
|
+
function _defineProperties(e, r) {
|
|
11
|
+
for (var t = 0; t < r.length; t++) {
|
|
12
|
+
var o = r[t];
|
|
13
|
+
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _createClass(e, r, t) {
|
|
17
|
+
return t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
18
|
+
writable: false
|
|
19
|
+
}), e;
|
|
20
|
+
}
|
|
21
|
+
function _toPrimitive(t, r) {
|
|
22
|
+
if ("object" != typeof t || !t) return t;
|
|
23
|
+
var e = t[Symbol.toPrimitive];
|
|
24
|
+
if (void 0 !== e) {
|
|
25
|
+
var i = e.call(t, r);
|
|
26
|
+
if ("object" != typeof i) return i;
|
|
27
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
28
|
+
}
|
|
29
|
+
return (String )(t);
|
|
30
|
+
}
|
|
31
|
+
function _toPropertyKey(t) {
|
|
32
|
+
var i = _toPrimitive(t, "string");
|
|
33
|
+
return "symbol" == typeof i ? i : i + "";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var Is = /*#__PURE__*/function () {
|
|
37
|
+
function Is() {
|
|
38
|
+
_classCallCheck(this, Is);
|
|
39
|
+
}
|
|
40
|
+
return _createClass(Is, null, [{
|
|
41
|
+
key: "callToString",
|
|
42
|
+
value: function callToString(arg) {
|
|
43
|
+
return Object.prototype.toString.call(arg);
|
|
44
|
+
}
|
|
45
|
+
}, {
|
|
46
|
+
key: "$string",
|
|
47
|
+
value: function $string(arg) {
|
|
48
|
+
return Is.callToString(arg) === '[object String]';
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "is",
|
|
52
|
+
value: function is(arg, type) {
|
|
53
|
+
if (Is.$function(type)) {
|
|
54
|
+
return arg instanceof type;
|
|
55
|
+
}
|
|
56
|
+
if (Is.$string(type)) {
|
|
57
|
+
return Is.callToString(arg) === "[object ".concat(type, "]");
|
|
58
|
+
}
|
|
59
|
+
return arg === type;
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "$array",
|
|
63
|
+
value: function $array(arg) {
|
|
64
|
+
return Is.is(arg, 'Array');
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
67
|
+
key: "$null",
|
|
68
|
+
value: function $null(arg) {
|
|
69
|
+
return Is.is(arg, 'Null');
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
72
|
+
key: "$number",
|
|
73
|
+
value: function $number(arg) {
|
|
74
|
+
return Is.is(arg, 'Number');
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
key: "$object",
|
|
78
|
+
value: function $object(arg) {
|
|
79
|
+
return Is.is(arg, 'Object');
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
key: "$undefined",
|
|
83
|
+
value: function $undefined(arg) {
|
|
84
|
+
return Is.is(arg, 'Undefined');
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: "$boolean",
|
|
88
|
+
value: function $boolean(arg) {
|
|
89
|
+
return Is.is(arg, 'Boolean');
|
|
90
|
+
}
|
|
91
|
+
}, {
|
|
92
|
+
key: "$function",
|
|
93
|
+
value: function $function(arg) {
|
|
94
|
+
return Is.callToString(arg) === '[object Function]';
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
key: "objectIsValid",
|
|
98
|
+
value: function objectIsValid(data, rules) {
|
|
99
|
+
if (!Is.$object(data)) throw new Error('The data parameter must be an Object');
|
|
100
|
+
if (!Is.$object(rules)) throw new Error('The rules parameter must be an Object');
|
|
101
|
+
var $response = true;
|
|
102
|
+
var $keys = Object.getOwnPropertyNames(rules);
|
|
103
|
+
$keys.forEach(function (key) {
|
|
104
|
+
var rule = rules[key];
|
|
105
|
+
if (Is.$array(rule)) {
|
|
106
|
+
if (rule.length < 1) return;
|
|
107
|
+
var parcial = false;
|
|
108
|
+
rule.forEach(function (_rule) {
|
|
109
|
+
parcial = parcial || Is.is(data[key], _rule);
|
|
110
|
+
});
|
|
111
|
+
return $response = $response && parcial;
|
|
112
|
+
}
|
|
113
|
+
$response = $response && Is.is(data[key], rule);
|
|
114
|
+
});
|
|
115
|
+
return $response;
|
|
116
|
+
}
|
|
117
|
+
}]);
|
|
118
|
+
}();
|
|
119
|
+
|
|
120
|
+
var Semantic = /*#__PURE__*/function () {
|
|
121
|
+
function Semantic() {
|
|
122
|
+
_classCallCheck(this, Semantic);
|
|
123
|
+
}
|
|
124
|
+
return _createClass(Semantic, null, [{
|
|
125
|
+
key: "$numeric",
|
|
126
|
+
value: function $numeric(arg) {
|
|
127
|
+
var validations = [Is.$number, function (arg) {
|
|
128
|
+
var $arg = String(arg || '');
|
|
129
|
+
var regex = /^[-+]?(([0-9]+)|([0-9]*(\.[0-9]+))|([0-9]+\.))([Ee]([-+]?[0-9]+))?$/g;
|
|
130
|
+
return regex.test($arg);
|
|
131
|
+
}];
|
|
132
|
+
return validations.some(function (validation) {
|
|
133
|
+
return validation(arg);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}, {
|
|
137
|
+
key: "$primitive",
|
|
138
|
+
value: function $primitive(arg) {
|
|
139
|
+
var validations = [Is.$undefined, Is.$null, Is.$boolean, Is.$number, Is.$string, function (arg) {
|
|
140
|
+
return Is.is(arg, 'Symbol');
|
|
141
|
+
}];
|
|
142
|
+
return validations.some(function (validation) {
|
|
143
|
+
return validation(arg);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}, {
|
|
147
|
+
key: "$empty",
|
|
148
|
+
value: function $empty(arg) {
|
|
149
|
+
var validations = [Is.$undefined, Is.$null, function (arg) {
|
|
150
|
+
return Is.$boolean(arg) && !arg;
|
|
151
|
+
}, function (arg) {
|
|
152
|
+
return Is.$number(arg) && arg === 0;
|
|
153
|
+
}, function (arg) {
|
|
154
|
+
return (Is.$array(arg) || Is.$string(arg)) && (arg === "0" || arg.length === 0);
|
|
155
|
+
}];
|
|
156
|
+
return validations.some(function (validation) {
|
|
157
|
+
return validation(arg);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}]);
|
|
161
|
+
}();
|
|
162
|
+
|
|
163
|
+
var is = Is.is,
|
|
164
|
+
$array = Is.$array,
|
|
165
|
+
$object = Is.$object,
|
|
166
|
+
$number = Is.$number,
|
|
167
|
+
$string = Is.$string,
|
|
168
|
+
$boolean = Is.$boolean,
|
|
169
|
+
$undefined = Is.$undefined,
|
|
170
|
+
$function = Is.$function,
|
|
171
|
+
$null = Is.$null;
|
|
172
|
+
var $primitive = Semantic.$primitive,
|
|
173
|
+
$empty = Semantic.$empty,
|
|
174
|
+
$numeric = Semantic.$numeric;
|
|
175
|
+
var api = {
|
|
176
|
+
types: Is,
|
|
177
|
+
semantic: Semantic,
|
|
178
|
+
is: is,
|
|
179
|
+
$object: $object,
|
|
180
|
+
$array: $array,
|
|
181
|
+
$number: $number,
|
|
182
|
+
$string: $string,
|
|
183
|
+
$boolean: $boolean,
|
|
184
|
+
$undefined: $undefined,
|
|
185
|
+
$function: $function,
|
|
186
|
+
$null: $null,
|
|
187
|
+
$empty: $empty,
|
|
188
|
+
$numeric: $numeric,
|
|
189
|
+
$primitive: $primitive
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
return api;
|
|
193
|
+
|
|
194
|
+
}));
|
|
195
|
+
//# sourceMappingURL=jis.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jis.browser.js","sources":["../src/Is.ts","../src/Semantic.ts","../src/main.ts"],"sourcesContent":["import type {IGen} from \"./interfaces/main\";\n\nexport default class Is{\n\n private static callToString(arg:any) {\n return Object.prototype.toString.call(arg)\n }\n\n static $string(arg:any) {\n return Is.callToString(arg) === '[object String]';\n }\n\n static is(arg: any, type : any){\n if(Is.$function(type))\n {\n return arg instanceof type;\n }\n\n if (Is.$string(type))\n {\n return Is.callToString(arg) === `[object ${type}]`;\n }\n\n return arg === type;\n }\n\n static $array(arg: any){\n return Is.is(arg, 'Array');\n }\n\n static $null(arg: any){\n return Is.is(arg, 'Null');\n }\n\n static $number(arg: any){\n return Is.is(arg, 'Number');\n }\n\n static $object(arg: any){\n return Is.is(arg, 'Object');\n }\n\n static $undefined(arg: any){\n return Is.is(arg, 'Undefined');\n }\n\n static $boolean(arg: any){\n return Is.is(arg, 'Boolean');\n }\n\n static $function(arg: any){\n return Is.callToString(arg) === '[object Function]';\n }\n\n static objectIsValid(data: IGen, rules: IGen) {\n if (!Is.$object(data)) throw new Error('The data parameter must be an Object');\n if (!Is.$object(rules)) throw new Error('The rules parameter must be an Object');\n\n let $response = true;\n let $keys = Object.getOwnPropertyNames(rules);\n\n $keys.forEach((key: string) => {\n let rule = rules[key];\n if (Is.$array(rule)) {\n if (rule.length < 1) return;\n let parcial = false;\n rule.forEach((_rule: any) => {\n parcial = parcial || Is.is(data[key], _rule);\n });\n return $response = $response && parcial;\n }\n $response = $response && Is.is(data[key], rule);\n });\n return $response;\n }\n\n}","import Is from \"./Is\";\n\nexport default class Semantic {\n\n static $numeric(arg: any)\n {\n const validations = [\n Is.$number,\n (arg: any) => {\n let $arg = String(arg || '');\n let regex = /^[-+]?(([0-9]+)|([0-9]*(\\.[0-9]+))|([0-9]+\\.))([Ee]([-+]?[0-9]+))?$/g;\n\n return regex.test( $arg );\n }\n ];\n\n return validations.some(validation => validation(arg));\n }\n\n static $primitive(arg: any)\n {\n let validations = [\n Is.$undefined,\n Is.$null,\n Is.$boolean,\n Is.$number,\n Is.$string,\n (arg: any) => Is.is(arg, 'Symbol')\n ]\n\n return validations.some(validation => validation(arg))\n }\n\n static $empty(arg: any)\n {\n let validations = [\n Is.$undefined,\n Is.$null,\n\n (arg: any) => Is.$boolean(arg) && !arg,\n (arg: any) => Is.$number(arg) && arg === 0,\n (arg: any) => (Is.$array(arg) || Is.$string(arg)) && (arg === \"0\" || (arg as any[]|string).length === 0)\n ]\n\n return validations.some(validation => validation(arg))\n }\n\n}","\nimport Is from \"./Is\";\nimport type ILegacyApi from \"./interfaces/ILegacyApi\";\nimport Semantic from \"./Semantic\";\nimport type IApi from \"./interfaces/IApi\";\n\nconst {\n is,\n $array,\n $object,\n $number,\n $string,\n $boolean,\n $undefined,\n $function,\n $null\n} = Is;\n\nconst {\n $primitive,\n $empty,\n $numeric\n} = Semantic\n\nconst api : ILegacyApi & IApi = {\n types: Is,\n semantic: Semantic,\n is,\n $object,\n $array,\n $number,\n $string,\n $boolean,\n $undefined,\n $function,\n $null,\n $empty,\n $numeric,\n $primitive\n};\n\nexport default api;"],"names":["Is","_classCallCheck","_createClass","key","value","callToString","arg","Object","prototype","toString","call","$string","is","type","$function","concat","$array","$null","$number","$object","$undefined","$boolean","objectIsValid","data","rules","Error","$response","$keys","getOwnPropertyNames","forEach","rule","length","parcial","_rule","Semantic","$numeric","validations","$arg","String","regex","test","some","validation","$primitive","$empty","api","types","semantic"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAEqBA,EAAE,gBAAA,YAAA;EAAA,EAAA,SAAAA,EAAAA,GAAA;EAAAC,IAAAA,eAAA,OAAAD,EAAA,CAAA;EAAA,EAAA;IAAA,OAAAE,YAAA,CAAAF,EAAA,EAAA,IAAA,EAAA,CAAA;MAAAG,GAAA,EAAA,cAAA;EAAAC,IAAAA,KAAA,EAEX,SAAOC,YAAYA,CAACC,GAAO,EAAA;QAC/B,OAAOC,MAAM,CAACC,SAAS,CAACC,QAAQ,CAACC,IAAI,CAACJ,GAAG,CAAC;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e():"function"==typeof define&&define.amd?define(e):(n="undefined"!=typeof globalThis?globalThis:n||self).jis=e()}(this,function(){"use strict";function n(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}function e(n,e,r){return r&&function(n,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,t(i.key),i)}}(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n}function t(n){var e=function(n,e){if("object"!=typeof n||!n)return n;var t=n[Symbol.toPrimitive];if(void 0!==t){var r=t.call(n,e);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(n)}(n,"string");return"symbol"==typeof e?e:e+""}var r=function(){function t(){n(this,t)}return e(t,0,[{key:"callToString",value:function(n){return Object.prototype.toString.call(n)}},{key:"$string",value:function(n){return"[object String]"===t.callToString(n)}},{key:"is",value:function(n,e){return t.$function(e)?n instanceof e:t.$string(e)?t.callToString(n)==="[object ".concat(e,"]"):n===e}},{key:"$array",value:function(n){return t.is(n,"Array")}},{key:"$null",value:function(n){return t.is(n,"Null")}},{key:"$number",value:function(n){return t.is(n,"Number")}},{key:"$object",value:function(n){return t.is(n,"Object")}},{key:"$undefined",value:function(n){return t.is(n,"Undefined")}},{key:"$boolean",value:function(n){return t.is(n,"Boolean")}},{key:"$function",value:function(n){return"[object Function]"===t.callToString(n)}},{key:"objectIsValid",value:function(n,e){if(!t.$object(n))throw new Error("The data parameter must be an Object");if(!t.$object(e))throw new Error("The rules parameter must be an Object");var r=!0;return Object.getOwnPropertyNames(e).forEach(function(i){var u=e[i];if(t.$array(u)){if(u.length<1)return;var o=!1;return u.forEach(function(e){o=o||t.is(n[i],e)}),r=r&&o}r=r&&t.is(n[i],u)}),r}}])}(),i=function(){return e(function e(){n(this,e)},0,[{key:"$numeric",value:function(n){var e=[r.$number,function(n){var e=String(n||"");return/^[-+]?(([0-9]+)|([0-9]*(\.[0-9]+))|([0-9]+\.))([Ee]([-+]?[0-9]+))?$/g.test(e)}];return e.some(function(e){return e(n)})}},{key:"$primitive",value:function(n){var e=[r.$undefined,r.$null,r.$boolean,r.$number,r.$string,function(n){return r.is(n,"Symbol")}];return e.some(function(e){return e(n)})}},{key:"$empty",value:function(n){var e=[r.$undefined,r.$null,function(n){return r.$boolean(n)&&!n},function(n){return r.$number(n)&&0===n},function(n){return(r.$array(n)||r.$string(n))&&("0"===n||0===n.length)}];return e.some(function(e){return e(n)})}}])}(),u=r.is,o=r.$array,a=r.$object,c=r.$number,f=r.$string,l=r.$boolean,$=r.$undefined,s=r.$function,b=r.$null,y=i.$primitive,m=i.$empty,v=i.$numeric;return{types:r,semantic:i,is:u,$object:a,$array:o,$number:c,$string:f,$boolean:l,$undefined:$,$function:s,$null:b,$empty:m,$numeric:v,$primitive:y}});
|
|
2
|
+
//# sourceMappingURL=jis.browser.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jis.browser.min.js","sources":["../src/Is.ts","../src/Semantic.ts","../src/main.ts"],"sourcesContent":["import type {IGen} from \"./interfaces/main\";\n\nexport default class Is{\n\n private static callToString(arg:any) {\n return Object.prototype.toString.call(arg)\n }\n\n static $string(arg:any) {\n return Is.callToString(arg) === '[object String]';\n }\n\n static is(arg: any, type : any){\n if(Is.$function(type))\n {\n return arg instanceof type;\n }\n\n if (Is.$string(type))\n {\n return Is.callToString(arg) === `[object ${type}]`;\n }\n\n return arg === type;\n }\n\n static $array(arg: any){\n return Is.is(arg, 'Array');\n }\n\n static $null(arg: any){\n return Is.is(arg, 'Null');\n }\n\n static $number(arg: any){\n return Is.is(arg, 'Number');\n }\n\n static $object(arg: any){\n return Is.is(arg, 'Object');\n }\n\n static $undefined(arg: any){\n return Is.is(arg, 'Undefined');\n }\n\n static $boolean(arg: any){\n return Is.is(arg, 'Boolean');\n }\n\n static $function(arg: any){\n return Is.callToString(arg) === '[object Function]';\n }\n\n static objectIsValid(data: IGen, rules: IGen) {\n if (!Is.$object(data)) throw new Error('The data parameter must be an Object');\n if (!Is.$object(rules)) throw new Error('The rules parameter must be an Object');\n\n let $response = true;\n let $keys = Object.getOwnPropertyNames(rules);\n\n $keys.forEach((key: string) => {\n let rule = rules[key];\n if (Is.$array(rule)) {\n if (rule.length < 1) return;\n let parcial = false;\n rule.forEach((_rule: any) => {\n parcial = parcial || Is.is(data[key], _rule);\n });\n return $response = $response && parcial;\n }\n $response = $response && Is.is(data[key], rule);\n });\n return $response;\n }\n\n}","import Is from \"./Is\";\n\nexport default class Semantic {\n\n static $numeric(arg: any)\n {\n const validations = [\n Is.$number,\n (arg: any) => {\n let $arg = String(arg || '');\n let regex = /^[-+]?(([0-9]+)|([0-9]*(\\.[0-9]+))|([0-9]+\\.))([Ee]([-+]?[0-9]+))?$/g;\n\n return regex.test( $arg );\n }\n ];\n\n return validations.some(validation => validation(arg));\n }\n\n static $primitive(arg: any)\n {\n let validations = [\n Is.$undefined,\n Is.$null,\n Is.$boolean,\n Is.$number,\n Is.$string,\n (arg: any) => Is.is(arg, 'Symbol')\n ]\n\n return validations.some(validation => validation(arg))\n }\n\n static $empty(arg: any)\n {\n let validations = [\n Is.$undefined,\n Is.$null,\n\n (arg: any) => Is.$boolean(arg) && !arg,\n (arg: any) => Is.$number(arg) && arg === 0,\n (arg: any) => (Is.$array(arg) || Is.$string(arg)) && (arg === \"0\" || (arg as any[]|string).length === 0)\n ]\n\n return validations.some(validation => validation(arg))\n }\n\n}","\nimport Is from \"./Is\";\nimport type ILegacyApi from \"./interfaces/ILegacyApi\";\nimport Semantic from \"./Semantic\";\nimport type IApi from \"./interfaces/IApi\";\n\nconst {\n is,\n $array,\n $object,\n $number,\n $string,\n $boolean,\n $undefined,\n $function,\n $null\n} = Is;\n\nconst {\n $primitive,\n $empty,\n $numeric\n} = Semantic\n\nconst api : ILegacyApi & IApi = {\n types: Is,\n semantic: Semantic,\n is,\n $object,\n $array,\n $number,\n $string,\n $boolean,\n $undefined,\n $function,\n $null,\n $empty,\n $numeric,\n $primitive\n};\n\nexport default api;"],"names":["Is","_classCallCheck","_createClass","key","value","arg","Object","prototype","toString","call","callToString","type","$function","$string","concat","is","data","rules","$object","Error","$response","getOwnPropertyNames","forEach","rule","$array","length","parcial","_rule","Semantic","validations","$number","$arg","String","test","some","validation","$undefined","$null","$boolean","$primitive","$empty","$numeric","types","semantic"],"mappings":"s2BAEqBA,EAAE,WAAA,SAAAA,IAAAC,OAAAD,EAAA,CAAA,OAAAE,EAAAF,EAAA,EAAA,CAAA,CAAAG,IAAA,eAAAC,MAEX,SAAoBC,GACxB,OAAOC,OAAOC,UAAUC,SAASC,KAAKJ,EAC1C,GAAC,CAAAF,IAAA,UAAAC,MAED,SAAeC,GACX,MAAgC,oBAAzBL,EAAGU,aAAaL,EAC3B,GAAC,CAAAF,IAAA,KAAAC,MAED,SAAUC,EAAUM,GAChB,OAAGX,EAAGY,UAAUD,GAELN,aAAeM,EAGtBX,EAAGa,QAAQF,GAEHX,EAAGU,aAAaL,KAAI,WAAAS,OAAgBH,EAAI,KAG7CN,IAAQM,CACnB,GAAC,CAAAR,IAAA,SAAAC,MAED,SAAcC,GACV,OAAOL,EAAGe,GAAGV,EAAK,QACtB,GAAC,CAAAF,IAAA,QAAAC,MAED,SAAaC,GACT,OAAOL,EAAGe,GAAGV,EAAK,OACtB,GAAC,CAAAF,IAAA,UAAAC,MAED,SAAeC,GACX,OAAOL,EAAGe,GAAGV,EAAK,SACtB,GAAC,CAAAF,IAAA,UAAAC,MAED,SAAeC,GACX,OAAOL,EAAGe,GAAGV,EAAK,SACtB,GAAC,CAAAF,IAAA,aAAAC,MAED,SAAkBC,GACd,OAAOL,EAAGe,GAAGV,EAAK,YACtB,GAAC,CAAAF,IAAA,WAAAC,MAED,SAAgBC,GACZ,OAAOL,EAAGe,GAAGV,EAAK,UACtB,GAAC,CAAAF,IAAA,YAAAC,MAED,SAAiBC,GACb,MAAgC,sBAAzBL,EAAGU,aAAaL,EAC3B,GAAC,CAAAF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GsC,SAASjC,KAASA,CAAG,EACtC,SAACA,GAAQ,OAAKL,EAAG8B,QAAQzB,IAAgB,IAARA,CAAS,EAC1C,SAACA,GAAQ,OAAML,EAAGwB,OAAOnB,IAAQL,EAAGa,QAAQR,MAAkB,MAARA,GAAgD,IAAhCA,EAAqBoB,OAAa,GAG5G,OAAOI,EAAYK,KAAK,SAAAC,GAAU,OAAIA,EAAW9B,EAAI,EACzD,IAAC,CA3CwB,GCKzBU,EASAf,EATAe,GACAS,EAQAxB,EARAwB,OACAN,EAOAlB,EAPAkB,QACAY,EAMA9B,EANA8B,QACAjB,EAKAb,EALAa,QACAyB,EAIAtC,EAJAsC,SACAF,EAGApC,EAHAoC,WACAxB,EAEAZ,EAFAY,UACAyB,EACArC,EADAqC,MAIAE,EAGAX,EAHAW,WACAC,EAEAZ,EAFAY,OACAC,EACAb,EADAa,eAG4B,CAC5BC,MAAO1C,EACP2C,SAAUf,EACVb,GAAAA,EACAG,QAAAA,EACAM,OAAAA,EACAM,QAAAA,EACAjB,QAAAA,EACAyB,SAAAA,EACAF,WAAAA,EACAxB,UAAAA,EACAyB,MAAAA,EACAG,OAAAA,EACAC,SAAAA,EACAF,WAAAA"}
|
package/dist/jis.js
CHANGED
|
@@ -1,76 +1,112 @@
|
|
|
1
|
-
class
|
|
2
|
-
static callToString(
|
|
3
|
-
return Object.prototype.toString.call(
|
|
1
|
+
class t {
|
|
2
|
+
static callToString(e) {
|
|
3
|
+
return Object.prototype.toString.call(e);
|
|
4
4
|
}
|
|
5
|
-
static $string(
|
|
6
|
-
return
|
|
5
|
+
static $string(e) {
|
|
6
|
+
return t.callToString(e) === "[object String]";
|
|
7
7
|
}
|
|
8
|
-
static is(
|
|
9
|
-
return
|
|
8
|
+
static is(e, r) {
|
|
9
|
+
return t.$function(r) ? e instanceof r : t.$string(r) ? t.callToString(e) === `[object ${r}]` : e === r;
|
|
10
10
|
}
|
|
11
|
-
static $array(
|
|
12
|
-
return
|
|
11
|
+
static $array(e) {
|
|
12
|
+
return t.is(e, "Array");
|
|
13
13
|
}
|
|
14
|
-
static $null(
|
|
15
|
-
return
|
|
14
|
+
static $null(e) {
|
|
15
|
+
return t.is(e, "Null");
|
|
16
16
|
}
|
|
17
|
-
static $number(
|
|
18
|
-
return
|
|
17
|
+
static $number(e) {
|
|
18
|
+
return t.is(e, "Number");
|
|
19
19
|
}
|
|
20
|
-
static $object(
|
|
21
|
-
return
|
|
20
|
+
static $object(e) {
|
|
21
|
+
return t.is(e, "Object");
|
|
22
22
|
}
|
|
23
|
-
static $undefined(
|
|
24
|
-
return
|
|
23
|
+
static $undefined(e) {
|
|
24
|
+
return t.is(e, "Undefined");
|
|
25
25
|
}
|
|
26
|
-
static $boolean(
|
|
27
|
-
return
|
|
26
|
+
static $boolean(e) {
|
|
27
|
+
return t.is(e, "Boolean");
|
|
28
28
|
}
|
|
29
|
-
static $function(
|
|
30
|
-
return
|
|
29
|
+
static $function(e) {
|
|
30
|
+
return t.callToString(e) === "[object Function]";
|
|
31
31
|
}
|
|
32
|
-
static objectIsValid(
|
|
33
|
-
if (!
|
|
34
|
-
if (!
|
|
35
|
-
let
|
|
36
|
-
return Object.getOwnPropertyNames(
|
|
37
|
-
let
|
|
38
|
-
if (
|
|
39
|
-
if (
|
|
40
|
-
let
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
}),
|
|
32
|
+
static objectIsValid(e, r) {
|
|
33
|
+
if (!t.$object(e)) throw new Error("The data parameter must be an Object");
|
|
34
|
+
if (!t.$object(r)) throw new Error("The rules parameter must be an Object");
|
|
35
|
+
let n = !0;
|
|
36
|
+
return Object.getOwnPropertyNames(r).forEach((i) => {
|
|
37
|
+
let a = r[i];
|
|
38
|
+
if (t.$array(a)) {
|
|
39
|
+
if (a.length < 1) return;
|
|
40
|
+
let o = !1;
|
|
41
|
+
return a.forEach((s) => {
|
|
42
|
+
o = o || t.is(e[i], s);
|
|
43
|
+
}), n = n && o;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
}),
|
|
45
|
+
n = n && t.is(e[i], a);
|
|
46
|
+
}), n;
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
}
|
|
49
|
+
class l {
|
|
50
|
+
static $numeric(e) {
|
|
51
|
+
return [
|
|
52
|
+
t.$number,
|
|
53
|
+
(n) => {
|
|
54
|
+
let c = String(n || "");
|
|
55
|
+
return /^[-+]?(([0-9]+)|([0-9]*(\.[0-9]+))|([0-9]+\.))([Ee]([-+]?[0-9]+))?$/g.test(c);
|
|
56
|
+
}
|
|
57
|
+
].some((n) => n(e));
|
|
53
58
|
}
|
|
54
|
-
static $primitive(
|
|
59
|
+
static $primitive(e) {
|
|
55
60
|
return [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
(
|
|
62
|
-
].some((
|
|
61
|
+
t.$undefined,
|
|
62
|
+
t.$null,
|
|
63
|
+
t.$boolean,
|
|
64
|
+
t.$number,
|
|
65
|
+
t.$string,
|
|
66
|
+
(n) => t.is(n, "Symbol")
|
|
67
|
+
].some((n) => n(e));
|
|
63
68
|
}
|
|
64
|
-
static $empty(
|
|
69
|
+
static $empty(e) {
|
|
65
70
|
return [
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
(
|
|
69
|
-
(
|
|
70
|
-
(
|
|
71
|
-
].some((
|
|
71
|
+
t.$undefined,
|
|
72
|
+
t.$null,
|
|
73
|
+
(n) => t.$boolean(n) && !n,
|
|
74
|
+
(n) => t.$number(n) && n === 0,
|
|
75
|
+
(n) => (t.$array(n) || t.$string(n)) && (n === "0" || n.length === 0)
|
|
76
|
+
].some((n) => n(e));
|
|
72
77
|
}
|
|
73
78
|
}
|
|
79
|
+
const {
|
|
80
|
+
is: $,
|
|
81
|
+
$array: u,
|
|
82
|
+
$object: b,
|
|
83
|
+
$number: m,
|
|
84
|
+
$string: f,
|
|
85
|
+
$boolean: d,
|
|
86
|
+
$undefined: j,
|
|
87
|
+
$function: g,
|
|
88
|
+
$null: p
|
|
89
|
+
} = t, {
|
|
90
|
+
$primitive: S,
|
|
91
|
+
$empty: h,
|
|
92
|
+
$numeric: v
|
|
93
|
+
} = l, O = {
|
|
94
|
+
types: t,
|
|
95
|
+
semantic: l,
|
|
96
|
+
is: $,
|
|
97
|
+
$object: b,
|
|
98
|
+
$array: u,
|
|
99
|
+
$number: m,
|
|
100
|
+
$string: f,
|
|
101
|
+
$boolean: d,
|
|
102
|
+
$undefined: j,
|
|
103
|
+
$function: g,
|
|
104
|
+
$null: p,
|
|
105
|
+
$empty: h,
|
|
106
|
+
$numeric: v,
|
|
107
|
+
$primitive: S
|
|
108
|
+
};
|
|
74
109
|
export {
|
|
75
|
-
|
|
110
|
+
O as default
|
|
76
111
|
};
|
|
112
|
+
//# sourceMappingURL=jis.js.map
|
package/dist/jis.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jis.js","sources":["../src/Is.ts","../src/Semantic.ts","../src/main.ts"],"sourcesContent":["import type {IGen} from \"./interfaces/main\";\n\nexport default class Is{\n\n private static callToString(arg:any) {\n return Object.prototype.toString.call(arg)\n }\n\n static $string(arg:any) {\n return Is.callToString(arg) === '[object String]';\n }\n\n static is(arg: any, type : any){\n if(Is.$function(type))\n {\n return arg instanceof type;\n }\n\n if (Is.$string(type))\n {\n return Is.callToString(arg) === `[object ${type}]`;\n }\n\n return arg === type;\n }\n\n static $array(arg: any){\n return Is.is(arg, 'Array');\n }\n\n static $null(arg: any){\n return Is.is(arg, 'Null');\n }\n\n static $number(arg: any){\n return Is.is(arg, 'Number');\n }\n\n static $object(arg: any){\n return Is.is(arg, 'Object');\n }\n\n static $undefined(arg: any){\n return Is.is(arg, 'Undefined');\n }\n\n static $boolean(arg: any){\n return Is.is(arg, 'Boolean');\n }\n\n static $function(arg: any){\n return Is.callToString(arg) === '[object Function]';\n }\n\n static objectIsValid(data: IGen, rules: IGen) {\n if (!Is.$object(data)) throw new Error('The data parameter must be an Object');\n if (!Is.$object(rules)) throw new Error('The rules parameter must be an Object');\n\n let $response = true;\n let $keys = Object.getOwnPropertyNames(rules);\n\n $keys.forEach((key: string) => {\n let rule = rules[key];\n if (Is.$array(rule)) {\n if (rule.length < 1) return;\n let parcial = false;\n rule.forEach((_rule: any) => {\n parcial = parcial || Is.is(data[key], _rule);\n });\n return $response = $response && parcial;\n }\n $response = $response && Is.is(data[key], rule);\n });\n return $response;\n }\n\n}","import Is from \"./Is\";\n\nexport default class Semantic {\n\n static $numeric(arg: any)\n {\n const validations = [\n Is.$number,\n (arg: any) => {\n let $arg = String(arg || '');\n let regex = /^[-+]?(([0-9]+)|([0-9]*(\\.[0-9]+))|([0-9]+\\.))([Ee]([-+]?[0-9]+))?$/g;\n\n return regex.test( $arg );\n }\n ];\n\n return validations.some(validation => validation(arg));\n }\n\n static $primitive(arg: any)\n {\n let validations = [\n Is.$undefined,\n Is.$null,\n Is.$boolean,\n Is.$number,\n Is.$string,\n (arg: any) => Is.is(arg, 'Symbol')\n ]\n\n return validations.some(validation => validation(arg))\n }\n\n static $empty(arg: any)\n {\n let validations = [\n Is.$undefined,\n Is.$null,\n\n (arg: any) => Is.$boolean(arg) && !arg,\n (arg: any) => Is.$number(arg) && arg === 0,\n (arg: any) => (Is.$array(arg) || Is.$string(arg)) && (arg === \"0\" || (arg as any[]|string).length === 0)\n ]\n\n return validations.some(validation => validation(arg))\n }\n\n}","\nimport Is from \"./Is\";\nimport type ILegacyApi from \"./interfaces/ILegacyApi\";\nimport Semantic from \"./Semantic\";\nimport type IApi from \"./interfaces/IApi\";\n\nconst {\n is,\n $array,\n $object,\n $number,\n $string,\n $boolean,\n $undefined,\n $function,\n $null\n} = Is;\n\nconst {\n $primitive,\n $empty,\n $numeric\n} = Semantic\n\nconst api : ILegacyApi & IApi = {\n types: Is,\n semantic: Semantic,\n is,\n $object,\n $array,\n $number,\n $string,\n $boolean,\n $undefined,\n $function,\n $null,\n $empty,\n $numeric,\n $primitive\n};\n\nexport default api;"],"names":["Is","arg","type","data","rules","$response","key","rule","parcial","_rule","Semantic","$arg","validation","is","$array","$object","$number","$string","$boolean","$undefined","$function","$null","$primitive","$empty","$numeric","api"],"mappings":"AAEA,MAAqBA,EAAE;AAAA,EAEnB,OAAe,aAAaC,GAAS;AACjC,WAAO,OAAO,UAAU,SAAS,KAAKA,CAAG;AAAA,EAC7C;AAAA,EAEA,OAAO,QAAQA,GAAS;AACpB,WAAOD,EAAG,aAAaC,CAAG,MAAM;AAAA,EACpC;AAAA,EAEA,OAAO,GAAGA,GAAUC,GAAW;AAC3B,WAAGF,EAAG,UAAUE,CAAI,IAETD,aAAeC,IAGtBF,EAAG,QAAQE,CAAI,IAEPF,EAAG,aAAaC,CAAG,MAAM,WAAWC,CAAI,MAG7CD,MAAQC;AAAA,EACnB;AAAA,EAEA,OAAO,OAAOD,GAAS;AACnB,WAAOD,EAAG,GAAGC,GAAK,OAAO;AAAA,EAC7B;AAAA,EAEA,OAAO,MAAMA,GAAS;AAClB,WAAOD,EAAG,GAAGC,GAAK,MAAM;AAAA,EAC5B;AAAA,EAEA,OAAO,QAAQA,GAAS;AACpB,WAAOD,EAAG,GAAGC,GAAK,QAAQ;AAAA,EAC9B;AAAA,EAEA,OAAO,QAAQA,GAAS;AACpB,WAAOD,EAAG,GAAGC,GAAK,QAAQ;AAAA,EAC9B;AAAA,EAEA,OAAO,WAAWA,GAAS;AACvB,WAAOD,EAAG,GAAGC,GAAK,WAAW;AAAA,EACjC;AAAA,EAEA,OAAO,SAASA,GAAS;AACrB,WAAOD,EAAG,GAAGC,GAAK,SAAS;AAAA,EAC/B;AAAA,EAEA,OAAO,UAAUA,GAAS;AACtB,WAAOD,EAAG,aAAaC,CAAG,MAAM;AAAA,EACpC;AAAA,EAEA,OAAO,cAAcE,GAAYC,GAAa;AAC1C,QAAI,CAACJ,EAAG,QAAQG,CAAI,EAAG,OAAM,IAAI,MAAM,sCAAsC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C,CAAG,KAAKA,MAAQ;AAAA,MACzC,CAACA,OAAcD,EAAG,OAAOC,CAAG,KAAKD,EAAG,QAAQC,CAAG,OAAOA,MAAQ,OAAQA,EAAqB,WAAW;AAAA,IAAA,EAGvF,KAAK,CAAAW,MAAcA,EAAWX,CAAG,CAAC;AAAA,EACzD;AAEJ;ACzCA,MAAM;AAAA,EACF,IAAAY;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC;AAAA,EACA,SAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,YAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AACJ,IAAIrB,GAEE;AAAA,EACF,YAAAsB;AAAA,EACA,QAAAC;AAAA,EACA,UAAAC;AACJ,IAAId,GAEEe,IAA0B;AAAA,EAC5B,OAAOzB;AAAA,EACP,UAAUU;AAAA,EACV,IAAAG;AAAA,EACA,SAAAE;AAAA,EACA,QAAAD;AAAA,EACA,SAAAE;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,YAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAE;AAAA,EACA,UAAAC;AAAA,EACA,YAAAF;AACJ;"}
|
package/dist/jis.umd.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
(function(t,
|
|
1
|
+
(function(t,r){typeof exports=="object"&&typeof module<"u"?module.exports=r():typeof define=="function"&&define.amd?define(r):(t=typeof globalThis<"u"?globalThis:t||self,t.jis=r())})(this,(function(){"use strict";class t{static callToString(e){return Object.prototype.toString.call(e)}static $string(e){return t.callToString(e)==="[object String]"}static is(e,i){return t.$function(i)?e instanceof i:t.$string(i)?t.callToString(e)===`[object ${i}]`:e===i}static $array(e){return t.is(e,"Array")}static $null(e){return t.is(e,"Null")}static $number(e){return t.is(e,"Number")}static $object(e){return t.is(e,"Object")}static $undefined(e){return t.is(e,"Undefined")}static $boolean(e){return t.is(e,"Boolean")}static $function(e){return t.callToString(e)==="[object Function]"}static objectIsValid(e,i){if(!t.$object(e))throw new Error("The data parameter must be an Object");if(!t.$object(i))throw new Error("The rules parameter must be an Object");let n=!0;return Object.getOwnPropertyNames(i).forEach(o=>{let a=i[o];if(t.$array(a)){if(a.length<1)return;let c=!1;return a.forEach(S=>{c=c||t.is(e[o],S)}),n=n&&c}n=n&&t.is(e[o],a)}),n}}class r{static $numeric(e){return[t.$number,n=>{let s=String(n||"");return/^[-+]?(([0-9]+)|([0-9]*(\.[0-9]+))|([0-9]+\.))([Ee]([-+]?[0-9]+))?$/g.test(s)}].some(n=>n(e))}static $primitive(e){return[t.$undefined,t.$null,t.$boolean,t.$number,t.$string,n=>t.is(n,"Symbol")].some(n=>n(e))}static $empty(e){return[t.$undefined,t.$null,n=>t.$boolean(n)&&!n,n=>t.$number(n)&&n===0,n=>(t.$array(n)||t.$string(n))&&(n==="0"||n.length===0)].some(n=>n(e))}}const{is:u,$array:l,$object:$,$number:f,$string:b,$boolean:d,$undefined:m,$function:p,$null:j}=t,{$primitive:g,$empty:h,$numeric:y}=r;return{types:t,semantic:r,is:u,$object:$,$array:l,$number:f,$string:b,$boolean:d,$undefined:m,$function:p,$null:j,$empty:h,$numeric:y,$primitive:g}}));
|
|
2
|
+
//# sourceMappingURL=jis.umd.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jis.umd.cjs","sources":["../src/Is.ts","../src/Semantic.ts","../src/main.ts"],"sourcesContent":["import type {IGen} from \"./interfaces/main\";\n\nexport default class Is{\n\n private static callToString(arg:any) {\n return Object.prototype.toString.call(arg)\n }\n\n static $string(arg:any) {\n return Is.callToString(arg) === '[object String]';\n }\n\n static is(arg: any, type : any){\n if(Is.$function(type))\n {\n return arg instanceof type;\n }\n\n if (Is.$string(type))\n {\n return Is.callToString(arg) === `[object ${type}]`;\n }\n\n return arg === type;\n }\n\n static $array(arg: any){\n return Is.is(arg, 'Array');\n }\n\n static $null(arg: any){\n return Is.is(arg, 'Null');\n }\n\n static $number(arg: any){\n return Is.is(arg, 'Number');\n }\n\n static $object(arg: any){\n return Is.is(arg, 'Object');\n }\n\n static $undefined(arg: any){\n return Is.is(arg, 'Undefined');\n }\n\n static $boolean(arg: any){\n return Is.is(arg, 'Boolean');\n }\n\n static $function(arg: any){\n return Is.callToString(arg) === '[object Function]';\n }\n\n static objectIsValid(data: IGen, rules: IGen) {\n if (!Is.$object(data)) throw new Error('The data parameter must be an Object');\n if (!Is.$object(rules)) throw new Error('The rules parameter must be an Object');\n\n let $response = true;\n let $keys = Object.getOwnPropertyNames(rules);\n\n $keys.forEach((key: string) => {\n let rule = rules[key];\n if (Is.$array(rule)) {\n if (rule.length < 1) return;\n let parcial = false;\n rule.forEach((_rule: any) => {\n parcial = parcial || Is.is(data[key], _rule);\n });\n return $response = $response && parcial;\n }\n $response = $response && Is.is(data[key], rule);\n });\n return $response;\n }\n\n}","import Is from \"./Is\";\n\nexport default class Semantic {\n\n static $numeric(arg: any)\n {\n const validations = [\n Is.$number,\n (arg: any) => {\n let $arg = String(arg || '');\n let regex = /^[-+]?(([0-9]+)|([0-9]*(\\.[0-9]+))|([0-9]+\\.))([Ee]([-+]?[0-9]+))?$/g;\n\n return regex.test( $arg );\n }\n ];\n\n return validations.some(validation => validation(arg));\n }\n\n static $primitive(arg: any)\n {\n let validations = [\n Is.$undefined,\n Is.$null,\n Is.$boolean,\n Is.$number,\n Is.$string,\n (arg: any) => Is.is(arg, 'Symbol')\n ]\n\n return validations.some(validation => validation(arg))\n }\n\n static $empty(arg: any)\n {\n let validations = [\n Is.$undefined,\n Is.$null,\n\n (arg: any) => Is.$boolean(arg) && !arg,\n (arg: any) => Is.$number(arg) && arg === 0,\n (arg: any) => (Is.$array(arg) || Is.$string(arg)) && (arg === \"0\" || (arg as any[]|string).length === 0)\n ]\n\n return validations.some(validation => validation(arg))\n }\n\n}","\nimport Is from \"./Is\";\nimport type ILegacyApi from \"./interfaces/ILegacyApi\";\nimport Semantic from \"./Semantic\";\nimport type IApi from \"./interfaces/IApi\";\n\nconst {\n is,\n $array,\n $object,\n $number,\n $string,\n $boolean,\n $undefined,\n $function,\n $null\n} = Is;\n\nconst {\n $primitive,\n $empty,\n $numeric\n} = Semantic\n\nconst api : ILegacyApi & IApi = {\n types: Is,\n semantic: Semantic,\n is,\n $object,\n $array,\n $number,\n $string,\n $boolean,\n $undefined,\n $function,\n $null,\n $empty,\n $numeric,\n $primitive\n};\n\nexport default api;"],"names":["Is","arg","type","data","rules","$response","key","rule","parcial","_rule","Semantic","$arg","validation","is","$array","$object","$number","$string","$boolean","$undefined","$function","$null","$primitive","$empty","$numeric"],"mappings":"qNAEA,MAAqBA,CAAE,CAEnB,OAAe,aAAaC,EAAS,CACjC,OAAO,OAAO,UAAU,SAAS,KAAKA,CAAG,CAC7C,CAEA,OAAO,QAAQA,EAAS,CACpB,OAAOD,EAAG,aAAaC,CAAG,IAAM,iBACpC,CAEA,OAAO,GAAGA,EAAUC,EAAW,CAC3B,OAAGF,EAAG,UAAUE,CAAI,EAETD,aAAeC,EAGtBF,EAAG,QAAQE,CAAI,EAEPF,EAAG,aAAaC,CAAG,IAAM,WAAWC,CAAI,IAG7CD,IAAQC,CACnB,CAEA,OAAO,OAAOD,EAAS,CACnB,OAAOD,EAAG,GAAGC,EAAK,OAAO,CAC7B,CAEA,OAAO,MAAMA,EAAS,CAClB,OAAOD,EAAG,GAAGC,EAAK,MAAM,CAC5B,CAEA,OAAO,QAAQA,EAAS,CACpB,OAAOD,EAAG,GAAGC,EAAK,QAAQ,CAC9B,CAEA,OAAO,QAAQA,EAAS,CACpB,OAAOD,EAAG,GAAGC,EAAK,QAAQ,CAC9B,CAEA,OAAO,WAAWA,EAAS,CACvB,OAAOD,EAAG,GAAGC,EAAK,WAAW,CACjC,CAEA,OAAO,SAASA,EAAS,CACrB,OAAOD,EAAG,GAAGC,EAAK,SAAS,CAC/B,CAEA,OAAO,UAAUA,EAAS,CACtB,OAAOD,EAAG,aAAaC,CAAG,IAAM,mB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,KAAQA,EAAqB,SAAW,EAAA,EAGvF,KAAKW,GAAcA,EAAWX,CAAG,CAAC,CACzD,CAEJ,CCzCA,KAAM,CACF,GAAAY,EACA,OAAAC,EACA,QAAAC,EACA,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,WAAAC,EACA,UAAAC,EACA,MAAAC,CACJ,EAAIrB,EAEE,CACF,WAAAsB,EACA,OAAAC,EACA,SAAAC,CACJ,EAAId,QAE4B,CAC5B,MAAOV,EACP,SAAUU,EACV,GAAAG,EACA,QAAAE,EACA,OAAAD,EACA,QAAAE,EACA,QAAAC,EACA,SAAAC,EACA,WAAAC,EACA,UAAAC,EACA,MAAAC,EACA,OAAAE,EACA,SAAAC,EACA,WAAAF,CACJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IGen } from './interfaces/main';
|
|
2
2
|
export default class Is {
|
|
3
3
|
private static callToString;
|
|
4
4
|
static $string(arg: any): boolean;
|
|
@@ -10,8 +10,5 @@ export default class Is {
|
|
|
10
10
|
static $undefined(arg: any): boolean;
|
|
11
11
|
static $boolean(arg: any): boolean;
|
|
12
12
|
static $function(arg: any): boolean;
|
|
13
|
-
static objectIsValid(data:
|
|
14
|
-
static $numeric(arg: any): boolean;
|
|
15
|
-
static $primitive(arg: any): boolean;
|
|
16
|
-
static $empty(arg: any): boolean;
|
|
13
|
+
static objectIsValid(data: IGen, rules: IGen): boolean;
|
|
17
14
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { default as Is } from '../Is';
|
|
2
|
+
import { default as Semantic } from '../Semantic';
|
|
3
|
+
export default interface ILegacyApi {
|
|
4
|
+
/** @deprecated Use `jis.types.is`. It'll be remove in v3.0.0 **/
|
|
5
|
+
is: typeof Is.is;
|
|
6
|
+
/** @deprecated Use `jis.types.$object`. It'll be remove in v3.0.0 **/
|
|
7
|
+
$object: typeof Is.$object;
|
|
8
|
+
/** @deprecated Use `jis.types.$array`. It'll be remove in v3.0.0 **/
|
|
9
|
+
$array: typeof Is.$array;
|
|
10
|
+
/** @deprecated Use `jis.types.$number`. It'll be remove in v3.0.0 **/
|
|
11
|
+
$number: typeof Is.$number;
|
|
12
|
+
/** @deprecated Use `jis.types.$string`. It'll be remove in v3.0.0 **/
|
|
13
|
+
$string: typeof Is.$string;
|
|
14
|
+
/** @deprecated Use `jis.types.$boolean`. It'll be remove in v3.0.0 **/
|
|
15
|
+
$boolean: typeof Is.$boolean;
|
|
16
|
+
/** @deprecated Use `jis.types.$undefined`. It'll be remove in v3.0.0 **/
|
|
17
|
+
$undefined: typeof Is.$undefined;
|
|
18
|
+
/** @deprecated Use `jis.types.$function`. It'll be remove in v3.0.0 **/
|
|
19
|
+
$function: typeof Is.$function;
|
|
20
|
+
/** @deprecated Use `jis.types.$null`. It'll be remove in v3.0.0 **/
|
|
21
|
+
$null: typeof Is.$null;
|
|
22
|
+
/** @deprecated Use `jis.semantic.$empty`. It'll be remove in v3.0.0 **/
|
|
23
|
+
$empty: typeof Semantic.$empty;
|
|
24
|
+
/** @deprecated Use `jis.semantic.$numeric`. It'll be remove in v3.0.0 **/
|
|
25
|
+
$numeric: typeof Semantic.$numeric;
|
|
26
|
+
/** @deprecated Use `jis.semantic.$primitive`. It'll be remove in v3.0.0 **/
|
|
27
|
+
$primitive: typeof Semantic.$primitive;
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jis",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.2.0-preview.1",
|
|
5
5
|
"description": "When you need validate the variable data type",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/jis.umd.cjs",
|
|
8
8
|
"module": "./dist/jis.js",
|
|
9
|
-
"
|
|
9
|
+
"browser": "./dist/jis.browser.min.js",
|
|
10
|
+
"unpkg": "./dist/jis.browser.min.js",
|
|
11
|
+
"jsdelivr": "./dist/jis.browser.min.js",
|
|
12
|
+
"types": "./dist/types/main.d.ts",
|
|
10
13
|
"files": [
|
|
11
|
-
"dist"
|
|
14
|
+
"dist",
|
|
15
|
+
"CHANGELOG.md"
|
|
12
16
|
],
|
|
13
17
|
"exports": {
|
|
14
18
|
".": {
|
|
15
|
-
"
|
|
19
|
+
"browser": "./dist/jis.browser.min.js",
|
|
20
|
+
"types": "./dist/types/main.d.ts",
|
|
16
21
|
"import": "./dist/jis.js",
|
|
17
22
|
"require": "./dist/jis.umd.cjs"
|
|
18
23
|
}
|
|
19
24
|
},
|
|
20
25
|
"scripts": {
|
|
21
26
|
"dev": "vite",
|
|
22
|
-
"build": "tsc && vite build",
|
|
27
|
+
"build": "tsc && vite build && rollup -c rollup.legacy.config.mjs",
|
|
23
28
|
"preview": "vite preview",
|
|
24
29
|
"test": "vitest run"
|
|
25
30
|
},
|
|
@@ -40,7 +45,14 @@
|
|
|
40
45
|
"author": "Jose Can <joseluisgpecanmtz@gmail.com>",
|
|
41
46
|
"license": "ISC",
|
|
42
47
|
"devDependencies": {
|
|
48
|
+
"@babel/core": "^7.28.5",
|
|
49
|
+
"@babel/preset-env": "^7.28.5",
|
|
50
|
+
"@rollup/plugin-babel": "^6.1.0",
|
|
51
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
52
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
43
53
|
"@types/node": "^25.0.3",
|
|
54
|
+
"rollup": "^4.55.1",
|
|
55
|
+
"tslib": "^2.8.1",
|
|
44
56
|
"typescript": "~5.9.3",
|
|
45
57
|
"vite": "^7.2.4",
|
|
46
58
|
"vite-plugin-dts": "^4.5.4",
|
package/dist/main.d.ts
DELETED