is-what 3.14.1 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # is What? 🙉
2
2
 
3
- Very simple & small JS type check functions. It's fully TypeScript supported!
3
+ <a href="https://www.npmjs.com/package/is-what"><img src="https://img.shields.io/npm/v/is-what.svg" alt="Total Downloads"></a>
4
+ <a href="https://www.npmjs.com/package/is-what"><img src="https://img.shields.io/npm/dw/is-what.svg" alt="Latest Stable Version"></a>
5
+
6
+ Very simple & small JS type check functions. It's fully TypeScript supported!
4
7
 
5
8
  ```
6
9
  npm i is-what
@@ -13,6 +16,7 @@ Or for deno available at: `"deno.land/x/is_what"`
13
16
  I built is-what because the existing solutions were all too complex or too poorly built.
14
17
 
15
18
  I was looking for:
19
+
16
20
  - A simple way to check any kind of type (including non-primitives)
17
21
  - Be able to check if an object is a plain object `{}` or a special object (like a class instance) ‼️
18
22
  - Let TypeScript automatically know what type a value is when checking
@@ -35,6 +39,12 @@ import { isString, isDate, isPlainObject } from 'is-what'
35
39
  ### Simple type check functions
36
40
 
37
41
  ```js
42
+ // basics
43
+ isBoolean(true) // true
44
+ isBoolean(false) // true
45
+ isUndefined(undefined) // true
46
+ isNull(null) // true
47
+
38
48
  // strings
39
49
  isString('') // true
40
50
  isEmptyString('') // true
@@ -42,38 +52,86 @@ isFullString('') // false
42
52
 
43
53
  // numbers
44
54
  isNumber(0) // true
45
- isNumber(NaN) // false
55
+ isNumber('0') // false
56
+ isNumber(NaN) // false *
57
+ isPositiveNumber(1) // true
58
+ isNegativeNumber(-1) // true
59
+ // * see below for special NaN use cases!
60
+
61
+ // arrays
62
+ isArray([]) // true
63
+ isEmptyArray([]) // true
64
+ isFullArray([1]) // true
65
+
66
+ // objects
67
+ isPlainObject({}) // true *
68
+ isEmptyObject({}) // true
69
+ isFullObject({ a: 1 }) // true
70
+ // * see below for special object (& class instance) use cases!
71
+
72
+ // functions
73
+ isFunction(function () {}) // true
74
+ isFunction(() => {}) // true
46
75
 
47
76
  // dates
48
77
  isDate(new Date()) // true
49
78
  isDate(new Date('invalid date')) // false
50
79
 
80
+ // maps & sets
81
+ isMap(new Map()) // true
82
+ isSet(new Set()) // true
83
+ isWeakMap(new WeakMap()) // true
84
+ isWeakSet(new WeakSet()) // true
85
+
51
86
  // others
52
- isBoolean(false) // true
53
- isFunction(function () {}) // true
54
- isArray([]) // true
55
- isUndefined(undefined) // true
56
- isNull(null) // true
57
87
  isRegExp(/\s/gi) // true
58
88
  isSymbol(Symbol()) // true
59
89
  isBlob(new Blob()) // true
60
90
  isFile(new File([''], '', { type: 'text/html' })) // true
91
+ isError(new Error('')) // true
92
+ isPromise(new Promise((resolve) => {})) // true
61
93
 
62
94
  // primitives
63
95
  isPrimitive('') // true
64
96
  // true for any of: boolean, null, undefined, number, string, symbol
65
97
  ```
66
98
 
67
- ### Getting and checking for specific types
99
+ ### Let's talk about NaN
68
100
 
69
- You can check for specific types with `getType` and `isType`:
101
+ `isNaN` is a built-in JS Function but it really makes no sense:
70
102
 
71
103
  ```js
72
- import { getType, isType } from 'is-what'
104
+ // 1)
105
+ typeof NaN === 'number' // true
106
+ // 🤔 ("not a number" is a "number"...)
73
107
 
74
- getType('') // returns 'String'
75
- // pass a Type as second param:
76
- isType('', String) // returns true
108
+ // 2)
109
+ isNaN('1') // false
110
+ // 🤔 the string '1' is not-"not a number"... so it's a number??
111
+
112
+ // 3)
113
+ isNaN('one') // true
114
+ // 🤔 'one' is NaN but `NaN === 'one'` is false...
115
+ ```
116
+
117
+ With is-what the way we treat NaN makes a little bit more sense:
118
+
119
+ ```js
120
+ import { isNumber, isNaNValue } from 'is-what'
121
+
122
+ // 1)
123
+ isNumber(NaN) // false!
124
+ // let's not treat NaN as a number
125
+
126
+ // 2)
127
+ isNaNValue('1') // false
128
+ // if it's not NaN, it's not NaN!!
129
+
130
+ // 3)
131
+ isNaNValue('one') // false
132
+ // if it's not NaN, it's not NaN!!
133
+
134
+ isNaNValue(NaN) // true
77
135
  ```
78
136
 
79
137
  ### isPlainObject vs isAnyObject
@@ -85,11 +143,11 @@ Checking for a JavaScript object can be really difficult. In JavaScript you can
85
143
 
86
144
  ```js
87
145
  // define a plain object
88
- const plainObject = {hello: 'I am a good old object.'}
146
+ const plainObject = { hello: 'I am a good old object.' }
89
147
 
90
148
  // define a special object
91
149
  class SpecialObject {
92
- constructor (somethingSpecial) {
150
+ constructor(somethingSpecial) {
93
151
  this.speciality = somethingSpecial
94
152
  }
95
153
  }
@@ -108,18 +166,30 @@ getType(specialObject) // returns 'Object'
108
166
 
109
167
  > Please note that `isPlainObject` will only return `true` for normal plain JavaScript objects.
110
168
 
169
+ ### Getting and checking for specific types
170
+
171
+ You can check for specific types with `getType` and `isType`:
172
+
173
+ ```js
174
+ import { getType, isType } from 'is-what'
175
+
176
+ getType('') // returns 'String'
177
+ // pass a Type as second param:
178
+ isType('', String) // returns true
179
+ ```
180
+
111
181
  ## TypeScript
112
182
 
113
183
  is-what makes TypeScript know the type during if statements. This means that a check returns the type of the payload for TypeScript users.
114
184
 
115
185
  ```ts
116
- function isNumber (payload: any): payload is number {
186
+ function isNumber(payload: any): payload is number {
117
187
  // return boolean
118
188
  }
119
189
  // As you can see above, all functions return a boolean for JavaScript, but pass the payload type to TypeScript.
120
190
 
121
191
  // usage example:
122
- function fn (payload: string | number): number {
192
+ function fn(payload: string | number): number {
123
193
  if (isNumber(payload)) {
124
194
  // ↑ TypeScript already knows payload is a number here!
125
195
  return payload
@@ -131,8 +201,8 @@ function fn (payload: string | number): number {
131
201
  `isPlainObject` and `isAnyObject` with TypeScript will declare the payload to be an object type with any props:
132
202
 
133
203
  ```ts
134
- function isPlainObject (payload: any): payload is {[key: string]: any}
135
- function isAnyObject (payload: any): payload is {[key: string]: any}
204
+ function isPlainObject(payload: any): payload is { [key: string]: any }
205
+ function isAnyObject(payload: any): payload is { [key: string]: any }
136
206
  // The reason to return `{[key: string]: any}` is to be able to do
137
207
  if (isPlainObject(payload) && payload.id) return payload.id
138
208
  // if isPlainObject() would return `payload is object` then it would give an error at `payload.id`
@@ -140,20 +210,34 @@ if (isPlainObject(payload) && payload.id) return payload.id
140
210
 
141
211
  ### isObjectLike
142
212
 
143
- If you want more control over which kind of objects are allowed you can use `isObjectLike<T>`:
213
+ If you want more control over what kind of interface/type is casted when checking for objects.
214
+
215
+ To cast to a specific type while checking for `isAnyObject`, can use `isObjectLike<T>`:
144
216
 
145
217
  ```ts
146
218
  import { isObjectLike } from 'is-what'
147
- // usage examples:
148
- isObjectLike<{specificKey: string}>(payload)
149
- isObjectLike<object>(payload)
150
- // you can pass a specific type for TS to check on.
219
+
220
+ const payload = { name: 'Mesqueeb' } // current type: `{ name: string }`
221
+
222
+ // Without casting:
223
+ if (isAnyObject(payload)) {
224
+ // in here `payload` is casted to: `Record<string | number | symbol, any>`
225
+ // WE LOOSE THE TYPE!
226
+ }
227
+
228
+ // With casting:
229
+ // you can pass a specific type for TS that will be casted when the function returns
230
+ if (isObjectLike<{ name: string }>(payload)) {
231
+ // in here `payload` is casted to: `{ name: string }`
232
+ }
151
233
  ```
152
234
 
235
+ Please note: this library will not actually check the shape of the object, you need to do that yourself.
236
+
153
237
  `isObjectLike<T>` works like this under the hood:
154
238
 
155
239
  ```ts
156
- function isObjectLike<T extends object> (payload: any): payload is T {
240
+ function isObjectLike<T extends object>(payload: any): payload is T {
157
241
  return isAnyObject(payload)
158
242
  }
159
243
  ```
@@ -173,16 +257,16 @@ function isObjectLike<T extends object> (payload: any): payload is T {
173
257
  It's litterally just these functions:
174
258
 
175
259
  ```js
176
- function getType (payload) {
260
+ function getType(payload) {
177
261
  return Object.prototype.toString.call(payload).slice(8, -1)
178
262
  }
179
- function isUndefined (payload) {
263
+ function isUndefined(payload) {
180
264
  return getType(payload) === 'Undefined'
181
265
  }
182
- function isString (payload) {
266
+ function isString(payload) {
183
267
  return getType(payload) === 'String'
184
268
  }
185
- function isAnyObject (payload) {
269
+ function isAnyObject(payload) {
186
270
  return getType(payload) === 'Object'
187
271
  }
188
272
  // etc...
@@ -162,6 +162,24 @@ function isEmptyString(payload) {
162
162
  function isNumber(payload) {
163
163
  return getType(payload) === 'Number' && !isNaN(payload);
164
164
  }
165
+ /**
166
+ * Returns whether the payload is a positive number (but not 0)
167
+ *
168
+ * @param {*} payload
169
+ * @returns {payload is number}
170
+ */
171
+ function isPositiveNumber(payload) {
172
+ return isNumber(payload) && payload > 0;
173
+ }
174
+ /**
175
+ * Returns whether the payload is a negative number (but not 0)
176
+ *
177
+ * @param {*} payload
178
+ * @returns {payload is number}
179
+ */
180
+ function isNegativeNumber(payload) {
181
+ return isNumber(payload) && payload < 0;
182
+ }
165
183
  /**
166
184
  * Returns whether the payload is a boolean
167
185
  *
@@ -299,11 +317,9 @@ function isPrimitive(payload) {
299
317
  * @param {*} payload
300
318
  * @returns {(payload is null | undefined)}
301
319
  */
302
- var isNullOrUndefined = isOneOf(isNull, isUndefined);
320
+ const isNullOrUndefined = isOneOf(isNull, isUndefined);
303
321
  function isOneOf(a, b, c, d, e) {
304
- return function (value) {
305
- return a(value) || b(value) || (!!c && c(value)) || (!!d && d(value)) || (!!e && e(value));
306
- };
322
+ return (value) => a(value) || b(value) || (!!c && c(value)) || (!!d && d(value)) || (!!e && e(value));
307
323
  }
308
324
  /**
309
325
  * Does a generic check to check that the given payload is of a given type.
@@ -324,7 +340,7 @@ function isType(payload, type) {
324
340
  throw new TypeError('Type is not a class');
325
341
  }
326
342
  // Classes usually have names (as functions usually have names)
327
- var name = type.name;
343
+ const name = type.name;
328
344
  return getType(payload) === name || Boolean(payload && payload.constructor === type);
329
345
  }
330
346
 
@@ -345,6 +361,7 @@ exports.isFullString = isFullString;
345
361
  exports.isFunction = isFunction;
346
362
  exports.isMap = isMap;
347
363
  exports.isNaNValue = isNaNValue;
364
+ exports.isNegativeNumber = isNegativeNumber;
348
365
  exports.isNull = isNull;
349
366
  exports.isNullOrUndefined = isNullOrUndefined;
350
367
  exports.isNumber = isNumber;
@@ -352,6 +369,7 @@ exports.isObject = isObject;
352
369
  exports.isObjectLike = isObjectLike;
353
370
  exports.isOneOf = isOneOf;
354
371
  exports.isPlainObject = isPlainObject;
372
+ exports.isPositiveNumber = isPositiveNumber;
355
373
  exports.isPrimitive = isPrimitive;
356
374
  exports.isPromise = isPromise;
357
375
  exports.isRegExp = isRegExp;
@@ -158,6 +158,24 @@ function isEmptyString(payload) {
158
158
  function isNumber(payload) {
159
159
  return getType(payload) === 'Number' && !isNaN(payload);
160
160
  }
161
+ /**
162
+ * Returns whether the payload is a positive number (but not 0)
163
+ *
164
+ * @param {*} payload
165
+ * @returns {payload is number}
166
+ */
167
+ function isPositiveNumber(payload) {
168
+ return isNumber(payload) && payload > 0;
169
+ }
170
+ /**
171
+ * Returns whether the payload is a negative number (but not 0)
172
+ *
173
+ * @param {*} payload
174
+ * @returns {payload is number}
175
+ */
176
+ function isNegativeNumber(payload) {
177
+ return isNumber(payload) && payload < 0;
178
+ }
161
179
  /**
162
180
  * Returns whether the payload is a boolean
163
181
  *
@@ -295,11 +313,9 @@ function isPrimitive(payload) {
295
313
  * @param {*} payload
296
314
  * @returns {(payload is null | undefined)}
297
315
  */
298
- var isNullOrUndefined = isOneOf(isNull, isUndefined);
316
+ const isNullOrUndefined = isOneOf(isNull, isUndefined);
299
317
  function isOneOf(a, b, c, d, e) {
300
- return function (value) {
301
- return a(value) || b(value) || (!!c && c(value)) || (!!d && d(value)) || (!!e && e(value));
302
- };
318
+ return (value) => a(value) || b(value) || (!!c && c(value)) || (!!d && d(value)) || (!!e && e(value));
303
319
  }
304
320
  /**
305
321
  * Does a generic check to check that the given payload is of a given type.
@@ -320,8 +336,8 @@ function isType(payload, type) {
320
336
  throw new TypeError('Type is not a class');
321
337
  }
322
338
  // Classes usually have names (as functions usually have names)
323
- var name = type.name;
339
+ const name = type.name;
324
340
  return getType(payload) === name || Boolean(payload && payload.constructor === type);
325
341
  }
326
342
 
327
- export { getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyArray, isEmptyObject, isEmptyString, isError, isFile, isFullArray, isFullObject, isFullString, isFunction, isMap, isNaNValue, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isOneOf, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isType, isUndefined, isWeakMap, isWeakSet };
343
+ export { getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyArray, isEmptyObject, isEmptyString, isError, isFile, isFullArray, isFullObject, isFullString, isFunction, isMap, isNaNValue, isNegativeNumber, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isOneOf, isPlainObject, isPositiveNumber, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isType, isUndefined, isWeakMap, isWeakSet };
@@ -129,6 +129,20 @@ export declare function isEmptyString(payload: any): payload is string;
129
129
  * @returns {payload is number}
130
130
  */
131
131
  export declare function isNumber(payload: any): payload is number;
132
+ /**
133
+ * Returns whether the payload is a positive number (but not 0)
134
+ *
135
+ * @param {*} payload
136
+ * @returns {payload is number}
137
+ */
138
+ export declare function isPositiveNumber(payload: any): payload is number;
139
+ /**
140
+ * Returns whether the payload is a negative number (but not 0)
141
+ *
142
+ * @param {*} payload
143
+ * @returns {payload is number}
144
+ */
145
+ export declare function isNegativeNumber(payload: any): payload is number;
132
146
  /**
133
147
  * Returns whether the payload is a boolean
134
148
  *
package/package.json CHANGED
@@ -1,19 +1,31 @@
1
1
  {
2
2
  "name": "is-what",
3
3
  "sideEffects": false,
4
- "version": "3.14.1",
4
+ "type": "module",
5
+ "version": "4.1.2",
5
6
  "description": "JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.",
6
- "main": "dist/index.cjs.js",
7
- "module": "dist/index.esm.js",
8
- "typings": "types/index.d.ts",
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
- "jest": "jest",
12
- "jest-w": "jest --watchAll",
13
- "lint": "tsc --noEmit src/index.ts && eslint . --ext .js,.jsx,.ts,.tsx",
14
- "rollup": "rollup -c ./build.js",
15
- "build": "rimraf types && rimraf dist && npm run lint && npm run rollup && npm run test && npm run jest",
16
- "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"
17
29
  },
18
30
  "repository": {
19
31
  "type": "git",
@@ -41,46 +53,63 @@
41
53
  "is-plain-object"
42
54
  ],
43
55
  "author": "Luca Ban - Mesqueeb",
56
+ "funding": "https://github.com/sponsors/mesqueeb",
44
57
  "license": "MIT",
45
58
  "bugs": {
46
59
  "url": "https://github.com/mesqueeb/is-what/issues"
47
60
  },
48
61
  "homepage": "https://github.com/mesqueeb/is-what#readme",
49
62
  "devDependencies": {
50
- "@babel/core": "^7.12.17",
51
- "@types/babel-core": "^6.25.6",
52
- "@types/jest": "^26.0.20",
53
- "@typescript-eslint/eslint-plugin": "^4.15.1",
54
- "@typescript-eslint/parser": "^4.15.1",
55
- "ava": "^3.15.0",
56
- "babel-core": "^7.0.0-bridge.0",
57
- "babel-jest": "^26.6.3",
58
- "babel-preset-env": "^1.7.0",
59
- "eslint": "^7.20.0",
60
- "eslint-config-prettier": "^7.2.0",
61
- "eslint-plugin-tree-shaking": "^1.8.0",
62
- "jest": "^26.6.3",
63
- "np": "^7.4.0",
64
- "prettier": "^2.2.1",
65
- "regenerator-runtime": "^0.13.7",
66
- "rimraf": "^3.0.2",
67
- "rollup": "^2.39.0",
68
- "rollup-plugin-typescript2": "^0.30.0",
69
- "ts-node": "^9.1.1",
70
- "tsconfig-paths": "^3.9.0",
71
- "typescript": "^4.1.5"
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"
72
75
  },
73
76
  "ava": {
74
- "extensions": [
75
- "ts"
76
- ],
77
- "require": [
78
- "tsconfig-paths/register",
79
- "ts-node/register"
77
+ "extensions": {
78
+ "ts": "module"
79
+ },
80
+ "nodeArguments": [
81
+ "--loader=ts-node/esm"
80
82
  ]
81
83
  },
82
84
  "np": {
83
85
  "yarn": false,
84
86
  "branch": "production"
87
+ },
88
+ "eslintConfig": {
89
+ "ignorePatterns": [
90
+ "node_modules",
91
+ "dist",
92
+ "scripts",
93
+ "test"
94
+ ],
95
+ "root": true,
96
+ "parser": "@typescript-eslint/parser",
97
+ "plugins": [
98
+ "@typescript-eslint",
99
+ "tree-shaking"
100
+ ],
101
+ "extends": [
102
+ "eslint:recommended",
103
+ "plugin:@typescript-eslint/eslint-recommended",
104
+ "plugin:@typescript-eslint/recommended",
105
+ "prettier"
106
+ ],
107
+ "rules": {
108
+ "@typescript-eslint/no-empty-function": "off",
109
+ "@typescript-eslint/no-explicit-any": "off",
110
+ "@typescript-eslint/ban-ts-ignore": "off",
111
+ "tree-shaking/no-side-effects-in-initialization": "error",
112
+ "@typescript-eslint/ban-ts-comment": "off"
113
+ }
85
114
  }
86
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
package/.eslintrc.js DELETED
@@ -1,18 +0,0 @@
1
- // npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier eslint-plugin-tree-shaking
2
- module.exports = {
3
- root: true,
4
- parser: '@typescript-eslint/parser',
5
- plugins: ['@typescript-eslint', 'tree-shaking'],
6
- extends: [
7
- 'eslint:recommended',
8
- 'plugin:@typescript-eslint/eslint-recommended',
9
- 'plugin:@typescript-eslint/recommended',
10
- 'prettier/@typescript-eslint',
11
- ],
12
- rules: {
13
- '@typescript-eslint/no-explicit-any': 'off',
14
- '@typescript-eslint/ban-ts-ignore': 'off',
15
- 'tree-shaking/no-side-effects-in-initialization': 'error',
16
- '@typescript-eslint/explicit-module-boundary-types': 'off'
17
- },
18
- }
@@ -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,60 +0,0 @@
1
- /* eslint-disable */
2
-
3
- // npm install rollup-plugin-typescript2 typescript --save-dev
4
- import typescript from 'rollup-plugin-typescript2'
5
- // import { terser } from 'rollup-plugin-terser'
6
- // import resolve from 'rollup-plugin-node-resolve'
7
-
8
- // ------------------------------------------------------------------------------------------
9
- // formats
10
- // ------------------------------------------------------------------------------------------
11
- // amd – Asynchronous Module Definition, used with module loaders like RequireJS
12
- // cjs – CommonJS, suitable for Node and Browserify/Webpack
13
- // esm – Keep the bundle as an ES module file
14
- // 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.)
15
- // umd – Universal Module Definition, works as amd, cjs and iife all in one
16
- // system – Native format of the SystemJS loader
17
-
18
- // ------------------------------------------------------------------------------------------
19
- // setup
20
- // ------------------------------------------------------------------------------------------
21
- const pkg = require('./package.json')
22
- const name = pkg.name
23
- const className = name.replace(/(^\w|-\w)/g, c => c.replace('-', '').toUpperCase())
24
- const external = Object.keys(pkg.dependencies || [])
25
- const plugins = [
26
- typescript({ useTsconfigDeclarationDir: true, tsconfigOverride: { exclude: ['test/**/*'] } }),
27
- ]
28
-
29
- // ------------------------------------------------------------------------------------------
30
- // Builds
31
- // ------------------------------------------------------------------------------------------
32
- function defaults (config) {
33
- // defaults
34
- const defaults = {
35
- plugins,
36
- external,
37
- }
38
- // defaults.output
39
- config.output = config.output.map(output => {
40
- return Object.assign(
41
- {
42
- sourcemap: false,
43
- name: className,
44
- exports: 'named',
45
- },
46
- output
47
- )
48
- })
49
- return Object.assign(defaults, config)
50
- }
51
-
52
- export default [
53
- defaults({
54
- input: 'src/index.ts',
55
- output: [
56
- { file: 'dist/index.cjs.js', format: 'cjs' },
57
- { file: 'dist/index.esm.js', format: 'esm' },
58
- ],
59
- }),
60
- ]