2024-05-03 18:31:14 +00:00
|
|
|
import { isArray } from "./TypeCheck.js";
|
2019-05-22 04:14:43 +00:00
|
|
|
|
|
|
|
// return an interface which excludes certain keys
|
|
|
|
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
|
|
|
|
|
|
/**
|
2019-09-14 20:39:18 +00:00
|
|
|
* Make the property not writable using `defineProperty`. Internal use only.
|
2019-05-22 04:14:43 +00:00
|
|
|
*/
|
|
|
|
export function readOnly(target: object, property: string | string[]): void {
|
|
|
|
if (isArray(property)) {
|
2024-05-03 18:31:14 +00:00
|
|
|
property.forEach((str) => readOnly(target, str));
|
2019-05-22 04:14:43 +00:00
|
|
|
} else {
|
|
|
|
Object.defineProperty(target, property, {
|
|
|
|
enumerable: true,
|
|
|
|
writable: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-09-14 20:39:18 +00:00
|
|
|
* Make an attribute writeable. Internal use only.
|
2019-05-22 04:14:43 +00:00
|
|
|
*/
|
|
|
|
export function writable(target: object, property: string | string[]): void {
|
|
|
|
if (isArray(property)) {
|
2024-05-03 18:31:14 +00:00
|
|
|
property.forEach((str) => writable(target, str));
|
2019-05-22 04:14:43 +00:00
|
|
|
} else {
|
|
|
|
Object.defineProperty(target, property, {
|
|
|
|
writable: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const noOp: (...args: any[]) => any = () => {
|
2019-11-03 22:42:51 +00:00
|
|
|
// no operation here!
|
2019-05-22 04:14:43 +00:00
|
|
|
};
|
2019-07-18 18:06:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursive Partial taken from here: https://stackoverflow.com/a/51365037
|
|
|
|
*/
|
|
|
|
export type RecursivePartial<T> = {
|
2024-05-03 18:31:14 +00:00
|
|
|
[P in keyof T]?: T[P] extends Array<infer U>
|
|
|
|
? Array<RecursivePartial<U>>
|
|
|
|
: T[P] extends object
|
|
|
|
? RecursivePartial<T[P]>
|
|
|
|
: T[P];
|
2019-07-18 18:06:53 +00:00
|
|
|
};
|