mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 09:08:03 +00:00
chore: update to version 14.0.11 and align website URLs
This commit is contained in:
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @name objectClear
|
||||
* @summary Removes all the keys from the input object
|
||||
*/
|
||||
export declare function objectClear<T>(value: Record<string, T>): Record<string, T>;
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @name objectClear
|
||||
* @summary Removes all the keys from the input object
|
||||
*/
|
||||
export function objectClear(value) {
|
||||
const keys = Object.keys(value);
|
||||
for (let i = 0, count = keys.length; i < count; i++) {
|
||||
delete value[keys[i]];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @name objectCopy
|
||||
* @summary Creates a shallow clone of the input object
|
||||
*/
|
||||
export declare function objectCopy<T extends object>(source: T): T;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { objectSpread } from './spread.js';
|
||||
/**
|
||||
* @name objectCopy
|
||||
* @summary Creates a shallow clone of the input object
|
||||
*/
|
||||
export function objectCopy(source) {
|
||||
return objectSpread({}, source);
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
type Entries<T> = {
|
||||
[K in keyof T]: [K, T[K]];
|
||||
}[keyof T][];
|
||||
/**
|
||||
* @name objectEntries
|
||||
* @summary A version of Object.entries that is typed for TS
|
||||
*/
|
||||
export declare function objectEntries<T extends object>(obj: T): Entries<T>;
|
||||
export {};
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @name objectEntries
|
||||
* @summary A version of Object.entries that is typed for TS
|
||||
*/
|
||||
export function objectEntries(obj) {
|
||||
return Object.entries(obj);
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
export { objectClear } from './clear.js';
|
||||
export { objectCopy } from './copy.js';
|
||||
export { objectEntries } from './entries.js';
|
||||
export { objectKeys } from './keys.js';
|
||||
export { objectProperties, objectProperty } from './property.js';
|
||||
export { objectSpread } from './spread.js';
|
||||
export { objectValues } from './values.js';
|
||||
@@ -0,0 +1,7 @@
|
||||
export { objectClear } from './clear.js';
|
||||
export { objectCopy } from './copy.js';
|
||||
export { objectEntries } from './entries.js';
|
||||
export { objectKeys } from './keys.js';
|
||||
export { objectProperties, objectProperty } from './property.js';
|
||||
export { objectSpread } from './spread.js';
|
||||
export { objectValues } from './values.js';
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @name objectKeys
|
||||
* @summary A version of Object.keys that is typed for TS
|
||||
*/
|
||||
export declare function objectKeys<T extends object, K extends Extract<keyof T, string>>(value: T): K[];
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @name objectKeys
|
||||
* @summary A version of Object.keys that is typed for TS
|
||||
*/
|
||||
export function objectKeys(value) {
|
||||
return Object.keys(value);
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @name objectProperty
|
||||
* @summary Assign a get property on the input object
|
||||
*/
|
||||
export declare function objectProperty<S>(that: object, key: string, getter: (key: string, index: number, self: S) => unknown, getName?: (key: string, index: number) => string, index?: number): void;
|
||||
/**
|
||||
* @name objectProperties
|
||||
* @summary Assign get properties on the input object
|
||||
*/
|
||||
export declare function objectProperties<S>(that: object, keys: string[], getter: (key: string, index: number, self: S) => unknown, getName?: (key: string, index: number) => string): void;
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @name objectProperty
|
||||
* @summary Assign a get property on the input object
|
||||
*/
|
||||
export function objectProperty(that, key, getter, getName, index = 0) {
|
||||
const name = getName
|
||||
? getName(key, index)
|
||||
: key;
|
||||
// There are 3 approaches here -
|
||||
// - Object.prototype.hasOwnProperty.call(that, key) - this only checks the current class, i.e
|
||||
// will retuirn false if the property is set in the parent class
|
||||
// - isUndefined(...) - this may yield a false positive when the property is there, but not set.
|
||||
// Additionally, on pre-defined getters it may make a call
|
||||
// - key in that - Does not need to be combined with either of the above and checks the full chain
|
||||
if (!(name in that)) {
|
||||
Object.defineProperty(that, name, {
|
||||
enumerable: true,
|
||||
// Unlike in lazy, we always call into the upper function, i.e. this method
|
||||
// does not cache old values (it is expected to be used for dynamic values)
|
||||
get: function () {
|
||||
return getter(key, index, this);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @name objectProperties
|
||||
* @summary Assign get properties on the input object
|
||||
*/
|
||||
export function objectProperties(that, keys, getter, getName) {
|
||||
for (let i = 0, count = keys.length; i < count; i++) {
|
||||
objectProperty(that, keys[i], getter, getName, i);
|
||||
}
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* @name objectSpread
|
||||
* @summary Concats all sources into the destination
|
||||
* @description Spreads object properties while maintaining object integrity
|
||||
*/
|
||||
export declare function objectSpread<T extends object>(dest: object, ...sources: (object | undefined | null)[]): T;
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @name objectSpread
|
||||
* @summary Concats all sources into the destination
|
||||
* @description Spreads object properties while maintaining object integrity
|
||||
*/
|
||||
export function objectSpread(dest, ...sources) {
|
||||
const filterProps = new Set(['__proto__', 'constructor', 'prototype']);
|
||||
for (let i = 0, count = sources.length; i < count; i++) {
|
||||
const src = sources[i];
|
||||
if (src) {
|
||||
if (typeof src.entries === 'function') {
|
||||
for (const [key, value] of src.entries()) {
|
||||
if (!filterProps.has(key)) {
|
||||
dest[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Create a clean copy of the source object
|
||||
const sanitizedSrc = Object.create(null);
|
||||
for (const [key, value] of Object.entries(src)) {
|
||||
if (!filterProps.has(key)) {
|
||||
sanitizedSrc[key] = value;
|
||||
}
|
||||
}
|
||||
Object.assign(dest, sanitizedSrc);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @name objectValues
|
||||
* @summary A version of Object.values that is typed for TS
|
||||
*/
|
||||
export declare function objectValues<T extends object>(obj: T): T[keyof T][];
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @name objectValues
|
||||
* @summary A version of Object.values that is typed for TS
|
||||
*/
|
||||
export function objectValues(obj) {
|
||||
return Object.values(obj);
|
||||
}
|
||||
Reference in New Issue
Block a user