mirror of
https://github.com/pezkuwichain/pezkuwi-dev.git
synced 2026-11-01 06:59:48 +00:00
- Updated all copyright headers from 2025 to 2026 (system date shows 2026)
- Added build output files to eslint ignore list in packages/dev/config/eslint.js
- Added build output patterns to .gitignore
- Ignored: packages/*/*.{d.ts,js,mjs,cjs}, packages/*/cjs/**, packages/*/env/**,
packages/*/rootJs/**, packages/*/rootStatic/**
- Successfully resolved 521 lint errors by properly ignoring generated files
- Build outputs should not be linted (source files are linted instead)
- Lint and build now pass successfully
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/dev-test authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { BaseFn, BaseObj, StubFn } from './types.js';
|
|
|
|
/**
|
|
* Extends an existing object with the additional function if they
|
|
* are not already existing.
|
|
*/
|
|
export function enhanceObj <T extends BaseObj | BaseFn, X> (obj: T, extra: X) {
|
|
Object
|
|
.entries(extra as Record<string, unknown>)
|
|
.forEach(([key, value]) => {
|
|
(obj as Record<string, unknown>)[key] ??= value;
|
|
});
|
|
|
|
return obj as T & Omit<X, keyof T>;
|
|
}
|
|
|
|
/**
|
|
* @internal
|
|
*
|
|
* A helper to create a stub object based wite the stub creator supplied
|
|
*/
|
|
function createStub <N extends readonly string[]> (keys: N, creator: (key: string) => StubFn) {
|
|
return keys.reduce<Record<string, StubFn>>((obj, key) => {
|
|
obj[key] ??= creator(key);
|
|
|
|
return obj;
|
|
}, {}) as unknown as { [K in N[number]]: StubFn };
|
|
}
|
|
|
|
/**
|
|
* Extends a given object with the named functions if they do not
|
|
* already exist on the object.
|
|
*
|
|
* @type {StubObjFn}
|
|
*/
|
|
export function stubObj <N extends readonly string[]> (objName: string, keys: N, alts?: Record<string, string>) {
|
|
return createStub(keys, (key) => () => {
|
|
const alt = alts?.[key];
|
|
|
|
throw new Error(`${objName}.${key} has not been implemented${alt ? ` (Use ${alt} instead)` : ''}`);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Extends a given object with the named functions if they do not
|
|
* already exist on the object.
|
|
*
|
|
* @type {StubObjFn}
|
|
*/
|
|
export function warnObj <N extends readonly string[]> (objName: string, keys: N) {
|
|
return createStub(keys, (key) => () => {
|
|
console.warn(`${objName}.${key} has been implemented as a noop`);
|
|
});
|
|
}
|