is-what 4.0.0 → 4.1.3

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/package.json CHANGED
@@ -1,17 +1,31 @@
1
1
  {
2
2
  "name": "is-what",
3
3
  "sideEffects": false,
4
- "version": "4.0.0",
5
- "description": "JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.",
6
4
  "type": "module",
7
- "exports": "./dist/index.js",
8
- "typings": "./types/index.d.ts",
5
+ "version": "4.1.3",
6
+ "description": "JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.",
7
+ "module": "./dist/index.es.js",
8
+ "main": "./dist/index.cjs",
9
+ "types": "./dist/types/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.es.js",
13
+ "require": "./dist/index.cjs",
14
+ "types": "./dist/types/index.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "engines": {
21
+ "node": ">=12.13",
22
+ "npm": ">=7"
23
+ },
9
24
  "scripts": {
10
- "test": "ava",
11
- "lint": "tsc --noEmit src/index.ts && eslint . --ext .js,.jsx,.ts,.tsx",
12
- "rollup": "rollup -c ./build.js",
13
- "build": "rimraf types && rimraf dist && npm run lint && npm run rollup && npm run test",
14
- "release": "npm run build && np"
25
+ "test": "vitest run",
26
+ "lint": "tsc --noEmit ./src/index.ts && eslint ./src --ext .ts",
27
+ "build": "rollup -c ./scripts/build.js",
28
+ "release": "npm run lint && del dist && npm run build && np"
15
29
  },
16
30
  "repository": {
17
31
  "type": "git",
@@ -39,41 +53,30 @@
39
53
  "is-plain-object"
40
54
  ],
41
55
  "author": "Luca Ban - Mesqueeb",
56
+ "funding": "https://github.com/sponsors/mesqueeb",
42
57
  "license": "MIT",
43
58
  "bugs": {
44
59
  "url": "https://github.com/mesqueeb/is-what/issues"
45
60
  },
46
61
  "homepage": "https://github.com/mesqueeb/is-what#readme",
47
62
  "devDependencies": {
48
- "@babel/core": "^7.13.8",
49
- "@types/babel-core": "^6.25.6",
50
- "@typescript-eslint/eslint-plugin": "^4.16.1",
51
- "@typescript-eslint/parser": "^4.16.1",
52
- "ava": "^3.15.0",
53
- "babel-core": "^7.0.0-bridge.0",
54
- "babel-preset-env": "^1.7.0",
55
- "eslint": "^7.21.0",
56
- "eslint-config-prettier": "^8.1.0",
57
- "eslint-plugin-tree-shaking": "^1.8.0",
58
- "np": "^7.4.0",
59
- "prettier": "^2.2.1",
60
- "rimraf": "^3.0.2",
61
- "rollup": "^2.40.0",
62
- "rollup-plugin-typescript2": "^0.30.0",
63
- "ts-node": "^9.1.1",
64
- "typescript": "^4.2.3"
65
- },
66
- "engines": {
67
- "node": ">=12.13",
68
- "npm": ">=7"
63
+ "@typescript-eslint/eslint-plugin": "^5.10.1",
64
+ "@typescript-eslint/parser": "^5.10.1",
65
+ "del-cli": "^4.0.1",
66
+ "eslint": "^8.7.0",
67
+ "eslint-config-prettier": "^8.3.0",
68
+ "eslint-plugin-tree-shaking": "^1.10.0",
69
+ "np": "^7.6.0",
70
+ "prettier": "^2.5.1",
71
+ "rollup": "^2.66.0",
72
+ "rollup-plugin-typescript2": "^0.31.1",
73
+ "typescript": "^4.5.5",
74
+ "vitest": "^0.2.1"
69
75
  },
70
76
  "ava": {
71
77
  "extensions": {
72
78
  "ts": "module"
73
79
  },
74
- "nonSemVerExperiments": {
75
- "configurableModuleFormat": true
76
- },
77
80
  "nodeArguments": [
78
81
  "--loader=ts-node/esm"
79
82
  ]
@@ -83,6 +86,12 @@
83
86
  "branch": "production"
84
87
  },
85
88
  "eslintConfig": {
89
+ "ignorePatterns": [
90
+ "node_modules",
91
+ "dist",
92
+ "scripts",
93
+ "test"
94
+ ],
86
95
  "root": true,
87
96
  "parser": "@typescript-eslint/parser",
88
97
  "plugins": [
@@ -96,10 +105,11 @@
96
105
  "prettier"
97
106
  ],
98
107
  "rules": {
108
+ "@typescript-eslint/no-empty-function": "off",
99
109
  "@typescript-eslint/no-explicit-any": "off",
100
110
  "@typescript-eslint/ban-ts-ignore": "off",
101
111
  "tree-shaking/no-side-effects-in-initialization": "error",
102
- "@typescript-eslint/explicit-module-boundary-types": "off"
112
+ "@typescript-eslint/ban-ts-comment": "off"
103
113
  }
104
114
  }
105
115
  }
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["env"]
3
- }
package/.eslintignore DELETED
@@ -1,9 +0,0 @@
1
- # don't ever lint node_modules
2
- node_modules
3
- # don't lint build output (make sure it's set to your correct build folder name)
4
- dist
5
- # don't lint nyc coverage output
6
- coverage
7
-
8
- test
9
- .eslintrc.js
@@ -1,12 +0,0 @@
1
- # These are supported funding model platforms
2
-
3
- github: mesqueeb
4
- patreon: # Replace with a single Patreon username
5
- open_collective: # Replace with a single Open Collective username
6
- ko_fi: # Replace with a single Ko-fi username
7
- tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
- community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
- liberapay: # Replace with a single Liberapay username
10
- issuehunt: # Replace with a single IssueHunt username
11
- otechie: # Replace with a single Otechie username
12
- custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
package/.prettierrc DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "printWidth": 100,
3
- "tabWidth": 2,
4
- "singleQuote": true,
5
- "trailingComma": "es5",
6
- "semi": false,
7
- "bracketSpacing": true,
8
- "quoteProps": "consistent"
9
- }
@@ -1,9 +0,0 @@
1
- {
2
- "editor.formatOnSave": true,
3
- "editor.defaultFormatter": "esbenp.prettier-vscode",
4
- "editor.tabSize": 2, // make sure this is the same as .prettierrc
5
- "editor.insertSpaces": true,
6
- "files.insertFinalNewline": true,
7
- "files.trimFinalNewlines": true,
8
- "files.trimTrailingWhitespace": true
9
- }
package/build.js DELETED
@@ -1,40 +0,0 @@
1
- /* eslint-disable */
2
-
3
- // npm i -D rollup rollup-plugin-typescript2 typescript
4
- import typescript from 'rollup-plugin-typescript2'
5
-
6
- // ------------------------------------------------------------------------------------------
7
- // formats
8
- // ------------------------------------------------------------------------------------------
9
- // amd – Asynchronous Module Definition, used with module loaders like RequireJS
10
- // cjs – CommonJS, suitable for Node and Browserify/Webpack
11
- // esm – Keep the bundle as an ES module file
12
- // iife – A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this, because it leads to smaller file sizes.)
13
- // umd – Universal Module Definition, works as amd, cjs and iife all in one
14
- // system – Native format of the SystemJS loader
15
-
16
- // ------------------------------------------------------------------------------------------
17
- // setup
18
- // ------------------------------------------------------------------------------------------
19
- const pkg = require('./package.json')
20
- const name = pkg.name
21
- const className = name.replace(/(^\w|-\w)/g, (c) => c.replace('-', '').toUpperCase())
22
-
23
- export default [
24
- {
25
- input: 'src/index.ts',
26
- output: [
27
- {
28
- file: 'dist/index.js',
29
- format: 'esm',
30
- sourcemap: false,
31
- name: className,
32
- exports: 'named',
33
- },
34
- ],
35
- plugins: [
36
- typescript({ useTsconfigDeclarationDir: true, tsconfigOverride: { exclude: ['test/**/*'] } }),
37
- ],
38
- external: Object.keys(pkg.dependencies || []),
39
- },
40
- ]
package/src/index.ts DELETED
@@ -1,395 +0,0 @@
1
- export type AnyFunction = (...args: any[]) => any
2
- export type AnyAsyncFunction = (...args: any[]) => Promise<any>
3
- export type AnyClass = new (...args: any[]) => any
4
- export type PlainObject = Record<string | number | symbol, any>
5
-
6
- type TypeGuard<A, B extends A> = (payload: A) => payload is B
7
-
8
- /**
9
- * Returns the object type of the given payload
10
- *
11
- * @param {*} payload
12
- * @returns {string}
13
- */
14
- export function getType(payload: any): string {
15
- return Object.prototype.toString.call(payload).slice(8, -1)
16
- }
17
-
18
- /**
19
- * Returns whether the payload is undefined
20
- *
21
- * @param {*} payload
22
- * @returns {payload is undefined}
23
- */
24
- export function isUndefined(payload: any): payload is undefined {
25
- return getType(payload) === 'Undefined'
26
- }
27
-
28
- /**
29
- * Returns whether the payload is null
30
- *
31
- * @param {*} payload
32
- * @returns {payload is null}
33
- */
34
- export function isNull(payload: any): payload is null {
35
- return getType(payload) === 'Null'
36
- }
37
-
38
- /**
39
- * Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
40
- *
41
- * @param {*} payload
42
- * @returns {payload is PlainObject}
43
- */
44
- export function isPlainObject(payload: any): payload is PlainObject {
45
- if (getType(payload) !== 'Object') return false
46
- return payload.constructor === Object && Object.getPrototypeOf(payload) === Object.prototype
47
- }
48
-
49
- /**
50
- * Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
51
- *
52
- * @param {*} payload
53
- * @returns {payload is PlainObject}
54
- */
55
- export function isObject(payload: any): payload is PlainObject {
56
- return isPlainObject(payload)
57
- }
58
-
59
- /**
60
- * Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
61
- *
62
- * @param {*} payload
63
- * @returns {payload is { [K in any]: never }}
64
- */
65
- export function isEmptyObject(payload: any): payload is { [K in any]: never } {
66
- return isPlainObject(payload) && Object.keys(payload).length === 0
67
- }
68
-
69
- /**
70
- * Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
71
- *
72
- * @param {*} payload
73
- * @returns {payload is PlainObject}
74
- */
75
- export function isFullObject(payload: any): payload is PlainObject {
76
- return isPlainObject(payload) && Object.keys(payload).length > 0
77
- }
78
-
79
- /**
80
- * Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
81
- *
82
- * @param {*} payload
83
- * @returns {payload is PlainObject}
84
- */
85
- export function isAnyObject(payload: any): payload is PlainObject {
86
- return getType(payload) === 'Object'
87
- }
88
-
89
- /**
90
- * Returns whether the payload is an object like a type passed in < >
91
- *
92
- * Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop.
93
- *
94
- * @template T this must be passed in < >
95
- * @param {*} payload
96
- * @returns {payload is T}
97
- */
98
- export function isObjectLike<T extends PlainObject>(payload: any): payload is T {
99
- return isAnyObject(payload)
100
- }
101
-
102
- /**
103
- * Returns whether the payload is a function (regular or async)
104
- *
105
- * @param {*} payload
106
- * @returns {payload is AnyFunction}
107
- */
108
- export function isFunction(payload: any): payload is AnyFunction {
109
- return typeof payload === 'function'
110
- }
111
-
112
- /**
113
- * Returns whether the payload is an array
114
- *
115
- * @param {any} payload
116
- * @returns {payload is any[]}
117
- */
118
- export function isArray(payload: any): payload is any[] {
119
- return getType(payload) === 'Array'
120
- }
121
-
122
- /**
123
- * Returns whether the payload is a an array with at least 1 item
124
- *
125
- * @param {*} payload
126
- * @returns {payload is any[]}
127
- */
128
- export function isFullArray(payload: any): payload is any[] {
129
- return isArray(payload) && payload.length > 0
130
- }
131
-
132
- /**
133
- * Returns whether the payload is a an empty array
134
- *
135
- * @param {*} payload
136
- * @returns {payload is []}
137
- */
138
- export function isEmptyArray(payload: any): payload is [] {
139
- return isArray(payload) && payload.length === 0
140
- }
141
-
142
- /**
143
- * Returns whether the payload is a string
144
- *
145
- * @param {*} payload
146
- * @returns {payload is string}
147
- */
148
- export function isString(payload: any): payload is string {
149
- return getType(payload) === 'String'
150
- }
151
-
152
- /**
153
- * Returns whether the payload is a string, BUT returns false for ''
154
- *
155
- * @param {*} payload
156
- * @returns {payload is string}
157
- */
158
- export function isFullString(payload: any): payload is string {
159
- return isString(payload) && payload !== ''
160
- }
161
-
162
- /**
163
- * Returns whether the payload is ''
164
- *
165
- * @param {*} payload
166
- * @returns {payload is string}
167
- */
168
- export function isEmptyString(payload: any): payload is string {
169
- return payload === ''
170
- }
171
-
172
- /**
173
- * Returns whether the payload is a number (but not NaN)
174
- *
175
- * This will return `false` for `NaN`!!
176
- *
177
- * @param {*} payload
178
- * @returns {payload is number}
179
- */
180
- export function isNumber(payload: any): payload is number {
181
- return getType(payload) === 'Number' && !isNaN(payload)
182
- }
183
-
184
- /**
185
- * Returns whether the payload is a boolean
186
- *
187
- * @param {*} payload
188
- * @returns {payload is boolean}
189
- */
190
- export function isBoolean(payload: any): payload is boolean {
191
- return getType(payload) === 'Boolean'
192
- }
193
-
194
- /**
195
- * Returns whether the payload is a regular expression (RegExp)
196
- *
197
- * @param {*} payload
198
- * @returns {payload is RegExp}
199
- */
200
- export function isRegExp(payload: any): payload is RegExp {
201
- return getType(payload) === 'RegExp'
202
- }
203
-
204
- /**
205
- * Returns whether the payload is a Map
206
- *
207
- * @param {*} payload
208
- * @returns {payload is Map<any, any>}
209
- */
210
- export function isMap(payload: any): payload is Map<any, any> {
211
- return getType(payload) === 'Map'
212
- }
213
-
214
- /**
215
- * Returns whether the payload is a WeakMap
216
- *
217
- * @param {*} payload
218
- * @returns {payload is WeakMap<any, any>}
219
- */
220
- export function isWeakMap(payload: any): payload is WeakMap<any, any> {
221
- return getType(payload) === 'WeakMap'
222
- }
223
-
224
- /**
225
- * Returns whether the payload is a Set
226
- *
227
- * @param {*} payload
228
- * @returns {payload is Set<any>}
229
- */
230
- export function isSet(payload: any): payload is Set<any> {
231
- return getType(payload) === 'Set'
232
- }
233
-
234
- /**
235
- * Returns whether the payload is a WeakSet
236
- *
237
- * @param {*} payload
238
- * @returns {payload is WeakSet<any>}
239
- */
240
- export function isWeakSet(payload: any): payload is WeakSet<any> {
241
- return getType(payload) === 'WeakSet'
242
- }
243
-
244
- /**
245
- * Returns whether the payload is a Symbol
246
- *
247
- * @param {*} payload
248
- * @returns {payload is symbol}
249
- */
250
- export function isSymbol(payload: any): payload is symbol {
251
- return getType(payload) === 'Symbol'
252
- }
253
-
254
- /**
255
- * Returns whether the payload is a Date, and that the date is valid
256
- *
257
- * @param {*} payload
258
- * @returns {payload is Date}
259
- */
260
- export function isDate(payload: any): payload is Date {
261
- return getType(payload) === 'Date' && !isNaN(payload)
262
- }
263
-
264
- /**
265
- * Returns whether the payload is a Blob
266
- *
267
- * @param {*} payload
268
- * @returns {payload is Blob}
269
- */
270
- export function isBlob(payload: any): payload is Blob {
271
- return getType(payload) === 'Blob'
272
- }
273
-
274
- /**
275
- * Returns whether the payload is a File
276
- *
277
- * @param {*} payload
278
- * @returns {payload is File}
279
- */
280
- export function isFile(payload: any): payload is File {
281
- return getType(payload) === 'File'
282
- }
283
-
284
- /**
285
- * Returns whether the payload is a Promise
286
- *
287
- * @param {*} payload
288
- * @returns {payload is Promise<any>}
289
- */
290
- export function isPromise(payload: any): payload is Promise<any> {
291
- return getType(payload) === 'Promise'
292
- }
293
-
294
- /**
295
- * Returns whether the payload is an Error
296
- *
297
- * @param {*} payload
298
- * @returns {payload is Error}
299
- */
300
- export function isError(payload: any): payload is Error {
301
- return getType(payload) === 'Error'
302
- }
303
-
304
- /**
305
- * Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`)
306
- *
307
- * @param {*} payload
308
- * @returns {payload is typeof NaN}
309
- */
310
- export function isNaNValue(payload: any): payload is typeof NaN {
311
- return getType(payload) === 'Number' && isNaN(payload)
312
- }
313
-
314
- /**
315
- * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
316
- *
317
- * @param {*} payload
318
- * @returns {(payload is boolean | null | undefined | number | string | symbol)}
319
- */
320
- export function isPrimitive(
321
- payload: any
322
- ): payload is boolean | null | undefined | number | string | symbol {
323
- return (
324
- isBoolean(payload) ||
325
- isNull(payload) ||
326
- isUndefined(payload) ||
327
- isNumber(payload) ||
328
- isString(payload) ||
329
- isSymbol(payload)
330
- )
331
- }
332
-
333
- /**
334
- * Returns true whether the payload is null or undefined
335
- *
336
- * @param {*} payload
337
- * @returns {(payload is null | undefined)}
338
- */
339
- export const isNullOrUndefined = isOneOf(isNull, isUndefined)
340
-
341
- export function isOneOf<A, B extends A, C extends A>(
342
- a: TypeGuard<A, B>,
343
- b: TypeGuard<A, C>
344
- ): TypeGuard<A, B | C>
345
- export function isOneOf<A, B extends A, C extends A, D extends A>(
346
- a: TypeGuard<A, B>,
347
- b: TypeGuard<A, C>,
348
- c: TypeGuard<A, D>
349
- ): TypeGuard<A, B | C | D>
350
- export function isOneOf<A, B extends A, C extends A, D extends A, E extends A>(
351
- a: TypeGuard<A, B>,
352
- b: TypeGuard<A, C>,
353
- c: TypeGuard<A, D>,
354
- d: TypeGuard<A, E>
355
- ): TypeGuard<A, B | C | D | E>
356
- export function isOneOf<A, B extends A, C extends A, D extends A, E extends A, F extends A>(
357
- a: TypeGuard<A, B>,
358
- b: TypeGuard<A, C>,
359
- c: TypeGuard<A, D>,
360
- d: TypeGuard<A, E>,
361
- e: TypeGuard<A, F>
362
- ): TypeGuard<A, B | C | D | E | F>
363
- export function isOneOf(
364
- a: AnyFunction,
365
- b: AnyFunction,
366
- c?: AnyFunction,
367
- d?: AnyFunction,
368
- e?: AnyFunction
369
- ): (value: unknown) => boolean {
370
- return (value) =>
371
- a(value) || b(value) || (!!c && c(value)) || (!!d && d(value)) || (!!e && e(value))
372
- }
373
-
374
- /**
375
- * Does a generic check to check that the given payload is of a given type.
376
- * In cases like Number, it will return true for NaN as NaN is a Number (thanks javascript!);
377
- * It will, however, differentiate between object and null
378
- *
379
- * @template T
380
- * @param {*} payload
381
- * @param {T} type
382
- * @throws {TypeError} Will throw type error if type is an invalid type
383
- * @returns {payload is T}
384
- */
385
- export function isType<T extends AnyFunction | AnyClass>(payload: any, type: T): payload is T {
386
- if (!(type instanceof Function)) {
387
- throw new TypeError('Type must be a function')
388
- }
389
- if (!Object.prototype.hasOwnProperty.call(type, 'prototype')) {
390
- throw new TypeError('Type is not a class')
391
- }
392
- // Classes usually have names (as functions usually have names)
393
- const name: string | undefined | null = (type as any).name
394
- return getType(payload) === name || Boolean(payload && payload.constructor === type)
395
- }