@alanszp/core 3.0.0 → 4.0.13

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.
@@ -0,0 +1,2 @@
1
+ export * from "./keepOrUpdate";
2
+ export * from "./types";
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./keepOrUpdate"), exports);
14
+ __exportStar(require("./types"), exports);
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/editable/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA+B;AAC/B,0CAAwB"}
@@ -0,0 +1,3 @@
1
+ import { EditableAndNullableField } from "./types";
2
+ export declare function keepOrUpdate<FieldType extends unknown, EditionType extends unknown>(defined: FieldType, value: EditableAndNullableField<EditionType>, formatter?: (value: EditionType) => FieldType): FieldType | null;
3
+ export declare function keepOrUpdateAsync<FieldType extends unknown, EditionType extends unknown>(defined: FieldType, value: EditableAndNullableField<EditionType>, formatter?: (value: EditionType) => Promise<FieldType>): Promise<FieldType | null>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keepOrUpdateAsync = exports.keepOrUpdate = void 0;
4
+ function id(param) {
5
+ return param;
6
+ }
7
+ function idAsync(param) {
8
+ return param;
9
+ }
10
+ function keepOrUpdate(defined, value, formatter = id) {
11
+ if (value === undefined)
12
+ return defined;
13
+ if (value === null)
14
+ return null;
15
+ return formatter(value);
16
+ }
17
+ exports.keepOrUpdate = keepOrUpdate;
18
+ function keepOrUpdateAsync(defined, value, formatter = idAsync) {
19
+ if (value === undefined)
20
+ return Promise.resolve(defined);
21
+ if (value === null)
22
+ return Promise.resolve(null);
23
+ return formatter(value);
24
+ }
25
+ exports.keepOrUpdateAsync = keepOrUpdateAsync;
26
+ //# sourceMappingURL=keepOrUpdate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keepOrUpdate.js","sourceRoot":"","sources":["../../src/editable/keepOrUpdate.ts"],"names":[],"mappings":";;;AAEA,SAAS,EAAE,CACT,KAAkB;IAElB,OAAO,KAAkB,CAAC;AAC5B,CAAC;AACD,SAAS,OAAO,CACd,KAAkB;IAElB,OAAO,KAA2B,CAAC;AACrC,CAAC;AAED,SAAgB,YAAY,CAI1B,OAAkB,EAClB,KAA4C,EAC5C,YAA+C,EAAE;IAEjD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IAExC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAEhC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAbD,oCAaC;AAED,SAAgB,iBAAiB,CAI/B,OAAkB,EAClB,KAA4C,EAC5C,YAAwD,OAAO;IAE/D,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAbD,8CAaC"}
@@ -0,0 +1,6 @@
1
+ export declare type JustEditableField<T> = T | undefined;
2
+ export declare type EditableAndNullableField<T> = T | undefined | null;
3
+ export declare type EditableField<T> = T extends undefined | null ? EditableAndNullableField<T> : JustEditableField<T>;
4
+ export declare type EditableObject<T> = {
5
+ [key in keyof T]: EditableField<T[key]>;
6
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/editable/types.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./assignKey";
2
2
  export * from "./lists";
3
+ export * from "./editable";
package/dist/index.js CHANGED
@@ -12,4 +12,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./assignKey"), exports);
14
14
  __exportStar(require("./lists"), exports);
15
+ __exportStar(require("./editable"), exports);
15
16
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0CAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0CAAwB;AACxB,6CAA2B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alanszp/core",
3
- "version": "3.0.0",
3
+ "version": "4.0.13",
4
4
  "description": "Alan's core TS/JS lib.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -15,7 +15,8 @@
15
15
  "compile": "rm -rf ./dist && tsc --declaration",
16
16
  "compile-watch": "tsc -w",
17
17
  "build": "yarn run compile",
18
- "prepack": "yarn run build"
18
+ "prepack": "yarn run build",
19
+ "yalc-publish": "yarn run yalc publish"
19
20
  },
20
- "gitHead": "c91e0b28a18aae2eb9db90a4348e1b021dc2cbbb"
21
+ "gitHead": "71a7bfa562fe5cfc52262f6bb4cadd6b977c6a4c"
21
22
  }
@@ -0,0 +1,2 @@
1
+ export * from "./keepOrUpdate";
2
+ export * from "./types";
@@ -0,0 +1,42 @@
1
+ import { EditableAndNullableField, JustEditableField } from "./types";
2
+
3
+ function id<FieldType extends unknown, EditionType extends unknown>(
4
+ param: EditionType
5
+ ): FieldType {
6
+ return param as FieldType;
7
+ }
8
+ function idAsync<FieldType extends unknown, EditionType extends unknown>(
9
+ param: EditionType
10
+ ): Promise<FieldType> {
11
+ return param as Promise<FieldType>;
12
+ }
13
+
14
+ export function keepOrUpdate<
15
+ FieldType extends unknown,
16
+ EditionType extends unknown
17
+ >(
18
+ defined: FieldType,
19
+ value: EditableAndNullableField<EditionType>,
20
+ formatter: (value: EditionType) => FieldType = id
21
+ ): FieldType | null {
22
+ if (value === undefined) return defined;
23
+
24
+ if (value === null) return null;
25
+
26
+ return formatter(value);
27
+ }
28
+
29
+ export function keepOrUpdateAsync<
30
+ FieldType extends unknown,
31
+ EditionType extends unknown
32
+ >(
33
+ defined: FieldType,
34
+ value: EditableAndNullableField<EditionType>,
35
+ formatter: (value: EditionType) => Promise<FieldType> = idAsync
36
+ ): Promise<FieldType | null> {
37
+ if (value === undefined) return Promise.resolve(defined);
38
+
39
+ if (value === null) return Promise.resolve(null);
40
+
41
+ return formatter(value);
42
+ }
@@ -0,0 +1,11 @@
1
+ export type JustEditableField<T> = T | undefined;
2
+
3
+ export type EditableAndNullableField<T> = T | undefined | null;
4
+
5
+ export type EditableField<T> = T extends undefined | null
6
+ ? EditableAndNullableField<T>
7
+ : JustEditableField<T>;
8
+
9
+ export type EditableObject<T> = {
10
+ [key in keyof T]: EditableField<T[key]>;
11
+ };
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./assignKey";
2
2
  export * from "./lists";
3
+ export * from "./editable";