-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(shared): move
defineProperties
out of shared
- Loading branch information
Showing
8 changed files
with
59 additions
and
52 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 |
---|---|---|
@@ -1 +1,34 @@ | ||
export { defineProperties as default } from '@nolyfill/shared'; | ||
const defineProperty = (object: any, name: string | number | symbol, value: any, predicate: (() => boolean) | true | undefined) => { | ||
if (name in object) { | ||
if (predicate === true) { | ||
if (object[name] === value) { | ||
return; | ||
} | ||
} else if ( | ||
typeof predicate !== 'function' | ||
|| !predicate() | ||
) { | ||
return; | ||
} | ||
} | ||
Object.defineProperty(object, name, { | ||
configurable: true, | ||
enumerable: false, | ||
value, | ||
writable: true | ||
}); | ||
}; | ||
|
||
const defineProperties = <M extends object>( | ||
object: object, | ||
map: M & ThisType<any>, | ||
predicates?: Partial<Record<keyof M, () => boolean>> | ||
) => { | ||
const props: Array<keyof M> = Array.prototype.concat.call(Object.keys(map), Object.getOwnPropertySymbols(map)); | ||
for (let i = 0, l = props.length; i < l; i++) { | ||
const k = props[i]; | ||
defineProperty(object, k, map[k], predicates?.[k]); | ||
} | ||
}; | ||
|
||
export default defineProperties; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export { uncurryThis } from './uncurry-this'; | ||
export { TypedArrayPrototype } from './typed-array-prototype'; | ||
export { defineProperties } from './define-properties'; | ||
export { makeEsShim } from './make-es-shim'; | ||
export { defineEsShim } from './define-es-shim'; |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
export const TypedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype) as Uint8Array; | ||
export const TypedArrayPrototype = Object.getPrototypeOf(Int8Array.prototype) as Int8Array; |