@alanszp/core 1.7.7 → 4.0.0

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.
@@ -1,5 +1,2 @@
1
- export declare type Assignable<Target, Source> = {
2
- [K in keyof Target & keyof Source as Source[K] extends Target[K] ? K : never]: Target[K];
3
- };
4
- export declare function assignKey<Target extends Record<string | number | symbol, unknown>, Source extends Record<string | number | symbol, unknown>, Key extends keyof Assignable<Target, Source>>(target: Target, source: Source, key: Key, defaultValue?: Assignable<Target, Source>[Key]): void;
5
- export declare function assignKeys<Target extends Record<string | number | symbol, unknown>, Source extends Record<string | number | symbol, unknown>>(target: Target, source: Source, keys: (keyof Assignable<Target, Source>)[]): void;
1
+ export declare function assignKey<CommonInterface, Key extends keyof CommonInterface>(target: CommonInterface, source: CommonInterface, key: Key, defaultValue?: CommonInterface[Key]): void;
2
+ export declare function assignKeys<CommonInterface>(target: CommonInterface, source: CommonInterface, keys: (keyof CommonInterface)[]): void;
package/dist/assignKey.js CHANGED
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assignKeys = exports.assignKey = void 0;
4
4
  function assignKey(target, source, key, defaultValue) {
5
- if (source[key]) {
5
+ if (source[key] !== undefined) {
6
6
  target[key] = source[key];
7
7
  return;
8
8
  }
9
- if (defaultValue) {
9
+ if (defaultValue !== undefined) {
10
10
  target[key] = defaultValue;
11
11
  }
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"assignKey.js","sourceRoot":"","sources":["../src/assignKey.ts"],"names":[],"mappings":";;;AAMA,SAAgB,SAAS,CAKvB,MAAc,EACd,MAAc,EACd,GAAQ,EACR,YAA8C;IAE9C,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE;QACf,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAoC,CAAC;QAC7D,OAAO;KACR;IAED,IAAI,YAAY,EAAE;QAChB,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;KAC5B;AACH,CAAC;AAlBD,8BAkBC;AAED,SAAgB,UAAU,CAIxB,MAAc,EACd,MAAc,EACd,IAA0C;IAE1C,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACnB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC;AAXD,gCAWC"}
1
+ {"version":3,"file":"assignKey.js","sourceRoot":"","sources":["../src/assignKey.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS,CACvB,MAAuB,EACvB,MAAuB,EACvB,GAAQ,EACR,YAAmC;IAEnC,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;QAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO;KACR;IAED,IAAI,YAAY,KAAK,SAAS,EAAE;QAC9B,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;KAC5B;AACH,CAAC;AAdD,8BAcC;AAED,SAAgB,UAAU,CACxB,MAAuB,EACvB,MAAuB,EACvB,IAA+B;IAE/B,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACnB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC;AARD,gCAQC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alanszp/core",
3
- "version": "1.7.7",
3
+ "version": "4.0.0",
4
4
  "description": "Alan's core TS/JS lib.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -17,5 +17,5 @@
17
17
  "build": "yarn run compile",
18
18
  "prepack": "yarn run build"
19
19
  },
20
- "gitHead": "809af8e744cf32903c4f2ab3543117a72dc92b87"
20
+ "gitHead": "a8c26eb79327b6f7a4d559e9f72dc3b374b5621a"
21
21
  }
package/src/assignKey.ts CHANGED
@@ -1,36 +1,23 @@
1
- export type Assignable<Target, Source> = {
2
- [K in keyof Target & keyof Source as Source[K] extends Target[K]
3
- ? K
4
- : never]: Target[K];
5
- };
6
-
7
- export function assignKey<
8
- Target extends Record<string | number | symbol, unknown>,
9
- Source extends Record<string | number | symbol, unknown>,
10
- Key extends keyof Assignable<Target, Source>
11
- >(
12
- target: Target,
13
- source: Source,
1
+ export function assignKey<CommonInterface, Key extends keyof CommonInterface>(
2
+ target: CommonInterface,
3
+ source: CommonInterface,
14
4
  key: Key,
15
- defaultValue?: Assignable<Target, Source>[Key]
5
+ defaultValue?: CommonInterface[Key]
16
6
  ): void {
17
- if (source[key]) {
18
- target[key] = source[key] as Assignable<Target, Source>[Key];
7
+ if (source[key] !== undefined) {
8
+ target[key] = source[key];
19
9
  return;
20
10
  }
21
11
 
22
- if (defaultValue) {
12
+ if (defaultValue !== undefined) {
23
13
  target[key] = defaultValue;
24
14
  }
25
15
  }
26
16
 
27
- export function assignKeys<
28
- Target extends Record<string | number | symbol, unknown>,
29
- Source extends Record<string | number | symbol, unknown>
30
- >(
31
- target: Target,
32
- source: Source,
33
- keys: (keyof Assignable<Target, Source>)[]
17
+ export function assignKeys<CommonInterface>(
18
+ target: CommonInterface,
19
+ source: CommonInterface,
20
+ keys: (keyof CommonInterface)[]
34
21
  ): void {
35
22
  keys.forEach((key) => {
36
23
  assignKey(target, source, key);