jis 2.0.2 → 2.1.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 +25 -0
- package/README.md +189 -134
- package/dist/Is.d.ts +2 -5
- package/dist/Semantic.d.ts +5 -0
- package/dist/interfaces/ILegacyApi.d.ts +28 -0
- package/dist/interfaces/main.d.ts +1 -1
- package/dist/jis.js +91 -56
- package/dist/jis.umd.cjs +1 -1
- package/dist/main.d.ts +7 -1
- package/package.json +3 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
|
|
13
|
+
## [2.0.2]
|
|
14
|
+
### Fixed
|
|
15
|
+
- Fixed CI configuration to run `build` and `test` jobs only on merge requests to `dev` and `master`
|
|
16
|
+
- Fixed package publishing issue where the `dist/` folder was not included
|
|
17
|
+
|
|
18
|
+
## [2.0.1]
|
|
19
|
+
### Changed
|
|
20
|
+
- Migrated build system from webpack to Vite
|
|
21
|
+
- Integrated Vitest
|
|
22
|
+
- Integrated CI/CD (build, test, and deploy)
|
|
23
|
+
|
|
24
|
+
### Notes
|
|
25
|
+
- Previous versions (< 2.0.1) were early iterations and did not follow a formal changelog.
|
package/README.md
CHANGED
|
@@ -1,242 +1,297 @@
|
|
|
1
1
|
# J`is`
|
|
2
2
|
|
|
3
|
-
`jis` is a data type verifier for
|
|
3
|
+
`jis` is a lightweight runtime data type verifier designed for browsers and environments where static typing or modern language features may not be reliable or available.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Based on `Object.prototype.toString.call`, the library provides a set of methods to perform reliable runtime data type checks.
|
|
6
|
+
|
|
7
|
+
### Why jis?
|
|
8
|
+
|
|
9
|
+
`jis` comes from `is`, the core of the library, prefixed with `j` (my initial).
|
|
10
|
+
Phonetically, it sounds like “ji-is”, a subtle nod to JS itself.
|
|
11
|
+
|
|
12
|
+
In the browser, everything runs as JavaScript at runtime.
|
|
13
|
+
Static types disappear after transpilation, and runtime type checks are often limited, inconsistent, or dependent on modern language features that are not always available.
|
|
14
|
+
|
|
15
|
+
`jis` focuses on providing simple, reliable runtime `is` checks using the most stable and widely supported mechanisms in JavaScript.
|
|
6
16
|
|
|
7
17
|
### Installation
|
|
8
|
-
|
|
9
|
-
```shell script
|
|
10
|
-
npm install jis
|
|
11
|
-
```
|
|
12
18
|
|
|
13
|
-
You can install this library with
|
|
19
|
+
You can install this library with npm or yarn.
|
|
14
20
|
|
|
15
|
-
```shell script
|
|
16
|
-
npm install jis
|
|
21
|
+
```shell script
|
|
22
|
+
npm install jis
|
|
17
23
|
```
|
|
18
24
|
|
|
19
25
|
### Usage
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
#### Import in ES5 or higher
|
|
22
28
|
|
|
23
29
|
```js
|
|
24
|
-
|
|
30
|
+
const jis = require('jis')
|
|
25
31
|
```
|
|
26
32
|
|
|
27
|
-
|
|
33
|
+
#### Import in TS
|
|
28
34
|
|
|
29
35
|
```ts
|
|
30
36
|
import jis from 'jis'
|
|
31
37
|
```
|
|
32
38
|
|
|
33
|
-
|
|
39
|
+
### ⚠️ Backward compatibility
|
|
34
40
|
|
|
35
|
-
|
|
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`.
|
|
36
42
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
jis.$array( [] ) // true
|
|
40
|
-
|
|
41
|
-
jis.$array( true ) //false
|
|
42
|
-
jis.$array( function() {} ) // false
|
|
43
|
-
jis.$array( null ) // false
|
|
44
|
-
jis.$array( 12 ) // false
|
|
45
|
-
jis.$array( {} ) // false
|
|
46
|
-
jis.$array( '' ) // false
|
|
47
|
-
jis.$array( undefined ) // false
|
|
43
|
+
If you are starting a new project or updating existing code, **use the new namespaces shown below**.
|
|
48
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);
|
|
49
60
|
```
|
|
50
61
|
|
|
51
|
-
|
|
62
|
+
Use the new namespaces instead:
|
|
52
63
|
|
|
53
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
|
+
```
|
|
54
79
|
|
|
55
|
-
|
|
56
|
-
jis.$boolean( false ) // true
|
|
80
|
+
## API
|
|
57
81
|
|
|
58
|
-
|
|
59
|
-
|
|
82
|
+
### Type checks (`jis.types`)
|
|
83
|
+
#### $array
|
|
60
84
|
|
|
61
|
-
|
|
85
|
+
```js
|
|
86
|
+
const { $array } = jis.types // jis.types.$array
|
|
87
|
+
|
|
88
|
+
$array( [] ) // true
|
|
62
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
|
|
63
97
|
```
|
|
64
98
|
|
|
65
|
-
|
|
99
|
+
#### $boolean
|
|
66
100
|
|
|
67
101
|
```js
|
|
102
|
+
const { $boolean } = jis.types
|
|
68
103
|
|
|
69
|
-
|
|
104
|
+
$boolean( true ) // true
|
|
105
|
+
$boolean( false ) // true
|
|
70
106
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
jis.$function( '' ) // false
|
|
107
|
+
$boolean( [] ) // false
|
|
108
|
+
$boolean( function() {} ) // false
|
|
74
109
|
|
|
75
110
|
// ...
|
|
76
|
-
|
|
77
111
|
```
|
|
78
112
|
|
|
79
|
-
|
|
113
|
+
#### $function
|
|
80
114
|
|
|
81
115
|
```js
|
|
116
|
+
const { $function } = jis.types
|
|
82
117
|
|
|
83
|
-
|
|
118
|
+
$function( function() {} ) // true
|
|
84
119
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
120
|
+
$function( 12 ) // false
|
|
121
|
+
$function( {} ) // false
|
|
122
|
+
$function( '' ) // false
|
|
88
123
|
|
|
89
124
|
// ...
|
|
90
|
-
|
|
91
125
|
```
|
|
92
126
|
|
|
93
|
-
|
|
127
|
+
#### $null
|
|
94
128
|
|
|
95
129
|
```js
|
|
130
|
+
const { $null } = jis.types
|
|
96
131
|
|
|
97
|
-
|
|
132
|
+
$null( null ) // true
|
|
98
133
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
134
|
+
$null( {} ) // false
|
|
135
|
+
$null( '' ) // false
|
|
136
|
+
$null( undefined ) // false
|
|
102
137
|
|
|
103
138
|
// ...
|
|
104
|
-
|
|
105
139
|
```
|
|
106
140
|
|
|
107
|
-
|
|
141
|
+
#### $number
|
|
108
142
|
|
|
109
143
|
```js
|
|
144
|
+
const { $number } = jis.types
|
|
110
145
|
|
|
111
|
-
|
|
146
|
+
$number( 12 ) // true
|
|
112
147
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
148
|
+
$number( function() {} ) // false
|
|
149
|
+
$number( null ) // false
|
|
150
|
+
$number( undefined ) // false
|
|
116
151
|
|
|
117
152
|
// ...
|
|
118
|
-
|
|
119
153
|
```
|
|
120
154
|
|
|
121
|
-
|
|
155
|
+
#### $object
|
|
122
156
|
|
|
123
157
|
```js
|
|
158
|
+
const { $object } = jis.types
|
|
124
159
|
|
|
125
|
-
|
|
160
|
+
$object( {} ) // true
|
|
126
161
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
162
|
+
$object( [] ) // false
|
|
163
|
+
$object( true ) // false
|
|
164
|
+
$object( 12 ) // false
|
|
130
165
|
|
|
131
166
|
// ...
|
|
132
|
-
|
|
133
167
|
```
|
|
134
168
|
|
|
135
|
-
|
|
169
|
+
#### $string
|
|
136
170
|
|
|
137
171
|
```js
|
|
172
|
+
const { $string } = jis.types
|
|
138
173
|
|
|
139
|
-
|
|
174
|
+
$string( 'Some text' ) // true
|
|
140
175
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
176
|
+
$string( [] ) // false
|
|
177
|
+
$string( true ) // false
|
|
178
|
+
$string( undefined ) // false
|
|
144
179
|
|
|
145
180
|
// ...
|
|
146
|
-
|
|
147
181
|
```
|
|
148
182
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
Check if the argument is a number or number string (including exponential)
|
|
183
|
+
#### $undefined
|
|
152
184
|
|
|
153
185
|
```js
|
|
186
|
+
const { $undefined } = jis.types
|
|
154
187
|
|
|
155
|
-
|
|
156
|
-
jis.$numeric( '12' ) // true
|
|
157
|
-
jis.$numeric( '-12' ) // true
|
|
158
|
-
jis.$numeric( '+12' ) // true
|
|
159
|
-
jis.$numeric( '12.' ) // true
|
|
160
|
-
jis.$numeric( '12.e5' ) // true
|
|
161
|
-
jis.$numeric( '12.E5' ) // true
|
|
162
|
-
jis.$numeric( '12.E-5' ) // true
|
|
163
|
-
jis.$numeric( '-12.E-5' ) // true
|
|
164
|
-
jis.$numeric( '+12.E-5' ) // true
|
|
188
|
+
$undefined( undefined ) // true
|
|
165
189
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
jis.$numeric( null ) // false
|
|
190
|
+
$undefined( [] ) // false
|
|
191
|
+
$undefined( {} ) // false
|
|
192
|
+
$undefined( '' ) // false
|
|
170
193
|
|
|
194
|
+
// ...
|
|
171
195
|
```
|
|
172
196
|
|
|
173
|
-
|
|
197
|
+
#### is
|
|
174
198
|
|
|
175
|
-
|
|
199
|
+
This method is the core of the library and provides more flexible and advanced type checks.
|
|
176
200
|
|
|
177
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
|
|
178
213
|
|
|
179
|
-
|
|
180
|
-
|
|
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
|
|
214
|
+
let date = new Date();
|
|
215
|
+
is(date, Date) // true
|
|
186
216
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
jis.$primitive(new Date()) // false
|
|
217
|
+
is(/^$/g, RegExp) // true
|
|
218
|
+
is(/^$/g, 'RegExp') // true
|
|
190
219
|
|
|
191
|
-
|
|
220
|
+
is(12, 12) // true
|
|
221
|
+
is(12, 13) // false
|
|
192
222
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
```js
|
|
223
|
+
// ... experiment with this method :D
|
|
224
|
+
```
|
|
196
225
|
|
|
197
|
-
jis
|
|
198
|
-
|
|
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
|
|
226
|
+
### Semantic checks (`jis.semantic`)
|
|
227
|
+
#### $numeric
|
|
205
228
|
|
|
206
|
-
|
|
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
|
|
229
|
+
Check if the argument is a number or number string (including exponential)
|
|
212
230
|
|
|
231
|
+
```js
|
|
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
|
|
213
249
|
```
|
|
214
250
|
|
|
215
|
-
|
|
251
|
+
#### $primitive
|
|
216
252
|
|
|
217
|
-
|
|
253
|
+
Check if the argument is a primitive value
|
|
218
254
|
|
|
219
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
|
+
```
|
|
220
270
|
|
|
221
|
-
|
|
222
|
-
jis.is( false, 'Boolean' ) // true
|
|
223
|
-
jis.is( true, 'Boolean' ) // true
|
|
224
|
-
jis.is( function(){}, 'Function' ) // true
|
|
225
|
-
jis.is( null, 'Null' ) // true
|
|
226
|
-
jis.is( 12, 'Number' ) // true
|
|
227
|
-
jis.is( {}, 'Object' ) // true
|
|
228
|
-
jis.is( 'Text', 'String' ) // true
|
|
229
|
-
jis.is( undefined, 'Undefined' ) // true
|
|
230
|
-
|
|
231
|
-
let date = new Date();
|
|
232
|
-
jis.is(date, Date) // true
|
|
271
|
+
#### $empty
|
|
233
272
|
|
|
234
|
-
|
|
235
|
-
jis.is(/^$/g, 'RegExp') // true
|
|
273
|
+
$empty follows a semantic definition of emptiness, where certain falsy or zero-like values are intentionally considered empty.
|
|
236
274
|
|
|
237
|
-
|
|
238
|
-
|
|
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
|
+
```
|
|
239
294
|
|
|
240
|
-
|
|
295
|
+
## Changelog
|
|
241
296
|
|
|
242
|
-
|
|
297
|
+
See [CHANGELOG.md](./CHANGELOG.md) for version history and breaking changes.
|
package/dist/Is.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IGen } from './interfaces/main.ts';
|
|
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.ts';
|
|
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/dist/jis.js
CHANGED
|
@@ -1,76 +1,111 @@
|
|
|
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
|
};
|
package/dist/jis.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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}}));
|
package/dist/main.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { default as Is } from './Is.ts';
|
|
2
|
-
|
|
2
|
+
import { default as ILegacyApi } from './interfaces/ILegacyApi.ts';
|
|
3
|
+
import { default as Semantic } from './Semantic.ts';
|
|
4
|
+
declare const api: ILegacyApi & {
|
|
5
|
+
types: typeof Is;
|
|
6
|
+
semantic: typeof Semantic;
|
|
7
|
+
};
|
|
8
|
+
export default api;
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jis",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.1.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
|
"types": "./dist/main.d.ts",
|
|
10
10
|
"files": [
|
|
11
|
-
"dist"
|
|
11
|
+
"dist",
|
|
12
|
+
"CHANGELOG.md"
|
|
12
13
|
],
|
|
13
14
|
"exports": {
|
|
14
15
|
".": {
|