@code-essentials/utils 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -15,6 +15,10 @@ export type RemovePrefix<Prefix extends string, T extends object> = T extends Pr
15
15
  [K in string & keyof T as K extends `${Prefix}${infer K1}` ? K1 : never]: T[K];
16
16
  };
17
17
  export declare function removePrefix<const Prefix extends string, const T extends object>(prefix: Prefix, o: T): RemovePrefix<Prefix, T>;
18
+ export type ValuesPrefixed<Prefix extends string, T extends Record<PropertyKey, string>> = {
19
+ [K in keyof T]: `${Prefix}${T[K]}`;
20
+ };
21
+ export declare function valuesPrefixed<Prefix extends string, T extends Record<PropertyKey, string>>(prefix: Prefix, values: T): ValuesPrefixed<Prefix, T>;
18
22
  export declare function assert<_Assertion extends true>(): void;
19
23
  export type Eq<A, B> = A extends B ? B extends A ? true : false : false;
20
24
  export type Extends<A, B> = A extends B ? true : false;
package/dist/types.js CHANGED
@@ -9,6 +9,9 @@ export function removePrefix(prefix, o) {
9
9
  .filter(([k]) => k.startsWith(prefix) && k.length > prefix.length)
10
10
  .map(([k, v]) => [k.substring(prefix.length), v]));
11
11
  }
12
+ export function valuesPrefixed(prefix, values) {
13
+ return Object.fromEntries(Object.entries(values).map(([k, value]) => [k, prefix + value]));
14
+ }
12
15
  export function assert() { }
13
16
  export function never() {
14
17
  throw new Error("never");
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import test from 'ava';
2
+ import { valuesPrefixed } from './types.js';
3
+ test("valuesPrefixed", t => {
4
+ const abc = {
5
+ a: '.a',
6
+ b: '.b',
7
+ c: '.c',
8
+ };
9
+ const prefix = "prefix1";
10
+ const abc_k1 = valuesPrefixed(prefix, abc);
11
+ t.deepEqual(abc_k1, {
12
+ a: `${prefix}${abc.a}`,
13
+ b: `${prefix}${abc.b}`,
14
+ c: `${prefix}${abc.c}`,
15
+ });
16
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-essentials/utils",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",