builtin-type 0.0.1 → 0.0.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/dist/index.d.mts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -1
- package/readme.md +27 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/index.d.ts
|
|
2
|
-
type BuiltinType = `undefined` | `null` | `boolean` | `number` | `bigint` | `string` | `symbol` | `Boolean` | `Number` | `String` | `Array` | `Map` | `Set` | `WeakMap` | `WeakSet` | `Function` | `GeneratorFunction` | `AsyncFunction` | `AsyncGeneratorFunction` | `Promise` | `Date` | `RegExp` | `URL` | `URLSearchParams` | `WeakRef` | `FinalizationRegistry` | `ArrayBuffer` | `SharedArrayBuffer` | `Buffer` | `Int8Array` | `Uint8Array` | `Uint8ClampedArray` | `Int16Array` | `Uint16Array` | `Int32Array` | `Uint32Array` | `BigInt64Array` | `BigUint64Array` | `Float16Array` | `Float32Array` | `Float64Array` | `DataView` | `Object`;
|
|
2
|
+
type BuiltinType = `undefined` | `null` | `boolean` | `number` | `bigint` | `string` | `symbol` | `Boolean` | `Number` | `String` | `Array` | `Map` | `Set` | `WeakMap` | `WeakSet` | `Function` | `GeneratorFunction` | `AsyncFunction` | `AsyncGeneratorFunction` | `Promise` | `Date` | `RegExp` | `URL` | `URLSearchParams` | `WeakRef` | `FinalizationRegistry` | `ArrayBuffer` | `SharedArrayBuffer` | `Buffer` | `Int8Array` | `Uint8Array` | `Uint8ClampedArray` | `Int16Array` | `Uint16Array` | `Int32Array` | `Uint32Array` | `BigInt64Array` | `BigUint64Array` | `Float16Array` | `Float32Array` | `Float64Array` | `DataView` | `Temporal.Duration` | `Temporal.Instant` | `Temporal.PlainDate` | `Temporal.PlainDateTime` | `Temporal.PlainMonthDay` | `Temporal.PlainTime` | `Temporal.PlainYearMonth` | `Temporal.ZonedDateTime` | `Object`;
|
|
3
3
|
declare const builtinType: (value: unknown) => BuiltinType;
|
|
4
4
|
//#endregion
|
|
5
5
|
export { BuiltinType, builtinType as default };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let e=e=>{if(e===null)return`null`;let n=typeof e;if(n==`object`){for(let n of t){let t=n(e);if(t)return t}return`Object`}if(n==`function`){let t=Function.prototype.toString.call(e),n=t.slice(0,t.indexOf(`(`));return`${n.includes(`async`)?`Async`:``}${n.includes(`*`)?`Generator`:``}Function`}return n},t=[...[[`Array`,`isArray`],[`Buffer`,`isBuffer`]].flatMap(([e,t])=>{let n=globalThis[e];if(!n)return[];let r=n[t];return t=>r(t)?e:void 0}),...[[`Boolean`,`valueOf`],[`Number`,`valueOf`],[`String`,`valueOf`],[`Map`,`has`],[`Set`,`has`],[`WeakMap`,`has`],[`WeakSet`,`has`],[`WeakRef`,`deref`],[`Promise`,`then`],[`Date`,`getDay`],[`RegExp`,`global`],[`URL`,`href`],[`URLSearchParams`,`size`],[`ArrayBuffer`,`byteLength`],[`SharedArrayBuffer`,`byteLength`],[`DataView`,`buffer`],[`FinalizationRegistry`,`unregister`,[{}]]].flatMap(([e,t,n=[]])=>{let r,i=
|
|
1
|
+
let e=e=>{if(e===null)return`null`;let n=typeof e;if(n==`object`){for(let n of t){let t=n(e);if(t)return t}return`Object`}if(n==`function`){let t=Function.prototype.toString.call(e),n=t.slice(0,t.indexOf(`(`));return`${n.includes(`async`)?`Async`:``}${n.includes(`*`)?`Generator`:``}Function`}return n},t=[...[[`Array`,`isArray`],[`Buffer`,`isBuffer`]].flatMap(([e,t])=>{let n=globalThis[e];if(!n)return[];let r=n[t];return t=>r(t)?e:void 0}),...[[`Boolean`,`valueOf`],[`Number`,`valueOf`],[`String`,`valueOf`],[`Map`,`has`],[`Set`,`has`],[`WeakMap`,`has`],[`WeakSet`,`has`],[`WeakRef`,`deref`],[`Promise`,`then`],[`Date`,`getDay`],[`RegExp`,`global`],[`URL`,`href`],[`URLSearchParams`,`size`],[`ArrayBuffer`,`byteLength`],[`SharedArrayBuffer`,`byteLength`],[`DataView`,`buffer`],[`FinalizationRegistry`,`unregister`,[{}]],[`Temporal.ZonedDateTime`,`timeZoneId`],[`Temporal.Instant`,`epochNanoseconds`],[`Temporal.PlainDateTime`,`year`],[`Temporal.PlainDate`,`year`],[`Temporal.PlainTime`,`hour`],[`Temporal.PlainYearMonth`,`year`],[`Temporal.PlainMonthDay`,`monthCode`],[`Temporal.Duration`,`sign`]].flatMap(([e,t,n=[]])=>{let r,i=e.split(`.`).reduce((e,t)=>e?.[t],globalThis)?.prototype;if(!i)return[];do{if(r=Object.getOwnPropertyDescriptor(i,t),r)break;i=Object.getPrototypeOf(i)}while(i);if(!r)return[];let a=r.value??r.get;return t=>{try{return a.apply(t,n)==null?void 0:e}catch{return}}})],n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag)?.get;n&&t.push(e=>n.call(e));export{e as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "builtin-type",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Tomer Aberbach",
|
|
6
6
|
"email": "tomer@aberba.ch",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"prettier": "@tomer/prettier-config",
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@fast-check/vitest": "^0.3.0",
|
|
45
|
+
"@js-temporal/polyfill": "^0.5.1",
|
|
45
46
|
"@rollup/plugin-terser": "^1.0.0",
|
|
46
47
|
"@tomer/eslint-config": "^4.6.1",
|
|
47
48
|
"@tomer/prettier-config": "^4.0.0",
|
package/readme.md
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
- **Robust:** Works
|
|
31
31
|
[cross-realm](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms)
|
|
32
32
|
- **Secure:** Resilient to spoofing
|
|
33
|
-
- **Tiny:** One
|
|
33
|
+
- **Tiny:** One 0.76 kB gzipped package instead of
|
|
34
34
|
[`which-builtin-type`'s 10.5 kB gzipped total size](https://bundlejs.com/?q=which-builtin-type%401.2.1)
|
|
35
35
|
with [50 dependencies](https://npmgraph.js.org/?q=which-builtin-type#zoom=w)
|
|
36
36
|
|
|
@@ -115,6 +115,32 @@ assert.equal(builtinType(new Float16Array()), `Float16Array`)
|
|
|
115
115
|
assert.equal(builtinType(new Float32Array()), `Float32Array`)
|
|
116
116
|
assert.equal(builtinType(new Float64Array()), `Float64Array`)
|
|
117
117
|
assert.equal(builtinType(new DataView(new ArrayBuffer())), `DataView`)
|
|
118
|
+
assert.equal(builtinType(new Temporal.Duration()), `Temporal.Duration`)
|
|
119
|
+
assert.equal(
|
|
120
|
+
builtinType(Temporal.Instant.fromEpochMilliseconds(0)),
|
|
121
|
+
`Temporal.Instant`,
|
|
122
|
+
)
|
|
123
|
+
assert.equal(
|
|
124
|
+
builtinType(new Temporal.PlainDate(2024, 1, 15)),
|
|
125
|
+
`Temporal.PlainDate`,
|
|
126
|
+
)
|
|
127
|
+
assert.equal(
|
|
128
|
+
builtinType(new Temporal.PlainDateTime(2024, 1, 15, 12)),
|
|
129
|
+
`Temporal.PlainDateTime`,
|
|
130
|
+
)
|
|
131
|
+
assert.equal(
|
|
132
|
+
builtinType(new Temporal.PlainMonthDay(1, 15)),
|
|
133
|
+
`Temporal.PlainMonthDay`,
|
|
134
|
+
)
|
|
135
|
+
assert.equal(builtinType(new Temporal.PlainTime(12)), `Temporal.PlainTime`)
|
|
136
|
+
assert.equal(
|
|
137
|
+
builtinType(new Temporal.PlainYearMonth(2024, 1)),
|
|
138
|
+
`Temporal.PlainYearMonth`,
|
|
139
|
+
)
|
|
140
|
+
assert.equal(
|
|
141
|
+
builtinType(new Temporal.ZonedDateTime(0n, `UTC`)),
|
|
142
|
+
`Temporal.ZonedDateTime`,
|
|
143
|
+
)
|
|
118
144
|
assert.equal(builtinType({}), `Object`)
|
|
119
145
|
```
|
|
120
146
|
|