-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
483 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "nolyfill-single-file", | ||
"version": "0.0.0", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"lint": "eslint ." | ||
}, | ||
"dependencies": { | ||
"@nolyfill/shared": "workspace:*", | ||
"@nolyfill/is-array-buffer": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { uncurryThis } from '@nolyfill/shared'; | ||
// @ts-expect-error -- no types | ||
import isArrayBuffer from '@nolyfill/is-array-buffer'; | ||
|
||
const bL = uncurryThis(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength')!.get!); | ||
const is = (ab: unknown) => { | ||
if (!isArrayBuffer(ab)) return NaN; | ||
return bL(ab); | ||
}; | ||
|
||
export default is; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// @ts-expect-error -- AsyncIterator is not a real global value, just a mock | ||
const asyncIterProto = typeof AsyncIterator === 'function' ? AsyncIterator.prototype : {}; | ||
if (!(Symbol.iterator in asyncIterProto)) { | ||
asyncIterProto[Symbol.iterator] = function () { return this; }; | ||
} | ||
|
||
export default asyncIterProto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default [ | ||
'BigInt64Array', 'BigUint64Array', | ||
'Float32Array', 'Float64Array', | ||
'Int16Array', 'Int32Array', 'Int8Array', | ||
'Uint16Array', 'Uint32Array', 'Uint8Array', 'Uint8ClampedArray' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { dequal } from "dequal" | ||
|
||
const deepEqual = (a: any, b: any) => dequal(a, b); | ||
export default deepEqual; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { defineProperties as default } from '@nolyfill/shared'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
interface SetToStringTagOption { | ||
force?: boolean | ||
} | ||
|
||
const set = (object: any, value: any, options: SetToStringTagOption = {}) => { | ||
if (options.force || !Object.prototype.hasOwnProperty.call(object, Symbol.toStringTag)) { | ||
Object.defineProperty(object, Symbol.toStringTag, { | ||
configurable: true, | ||
enumerable: false, | ||
value, | ||
writable: false | ||
}); | ||
} | ||
}; | ||
|
||
export default set; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { uncurryThis } from '@nolyfill/shared'; | ||
export default uncurryThis(Object.getOwnPropertyDescriptor(Symbol.prototype, 'description')!.get!); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default Object.getOwnPropertyDescriptors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default Reflect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const hasPropertyDescriptors = () => true; | ||
hasPropertyDescriptors.hasArrayLengthDefineBug = () => false; | ||
export default hasPropertyDescriptors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const hasProto = () => true; | ||
export default hasProto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const channel = new WeakMap(); | ||
const check = (O: WeakKey, slot: string) => { | ||
if (!O || (typeof O !== 'object' && typeof O !== 'function')) { | ||
throw new TypeError('`O` is not an object'); | ||
} | ||
if (typeof slot !== 'string') { | ||
throw new TypeError('`slot` must be a string'); | ||
} | ||
}; | ||
const has = (O: WeakKey, slot: string) => { | ||
check(O, slot); | ||
const slots = channel.get(O); | ||
return !!slots && Object.prototype.hasOwnProperty.call(slots, `$${slot}`); | ||
}; | ||
const get = (O: WeakKey, slot: string) => { | ||
check(O, slot); | ||
const slots = channel.get(O); | ||
return slots && slots[`$${slot}`]; | ||
}; | ||
const set = (O: WeakKey, slot: string, V: any) => { | ||
check(O, slot); | ||
let slots = channel.get(O); | ||
if (!slots) { | ||
slots = {}; | ||
channel.set(O, slots); | ||
} | ||
slots[`$${slot}`] = V; | ||
}; | ||
const assert = (O: WeakKey, slot: string) => { | ||
check(O, slot); | ||
if (!channel.has(O)) { | ||
throw new TypeError('Side channel does not contain the given key'); | ||
} | ||
if (!has(O, slot)) { | ||
throw new TypeError(`"${slot}" is not present on "O"`); | ||
} | ||
}; | ||
module.exports = Object.freeze({ has, get, set, assert }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const isStandardArguments = (value: any) => ((value && typeof value === 'object' && Symbol.toStringTag in value) | ||
? false | ||
: Object.prototype.toString.call(value) === '[object Arguments]'); | ||
|
||
const isLegacyArguments = (value: any) => (isStandardArguments(value) | ||
? true | ||
: ( | ||
value !== null | ||
&& typeof value === 'object' | ||
&& typeof value.length === 'number' | ||
&& value.length >= 0 | ||
&& Object.prototype.toString.call(value) !== '[object Array]' | ||
&& Object.prototype.toString.call(value.callee) === '[object Function]') | ||
); | ||
// isStandardArguments.isLegacyArguments = isLegacyArguments; // for tests | ||
// eslint-disable-next-line prefer-rest-params -- detect arguments object | ||
module.exports = (function () { return isStandardArguments(arguments); }()) ? isStandardArguments : isLegacyArguments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { uncurryThis } from '@nolyfill/shared'; | ||
|
||
const bL = uncurryThis(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength')!.get!); | ||
const is = (obj: unknown): obj is ArrayBuffer => { | ||
if (!obj || typeof obj !== 'object') { | ||
return false; | ||
} | ||
try { | ||
bL(obj); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
}; | ||
|
||
export default is; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const is = (value: unknown): value is Date => { | ||
if (typeof value !== 'object' || value === null) return false; | ||
try { | ||
Date.prototype.getDay.call(value); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
|
||
export default is; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const isFnRegex = /^\s*(?:function)?\*/; | ||
// Node.js has full native support for generators since Node.js 6.4.0, so we don't need eval | ||
const GeneratorFunction = Object.getPrototypeOf(function* () {}); | ||
function isGeneratorFunction(fn: unknown): fn is Function { | ||
if (typeof fn !== 'function') return false; | ||
if (isFnRegex.test(Function.prototype.toString.call(fn))) return true; | ||
return Object.getPrototypeOf(fn) === GeneratorFunction; | ||
}; | ||
|
||
export default isGeneratorFunction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const is = (value: unknown): value is RegExp => { | ||
if (!value || (typeof value !== 'object' && typeof value !== 'function')) return false; | ||
return Object.prototype.toString.call(value) === '[object RegExp]'; | ||
}; | ||
|
||
export default is; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { uncurryThis } from '@nolyfill/shared'; | ||
|
||
const bL = uncurryThis(Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength')!.get!); | ||
const is = (obj: unknown): obj is SharedArrayBuffer => { | ||
if (!obj || typeof obj !== 'object') { | ||
return false; | ||
} | ||
try { | ||
bL(obj); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
}; | ||
|
||
export default is; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const is = (value: any): value is string => { | ||
if (typeof value === 'string') return true; | ||
if (typeof value !== 'object') return false; | ||
try { | ||
String.prototype.valueOf.call(value); | ||
return true; | ||
} catch (e) { return false; } | ||
}; | ||
|
||
export default is; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const is = (value: unknown): value is symbol => { | ||
if (typeof value === 'symbol') return true; | ||
if (Object.prototype.toString.call(value) !== '[object Symbol]') return false; | ||
try { | ||
if (typeof (value as any).valueOf() !== 'symbol') return false; | ||
return Symbol.prototype.toString.call(value).startsWith('Symbol('); | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
|
||
export default is; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const is = (value: unknown) => { | ||
if (typeof WeakRef === 'undefined') return false; | ||
if (!value || typeof value !== 'object') return false; | ||
try { | ||
WeakRef.prototype.deref.call(value); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const empty: any[] = []; | ||
// @ts-expect-error -- JS is awesome | ||
empty[Symbol.isConcatSpreadable] = true; | ||
|
||
const concat = (...args: any[]) => { | ||
for (let i = 0, l = args.length; i < l; i += 1) { | ||
const arg = args[i]; | ||
if (arg && typeof arg === 'object' && typeof arg[Symbol.isConcatSpreadable] === 'boolean') { | ||
const arr = Array.isArray(arg) ? Array.prototype.slice.call(arg) : [arg]; | ||
// @ts-expect-error -- JS is awesome | ||
arr[Symbol.isConcatSpreadable] = true; | ||
args[i] = arr; | ||
} | ||
} | ||
return Array.prototype.concat.apply(empty, args); | ||
}; | ||
|
||
export default concat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const safeRegexTest = (r: RegExp) => { | ||
if ( | ||
!r | ||
|| (typeof r !== 'object' && typeof r !== 'function') | ||
|| Object.prototype.toString.call(r) !== '[object RegExp]' | ||
) { | ||
throw new TypeError('\`regex\` must be a RegExp'); | ||
} | ||
return (s: string) => RegExp.prototype.exec.call(r, s) !== null; | ||
}; | ||
|
||
export default safeRegexTest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const create = () => { | ||
let $wm: WeakMap<any, any>, $m: Map<any, any>; | ||
|
||
const get = (key: any) => { | ||
if (key && (typeof key === 'object' || typeof key === 'function')) { | ||
if ($wm) return $wm.get(key); | ||
} else if ($m) { | ||
return $m.get(key); | ||
} | ||
return undefined; | ||
}; | ||
const set = (key: any, value: any) => { | ||
if (key && (typeof key === 'object' || typeof key === 'function')) { | ||
if (!$wm) $wm = new WeakMap(); | ||
$wm.set(key, value); | ||
} else { | ||
if (!$m) $m = new Map(); | ||
$m.set(key, value); | ||
} | ||
}; | ||
const has = (key: any) => { | ||
if (key && (typeof key === 'object' || typeof key === 'function')) { | ||
if ($wm) { | ||
return $wm.has(key); | ||
} | ||
} else if ($m) { | ||
return $m.has(key); | ||
} | ||
return false; | ||
}; | ||
const assert = (key: any) => { | ||
if (!has(key)) { | ||
throw new TypeError('Side channel does not contain the given key'); | ||
} | ||
}; | ||
return { get, set, has, assert }; | ||
}; | ||
|
||
export default create; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { uncurryThis } from '@nolyfill/shared'; | ||
|
||
export default uncurryThis(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Int8Array.prototype), 'buffer')!.get!); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { uncurryThis, TypedArrayPrototype } from '@nolyfill/shared'; | ||
|
||
const typedArrayByteLength = uncurryThis(Object.getOwnPropertyDescriptor(TypedArrayPrototype, 'byteLength')!.get!); | ||
const g = (value: unknown) => { | ||
try { | ||
return typedArrayByteLength(value); | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
|
||
export default g; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { uncurryThis, TypedArrayPrototype } from '@nolyfill/shared'; | ||
|
||
const typedArrayByteOffSet = uncurryThis(Object.getOwnPropertyDescriptor(TypedArrayPrototype, 'byteOffset')!.get!); | ||
const g = (value: unknown) => { | ||
try { | ||
return typedArrayByteOffSet(value); | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
|
||
export default g; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { uncurryThis, TypedArrayPrototype } from '@nolyfill/shared'; | ||
|
||
const typedArrayLength = uncurryThis(Object.getOwnPropertyDescriptor(TypedArrayPrototype, 'length')!.get!); | ||
const g = (value: unknown) => { | ||
try { | ||
return typedArrayLength(value); | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
|
||
export default g; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export default function unboxPrimitive(value: unknown) { | ||
if (value == null || (typeof value !== 'object' && typeof value !== 'function')) { | ||
throw new TypeError(value === null ? 'value is an unboxed primitive' : 'value is a non-boxed-primitive object'); | ||
} | ||
if (typeof value === 'string' || Object.prototype.toString.call(value) === '[object String]') { | ||
return String.prototype.toString.call(value); | ||
} | ||
if (typeof value === 'number' || Object.prototype.toString.call(value) === '[object Number]') { | ||
return Number.prototype.valueOf.call(value); | ||
} | ||
if (typeof value === 'boolean' || Object.prototype.toString.call(value) === '[object Boolean]') { | ||
return Boolean.prototype.valueOf.call(value); | ||
} | ||
if (typeof value === 'symbol' || ( | ||
Object.prototype.toString.call(value) === '[object Symbol]' | ||
&& typeof value.valueOf() === 'symbol' | ||
&& Symbol.prototype.toString.call(value).startsWith('Symbol(') | ||
)) { | ||
return Symbol.prototype.valueOf.call(value); | ||
} | ||
try { | ||
return BigInt.prototype.valueOf.call(value); | ||
} catch (_) {} | ||
throw new RangeError('unknown boxed primitive'); | ||
}; |
Oops, something went wrong.