@code-essentials/utils 1.0.8 → 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
@@ -4,6 +4,7 @@ export type Deleteable<T, K extends keyof T = keyof T> = {
4
4
  export type PartlyDeleteable<T, K extends keyof T> = {
5
5
  [K1 in keyof T as (K1 extends K ? never : K1)]: T[K1];
6
6
  } & Deleteable<T, K>;
7
+ export type PartiallyPartial<T, K extends keyof T> = Omit<T, K> & Deleteable<Pick<T, K>>;
7
8
  export type UndefinedIf<T, Condition extends boolean = boolean> = Condition extends true ? undefined : T;
8
9
  export declare function undefinedIf<T, Condition extends boolean = boolean>(condition: Condition, item: () => T): UndefinedIf<T, Condition>;
9
10
  export type Prefixed<Prefix extends string, T extends object> = {
@@ -14,6 +15,10 @@ export type RemovePrefix<Prefix extends string, T extends object> = T extends Pr
14
15
  [K in string & keyof T as K extends `${Prefix}${infer K1}` ? K1 : never]: T[K];
15
16
  };
16
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>;
17
22
  export declare function assert<_Assertion extends true>(): void;
18
23
  export type Eq<A, B> = A extends B ? B extends A ? true : false : false;
19
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,12 +1,12 @@
1
1
  {
2
2
  "name": "@code-essentials/utils",
3
- "version": "1.0.8",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "files": [
9
- "dist/**/*"
9
+ "dist"
10
10
  ],
11
11
  "devDependencies": {
12
12
  "@ava/typescript": "^6.0.0",