mirror of
https://github.com/pezkuwichain/pezkuwi-dev.git
synced 2026-11-01 15:01:06 +00:00
Initial rebrand: @polkadot -> @pezkuwi (3 packages)
- Package namespace: @polkadot/dev -> @pezkuwi/dev - Repository: polkadot-js/dev -> pezkuwichain/pezkuwi-dev - Author: Pezkuwi Team <team@pezkuwichain.io> Packages: - @pezkuwi/dev (build tools, linting, CI scripts) - @pezkuwi/dev-test (test runner) - @pezkuwi/dev-ts (TypeScript build) Upstream: polkadot-js/dev v0.83.3
This commit is contained in:
commit
8d28b36f9c
135 files changed
+19232
No files matched your search
@@ -0,0 +1,57 @@
|
||||
// Copyright 2017-2025 @polkadot/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`);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user