@pdg/data 1.0.7 → 1.0.8

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/index.esm.js CHANGED
@@ -15,39 +15,7 @@ function lv(label, value, other) {
15
15
  * ******************************************************************************************************************/
16
16
  function vl(value, label, other) {
17
17
  return Object.assign(Object.assign({}, other), { value, label });
18
- }/******************************************************************************
19
- Copyright (c) Microsoft Corporation.
20
-
21
- Permission to use, copy, modify, and/or distribute this software for any
22
- purpose with or without fee is hereby granted.
23
-
24
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
25
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
26
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
27
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
28
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
29
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
30
- PERFORMANCE OF THIS SOFTWARE.
31
- ***************************************************************************** */
32
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
33
-
34
-
35
- function __rest(s, e) {
36
- var t = {};
37
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
- t[p] = s[p];
39
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
- t[p[i]] = s[p[i]];
43
- }
44
- return t;
45
- }
46
-
47
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
48
- var e = new Error(message);
49
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
50
- };/********************************************************************************************************************
18
+ }/********************************************************************************************************************
51
19
  * Types
52
20
  * ******************************************************************************************************************/
53
21
  /********************************************************************************************************************
@@ -60,15 +28,13 @@ function camelCase(str) {
60
28
  /********************************************************************************************************************
61
29
  * makeConst
62
30
  * ******************************************************************************************************************/
63
- function _makeConst(name, items) {
64
- const aliasValueMap = items.reduce((acc, item) => {
65
- if (item.length === 3) {
66
- const [value, , alias] = item;
31
+ function makeConst(items) {
32
+ const aliasValueMap = items.reduce((acc, [value, , alias]) => {
33
+ if (alias !== undefined) {
67
34
  acc[alias] = value;
68
35
  return acc;
69
36
  }
70
- else {
71
- const [value] = item;
37
+ else if (typeof value === 'string') {
72
38
  const alias = camelCase(value);
73
39
  acc[alias] = value;
74
40
  }
@@ -78,33 +44,15 @@ function _makeConst(name, items) {
78
44
  acc[value] = label;
79
45
  return acc;
80
46
  }, {});
81
- const list = items.map((item) => item[0]);
82
- const nvList = items.map((item) => ({ [name]: item[0], name: item[1] }));
83
- const lvList = items.map((item) => ({ value: item[0], label: item[1] }));
84
- return Object.assign(Object.assign({}, aliasValueMap), { getLabel(value) {
47
+ return Object.assign(Object.assign({}, aliasValueMap), { Type: undefined, getLabel(value) {
85
48
  return valueLabelMap[value];
86
49
  },
87
50
  getList() {
88
- return [...list];
89
- },
90
- getNvList() {
91
- return nvList.map((item) => (Object.assign({}, item)));
51
+ return items.map((item) => item[0]);
92
52
  },
93
53
  getLvList(extraPreItems) {
94
- return [...(extraPreItems || []), ...lvList.map((item) => (Object.assign({}, item)))];
54
+ return [...(extraPreItems || []), ...items.map((item) => ({ value: item[0], label: item[1] }))];
95
55
  } });
96
- }
97
- function makeConst(nameOrItems, itemsOrUndefined) {
98
- if (itemsOrUndefined === undefined) {
99
- const constObj = _makeConst('Unknown', nameOrItems);
100
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
101
- const { getNvList } = constObj, others = __rest(constObj, ["getNvList"]);
102
- return Object.assign(Object.assign({}, others), { Type: null });
103
- }
104
- else {
105
- const constObj = _makeConst(nameOrItems, itemsOrUndefined);
106
- return Object.assign(Object.assign({}, constObj), { Type: null });
107
- }
108
56
  }var index = {
109
57
  copy,
110
58
  lv,
package/dist/index.js CHANGED
@@ -15,39 +15,7 @@ function lv(label, value, other) {
15
15
  * ******************************************************************************************************************/
16
16
  function vl(value, label, other) {
17
17
  return Object.assign(Object.assign({}, other), { value, label });
18
- }/******************************************************************************
19
- Copyright (c) Microsoft Corporation.
20
-
21
- Permission to use, copy, modify, and/or distribute this software for any
22
- purpose with or without fee is hereby granted.
23
-
24
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
25
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
26
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
27
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
28
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
29
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
30
- PERFORMANCE OF THIS SOFTWARE.
31
- ***************************************************************************** */
32
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
33
-
34
-
35
- function __rest(s, e) {
36
- var t = {};
37
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
- t[p] = s[p];
39
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
- t[p[i]] = s[p[i]];
43
- }
44
- return t;
45
- }
46
-
47
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
48
- var e = new Error(message);
49
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
50
- };/********************************************************************************************************************
18
+ }/********************************************************************************************************************
51
19
  * Types
52
20
  * ******************************************************************************************************************/
53
21
  /********************************************************************************************************************
@@ -60,15 +28,13 @@ function camelCase(str) {
60
28
  /********************************************************************************************************************
61
29
  * makeConst
62
30
  * ******************************************************************************************************************/
63
- function _makeConst(name, items) {
64
- const aliasValueMap = items.reduce((acc, item) => {
65
- if (item.length === 3) {
66
- const [value, , alias] = item;
31
+ function makeConst(items) {
32
+ const aliasValueMap = items.reduce((acc, [value, , alias]) => {
33
+ if (alias !== undefined) {
67
34
  acc[alias] = value;
68
35
  return acc;
69
36
  }
70
- else {
71
- const [value] = item;
37
+ else if (typeof value === 'string') {
72
38
  const alias = camelCase(value);
73
39
  acc[alias] = value;
74
40
  }
@@ -78,33 +44,15 @@ function _makeConst(name, items) {
78
44
  acc[value] = label;
79
45
  return acc;
80
46
  }, {});
81
- const list = items.map((item) => item[0]);
82
- const nvList = items.map((item) => ({ [name]: item[0], name: item[1] }));
83
- const lvList = items.map((item) => ({ value: item[0], label: item[1] }));
84
- return Object.assign(Object.assign({}, aliasValueMap), { getLabel(value) {
47
+ return Object.assign(Object.assign({}, aliasValueMap), { Type: undefined, getLabel(value) {
85
48
  return valueLabelMap[value];
86
49
  },
87
50
  getList() {
88
- return [...list];
89
- },
90
- getNvList() {
91
- return nvList.map((item) => (Object.assign({}, item)));
51
+ return items.map((item) => item[0]);
92
52
  },
93
53
  getLvList(extraPreItems) {
94
- return [...(extraPreItems || []), ...lvList.map((item) => (Object.assign({}, item)))];
54
+ return [...(extraPreItems || []), ...items.map((item) => ({ value: item[0], label: item[1] }))];
95
55
  } });
96
- }
97
- function makeConst(nameOrItems, itemsOrUndefined) {
98
- if (itemsOrUndefined === undefined) {
99
- const constObj = _makeConst('Unknown', nameOrItems);
100
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
101
- const { getNvList } = constObj, others = __rest(constObj, ["getNvList"]);
102
- return Object.assign(Object.assign({}, others), { Type: null });
103
- }
104
- else {
105
- const constObj = _makeConst(nameOrItems, itemsOrUndefined);
106
- return Object.assign(Object.assign({}, constObj), { Type: null });
107
- }
108
56
  }var index = {
109
57
  copy,
110
58
  lv,
@@ -1,7 +1,9 @@
1
1
  /********************************************************************************************************************
2
2
  * Types
3
3
  * ******************************************************************************************************************/
4
- type ValueOf<T> = T[keyof T];
4
+ type Writable<T> = {
5
+ -readonly [P in keyof T]: T[P];
6
+ };
5
7
  type IsArray<T> = T extends unknown[] ? true : false;
6
8
  /********************************************************************************************************************
7
9
  * Types
@@ -18,40 +20,27 @@ type MakeAliasValueMap<Items extends TItems> = {
18
20
  type MakeValueLabelMap<Items extends TItems> = {
19
21
  [K in Items[number] as K[0]]: K[1];
20
22
  };
21
- /** MakeNameList */
22
- type MakeNameValueList<Name extends string, Items extends TItems> = Array<ValueOf<{
23
- [K in Items[number] as K[0]]: {
24
- [V in Name]: K[0];
25
- } & {
26
- label: K[1];
27
- };
28
- }>>;
29
23
  /** MakeLvList */
30
- type MakeLabelValueMap<Items extends TItems> = Items extends readonly (infer Item)[] ? Item extends readonly [infer V, infer N, any?] ? {
31
- value: V;
32
- label: N;
33
- } : never : never;
24
+ type MakeLvList<Items extends TItems> = {
25
+ [K in keyof Items]: Items[K] extends readonly [infer V, infer L, ...any[]] ? {
26
+ value: V;
27
+ label: L;
28
+ } : never;
29
+ };
34
30
  /********************************************************************************************************************
35
- * getLvList
31
+ * makeConst
36
32
  * ******************************************************************************************************************/
37
- declare function makeConst<StringValue extends string, NumberValue extends number, Label extends string, Alias extends string, const Items extends readonly (readonly [StringValue, Label])[] | readonly (readonly [StringValue | NumberValue, Label, Alias])[], AliasValueMap = MakeAliasValueMap<Items>, ValueLabelMap = MakeValueLabelMap<Items>, ValueList = Items[number][0][], LabelValueMap = MakeLabelValueMap<Items>, ValueType = Items[number][0], GetLabel = <T extends keyof ValueLabelMap>(value: T) => ValueLabelMap[T], GetList = () => ValueList, GetLvList = <LvValue extends string | number, LvLabel extends string, LvItems extends readonly {
33
+ declare function makeConst<StringValue extends string, NumberValue extends number, Label extends string, Alias extends string, const Items extends readonly (readonly [StringValue, Label])[] | readonly (readonly [StringValue | NumberValue, Label, Alias])[], AliasValueMap = MakeAliasValueMap<Items>, ValueLabelMap = MakeValueLabelMap<Items>, ValueList = Items[number][0][], ValueLabelList = MakeLvList<Items>, ValueType = Items[number][0], GetLabel = <T extends keyof ValueLabelMap>(value: T) => ValueLabelMap[T], GetList = () => ValueList, GetLvList = <LvValue extends string | number, LvLabel extends string, LvItems extends readonly {
38
34
  value: LvValue;
39
35
  label: LvLabel;
40
- }[]>(items?: LvItems) => [...ReadonlyArray<LabelValueMap>, ...(IsArray<LvItems> extends true ? LvItems : [])], Result = AliasValueMap & {
36
+ }[]>(items?: LvItems) => Writable<[
37
+ ...(ValueLabelList extends readonly any[] ? ValueLabelList : []),
38
+ ...(IsArray<LvItems> extends true ? LvItems : [])
39
+ ]>, Result = AliasValueMap & {
41
40
  Type: ValueType;
42
41
  getLabel: GetLabel;
43
42
  getList: GetList;
44
43
  getLvList: GetLvList;
45
44
  }>(items: Items): Result;
46
- declare function makeConst<Name extends string, StringValue extends string, NumberValue extends number, Label extends string, Alias extends string, const Items extends readonly (readonly [StringValue, Label])[] | readonly (readonly [StringValue | NumberValue, Label, Alias])[], AliasValueMap = MakeAliasValueMap<Items>, ValueLabelMap = MakeValueLabelMap<Items>, ValueList = Items[number][0][], NameValueList = MakeNameValueList<Name, Items>, LabelValueMap = MakeLabelValueMap<Items>, ValueType = Items[number][0], GetLabel = <T extends keyof ValueLabelMap>(value: T) => ValueLabelMap[T], GetList = () => ValueList, GetNvList = () => NameValueList, GetLvList = <LvValue extends string | number, LvLabel extends string, LvItems extends readonly {
47
- value: LvValue;
48
- label: LvLabel;
49
- }[]>(items?: LvItems) => [...ReadonlyArray<LabelValueMap>, ...(IsArray<LvItems> extends true ? LvItems : [])], Result = AliasValueMap & {
50
- Type: ValueType;
51
- getLabel: GetLabel;
52
- getList: GetList;
53
- getNvList: GetNvList;
54
- getLvList: GetLvList;
55
- }>(name: Name, items: Items): Result;
56
45
  export { makeConst };
57
46
  export default makeConst;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@pdg/data",
3
3
  "title": "Typescript Data Module",
4
4
  "description": "Typescript Data Module",
5
- "version": "1.0.7",
5
+ "version": "1.0.8",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.esm.js",