@wener/common 1.0.4 → 2.0.1

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.
Files changed (151) hide show
  1. package/lib/cn/DivisionCode.js +55 -32
  2. package/lib/cn/DivisionCode.test.js +140 -0
  3. package/lib/cn/Mod11Checksum.js +80 -37
  4. package/lib/cn/Mod31Checksum.js +89 -40
  5. package/lib/cn/ResidentIdentityCardNumber.js +16 -16
  6. package/lib/cn/ResidentIdentityCardNumber.test.js +21 -0
  7. package/lib/cn/UnifiedSocialCreditCode.js +32 -26
  8. package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
  9. package/lib/cn/formatDate.js +5 -7
  10. package/lib/cn/index.js +0 -1
  11. package/lib/cn/parseSex.js +0 -2
  12. package/lib/cn/types.d.js +0 -2
  13. package/lib/consola/createStandardConsolaReporter.js +18 -0
  14. package/lib/consola/formatLogObject.js +226 -0
  15. package/lib/consola/index.js +2 -0
  16. package/lib/data/formatSort.js +5 -6
  17. package/lib/data/formatSort.test.js +34 -0
  18. package/lib/data/index.js +0 -1
  19. package/lib/data/maybeNumber.js +11 -5
  20. package/lib/data/parseSort.js +28 -22
  21. package/lib/data/parseSort.test.js +188 -0
  22. package/lib/data/resolvePagination.js +27 -16
  23. package/lib/data/resolvePagination.test.js +232 -0
  24. package/lib/data/types.d.js +0 -2
  25. package/lib/index.js +0 -1
  26. package/lib/jsonschema/JsonSchema.js +80 -54
  27. package/lib/jsonschema/JsonSchema.test.js +137 -0
  28. package/lib/jsonschema/index.js +0 -1
  29. package/lib/jsonschema/types.d.js +5 -3
  30. package/lib/meta/defineFileType.js +103 -20
  31. package/lib/meta/defineInit.js +250 -31
  32. package/lib/meta/defineMetadata.js +140 -24
  33. package/lib/meta/defineMetadata.test.js +13 -0
  34. package/lib/meta/index.js +0 -1
  35. package/lib/password/PHC.js +87 -63
  36. package/lib/password/PHC.test.js +539 -0
  37. package/lib/password/Password.js +291 -29
  38. package/lib/password/Password.test.js +362 -0
  39. package/lib/password/createArgon2PasswordAlgorithm.js +191 -35
  40. package/lib/password/createBase64PasswordAlgorithm.js +141 -8
  41. package/lib/password/createBcryptPasswordAlgorithm.js +168 -13
  42. package/lib/password/createPBKDF2PasswordAlgorithm.js +228 -46
  43. package/lib/password/createScryptPasswordAlgorithm.js +211 -55
  44. package/lib/password/index.js +0 -1
  45. package/lib/password/server/index.js +0 -1
  46. package/lib/resource/Identifiable.js +1 -0
  47. package/lib/resource/getTitleOfResource.js +10 -0
  48. package/lib/resource/index.js +1 -0
  49. package/lib/resource/schema/AnyResourceSchema.js +89 -0
  50. package/lib/resource/schema/BaseResourceSchema.js +29 -0
  51. package/lib/resource/schema/ResourceActionType.js +118 -0
  52. package/lib/resource/schema/ResourceStatus.js +93 -0
  53. package/lib/resource/schema/ResourceType.js +24 -0
  54. package/lib/resource/schema/SchemaRegistry.js +38 -0
  55. package/lib/resource/schema/SexType.js +10 -0
  56. package/lib/resource/schema/types.js +89 -0
  57. package/lib/resource/schema/types.test.js +14 -0
  58. package/lib/schema/TypeSchema.d.js +1 -0
  59. package/lib/schema/createSchemaData.js +173 -0
  60. package/lib/schema/findJsonSchemaByPath.js +49 -0
  61. package/lib/schema/getSchemaCache.js +11 -0
  62. package/lib/schema/getSchemaOptions.js +24 -0
  63. package/lib/schema/index.js +5 -0
  64. package/lib/schema/toJsonSchema.js +441 -0
  65. package/lib/schema/toJsonSchema.test.js +27 -0
  66. package/lib/schema/validate.js +124 -0
  67. package/lib/search/AdvanceSearch.js +0 -1
  68. package/lib/search/AdvanceSearch.test.js +435 -0
  69. package/lib/search/formatAdvanceSearch.js +41 -27
  70. package/lib/search/index.js +0 -1
  71. package/lib/search/optimizeAdvanceSearch.js +79 -25
  72. package/lib/search/parseAdvanceSearch.js +5 -5
  73. package/lib/search/parser.d.js +0 -2
  74. package/lib/search/parser.js +97 -74
  75. package/lib/search/types.d.js +0 -2
  76. package/lib/tools/generateSchema.js +201 -0
  77. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
  78. package/package.json +30 -9
  79. package/src/consola/createStandardConsolaReporter.ts +31 -0
  80. package/src/consola/formatLogObject.ts +171 -0
  81. package/src/consola/index.ts +2 -0
  82. package/src/data/maybeNumber.ts +5 -1
  83. package/src/data/resolvePagination.test.ts +1 -1
  84. package/src/data/resolvePagination.ts +18 -7
  85. package/src/data/types.d.ts +12 -0
  86. package/src/jsonschema/JsonSchema.test.ts +17 -0
  87. package/src/jsonschema/JsonSchema.ts +4 -4
  88. package/src/jsonschema/types.d.ts +63 -12
  89. package/src/resource/Identifiable.ts +3 -0
  90. package/src/resource/getTitleOfResource.tsx +6 -0
  91. package/src/resource/index.ts +3 -0
  92. package/src/resource/schema/AnyResourceSchema.ts +113 -0
  93. package/src/resource/schema/BaseResourceSchema.ts +32 -0
  94. package/src/resource/schema/ResourceActionType.ts +123 -0
  95. package/src/resource/schema/ResourceStatus.ts +94 -0
  96. package/src/resource/schema/ResourceType.ts +25 -0
  97. package/src/resource/schema/SchemaRegistry.ts +42 -0
  98. package/src/resource/schema/SexType.ts +13 -0
  99. package/src/resource/schema/types.test.ts +18 -0
  100. package/src/resource/schema/types.ts +105 -0
  101. package/src/schema/TypeSchema.d.ts +32 -0
  102. package/src/schema/createSchemaData.ts +81 -0
  103. package/src/schema/findJsonSchemaByPath.ts +37 -0
  104. package/src/schema/getSchemaCache.ts +21 -0
  105. package/src/schema/getSchemaOptions.ts +24 -0
  106. package/src/schema/index.ts +6 -0
  107. package/src/schema/toJsonSchema.test.ts +37 -0
  108. package/src/schema/toJsonSchema.ts +200 -0
  109. package/src/schema/validate.ts +135 -0
  110. package/src/tools/generateSchema.ts +39 -0
  111. package/lib/cn/DivisionCode.js.map +0 -1
  112. package/lib/cn/Mod11Checksum.js.map +0 -1
  113. package/lib/cn/Mod31Checksum.js.map +0 -1
  114. package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
  115. package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
  116. package/lib/cn/formatDate.js.map +0 -1
  117. package/lib/cn/index.js.map +0 -1
  118. package/lib/cn/parseSex.js.map +0 -1
  119. package/lib/cn/types.d.js.map +0 -1
  120. package/lib/data/formatSort.js.map +0 -1
  121. package/lib/data/index.js.map +0 -1
  122. package/lib/data/maybeNumber.js.map +0 -1
  123. package/lib/data/parseSort.js.map +0 -1
  124. package/lib/data/resolvePagination.js.map +0 -1
  125. package/lib/data/types.d.js.map +0 -1
  126. package/lib/index.js.map +0 -1
  127. package/lib/jsonschema/JsonSchema.js.map +0 -1
  128. package/lib/jsonschema/index.js.map +0 -1
  129. package/lib/jsonschema/types.d.js.map +0 -1
  130. package/lib/meta/defineFileType.js.map +0 -1
  131. package/lib/meta/defineInit.js.map +0 -1
  132. package/lib/meta/defineMetadata.js.map +0 -1
  133. package/lib/meta/index.js.map +0 -1
  134. package/lib/password/PHC.js.map +0 -1
  135. package/lib/password/Password.js.map +0 -1
  136. package/lib/password/createArgon2PasswordAlgorithm.js.map +0 -1
  137. package/lib/password/createBase64PasswordAlgorithm.js.map +0 -1
  138. package/lib/password/createBcryptPasswordAlgorithm.js.map +0 -1
  139. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +0 -1
  140. package/lib/password/createScryptPasswordAlgorithm.js.map +0 -1
  141. package/lib/password/index.js.map +0 -1
  142. package/lib/password/server/index.js.map +0 -1
  143. package/lib/search/AdvanceSearch.js.map +0 -1
  144. package/lib/search/formatAdvanceSearch.js.map +0 -1
  145. package/lib/search/index.js.map +0 -1
  146. package/lib/search/optimizeAdvanceSearch.js.map +0 -1
  147. package/lib/search/parseAdvanceSearch.js.map +0 -1
  148. package/lib/search/parser.d.js.map +0 -1
  149. package/lib/search/parser.js.map +0 -1
  150. package/lib/search/types.d.js.map +0 -1
  151. package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +0 -1
@@ -1,17 +1,18 @@
1
- import Ajv from "ajv";
2
- import addFormats from "ajv-formats";
3
- import localize from "ajv-i18n/localize/zh";
4
- import addKeywords from "ajv-keywords";
5
- import { isNil } from "es-toolkit";
6
- import { match, P } from "ts-pattern";
1
+ import Ajv from 'ajv';
2
+ import addFormats from 'ajv-formats';
3
+ // import localize from 'ajv-i18n/localize/zh';
4
+ import addKeywords from 'ajv-keywords';
5
+ import { isNil } from 'es-toolkit';
6
+ import { match, P } from 'ts-pattern';
7
7
  function _createAjv(opt) {
8
- const ajv = new Ajv(opt);
8
+ var ajv = new Ajv(opt);
9
9
  addKeywords(ajv);
10
10
  addFormats(ajv);
11
11
  return ajv;
12
12
  }
13
- function validate({ schema, data, mutate, clone, ajv }) {
14
- let opts = {
13
+ function validate(param) {
14
+ var schema = param.schema, data = param.data, mutate = param.mutate, clone = param.clone, ajv = param.ajv;
15
+ var opts = {
15
16
  // strict: 'log',
16
17
  strict: true,
17
18
  strictSchema: 'log'
@@ -30,13 +31,13 @@ function validate({ schema, data, mutate, clone, ajv }) {
30
31
  if (!ajv) {
31
32
  ajv = JsonSchema.createAjv(opts);
32
33
  }
33
- const validate = ajv.compile(schema);
34
+ var validate = ajv.compile(schema);
34
35
  // consider reusing validate instance
35
- const valid = validate(data);
36
- const errors = validate.errors;
37
- localize(errors);
36
+ var valid = validate(data);
37
+ var errors = validate.errors;
38
+ // localize(errors);
38
39
  return {
39
- data,
40
+ data: data,
40
41
  success: valid,
41
42
  message: ajv.errorsText(errors),
42
43
  errors: errors
@@ -45,22 +46,29 @@ function validate({ schema, data, mutate, clone, ajv }) {
45
46
  (function(JsonSchema) {
46
47
  JsonSchema.schemas = [];
47
48
  JsonSchema.createAjv = _createAjv;
48
- function addSchema(schema, { onConflict = 'throw' } = {}) {
49
+ function addSchema(schema) {
50
+ var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, _ref_onConflict = _ref.onConflict, onConflict = _ref_onConflict === void 0 ? 'throw' : _ref_onConflict;
49
51
  if (!schema.$id) throw new Error('Schema must have $id');
50
52
  switch(onConflict){
51
53
  case 'ignore':
52
- onConflict = (old)=>old;
54
+ onConflict = function(old) {
55
+ return old;
56
+ };
53
57
  break;
54
58
  case 'replace':
55
- onConflict = (_, neo)=>neo;
59
+ onConflict = function(_, neo) {
60
+ return neo;
61
+ };
56
62
  break;
57
63
  case 'throw':
58
- onConflict = (old, neo)=>{
59
- throw new Error(`Schema ${neo.$id} already exists`);
64
+ onConflict = function(old, neo) {
65
+ throw new Error("Schema ".concat(neo.$id, " already exists"));
60
66
  };
61
67
  break;
62
68
  }
63
- let idx = JsonSchema.schemas.findIndex((s)=>s.$id === schema.$id);
69
+ var idx = JsonSchema.schemas.findIndex(function(s) {
70
+ return s.$id === schema.$id;
71
+ });
64
72
  if (idx >= 0) {
65
73
  JsonSchema.schemas[idx] = onConflict(JsonSchema.schemas[idx], schema);
66
74
  } else {
@@ -70,8 +78,8 @@ function validate({ schema, data, mutate, clone, ajv }) {
70
78
  JsonSchema.addSchema = addSchema;
71
79
  function check(schema, data) {
72
80
  return validate({
73
- schema,
74
- data,
81
+ schema: schema,
82
+ data: data,
75
83
  mutate: false,
76
84
  clone: true
77
85
  });
@@ -81,8 +89,8 @@ function validate({ schema, data, mutate, clone, ajv }) {
81
89
  */ JsonSchema.check = check;
82
90
  function safeParse(schema, data) {
83
91
  return validate({
84
- schema,
85
- data,
92
+ schema: schema,
93
+ data: data,
86
94
  mutate: true,
87
95
  clone: true
88
96
  });
@@ -91,12 +99,12 @@ function validate({ schema, data, mutate, clone, ajv }) {
91
99
  * Parse data with default value and coerceTypes
92
100
  */ JsonSchema.safeParse = safeParse;
93
101
  function parse(schema, data) {
94
- const { data: out, message, errors } = validate({
95
- schema,
96
- data,
102
+ var _validate = validate({
103
+ schema: schema,
104
+ data: data,
97
105
  mutate: true,
98
106
  clone: true
99
- });
107
+ }), out = _validate.data, message = _validate.message, errors = _validate.errors;
100
108
  if (errors) {
101
109
  throw new Error(message);
102
110
  }
@@ -106,56 +114,72 @@ function validate({ schema, data, mutate, clone, ajv }) {
106
114
  function create(schema, data) {
107
115
  // will not ensure value match the rule
108
116
  return match(schema).returnType().with({
109
- const: P.select()
110
- }, (v)=>v).with({
117
+ const: P.nonNullable
118
+ }, function(v) {
119
+ return v;
120
+ }).with({
111
121
  default: P.select()
112
- }, (v)=>v).with({
122
+ }, function(v) {
123
+ return v;
124
+ }).with({
113
125
  anyOf: P.nonNullable
114
- }, (schema)=>{
126
+ }, function(schema) {
115
127
  return create(schema.anyOf[0]);
116
128
  }).with({
117
129
  oneOf: P.nonNullable
118
- }, (schema)=>{
130
+ }, function(schema) {
119
131
  return create(schema.oneOf[0]);
120
132
  }).with({
121
133
  type: 'string'
122
- }, (schema)=>'').with({
134
+ }, function(schema) {
135
+ return '';
136
+ }).with({
123
137
  type: P.union('number', 'integer')
124
- }, (schema)=>0).with({
138
+ }, function(schema) {
139
+ return 0;
140
+ }).with({
125
141
  type: 'object'
126
- }, (schema)=>{
127
- let out = validate({
128
- schema,
129
- data: data ?? {},
142
+ }, function(schema) {
143
+ var out = validate({
144
+ schema: schema,
145
+ data: data !== null && data !== void 0 ? data : {},
130
146
  mutate: true
131
147
  });
132
148
  if (!out.success) {
149
+ var _schema_required;
133
150
  // fallback
134
- let obj = data || {};
135
- schema.required?.forEach((key)=>{
151
+ var obj = data || {};
152
+ (_schema_required = schema.required) === null || _schema_required === void 0 ? void 0 : _schema_required.forEach(function(key) {
136
153
  if (!(key in obj)) {
137
- let last = obj[key];
138
- let prop = schema.properties?.[key];
154
+ var _schema_properties;
155
+ var last = obj[key];
156
+ var prop = (_schema_properties = schema.properties) === null || _schema_properties === void 0 ? void 0 : _schema_properties[key];
139
157
  if (prop && isNil(last)) obj[key] = JsonSchema.create(prop, last);
140
158
  }
141
159
  });
142
160
  out = validate({
143
- schema,
161
+ schema: schema,
144
162
  data: obj,
145
163
  mutate: true
146
164
  });
147
165
  if (!out.success) {
148
- console.warn(`Failed to create object with schema: ${out.message}`);
166
+ console.warn("Failed to create object with schema: ".concat(out.message));
149
167
  }
150
168
  }
151
169
  return out.data;
152
170
  }).with({
153
171
  type: 'null'
154
- }, ()=>null).with({
172
+ }, function() {
173
+ return null;
174
+ }).with({
155
175
  type: 'boolean'
156
- }, (schema)=>false).with({
176
+ }, function(schema) {
177
+ return false;
178
+ }).with({
157
179
  type: 'array'
158
- }, (schema)=>[]).otherwise(()=>{
180
+ }, function(schema) {
181
+ return [];
182
+ }).otherwise(function() {
159
183
  return undefined;
160
184
  });
161
185
  }
@@ -163,18 +187,20 @@ function validate({ schema, data, mutate, clone, ajv }) {
163
187
  function isPrimitiveType(schema) {
164
188
  return match(schema).returnType().with({
165
189
  type: P.union('number', 'integer', 'string', 'boolean')
166
- }, ()=>true).with({
190
+ }, function() {
191
+ return true;
192
+ }).with({
167
193
  anyOf: P.nonNullable
168
- }, (schema)=>{
194
+ }, function(schema) {
169
195
  return isPrimitiveType(schema.anyOf[0]);
170
196
  }).with({
171
197
  oneOf: P.nonNullable
172
- }, (schema)=>{
198
+ }, function(schema) {
173
199
  return isPrimitiveType(schema.oneOf[0]);
174
- }).otherwise(()=>false);
200
+ }).otherwise(function() {
201
+ return false;
202
+ });
175
203
  }
176
204
  JsonSchema.isPrimitiveType = isPrimitiveType;
177
205
  })(JsonSchema || (JsonSchema = {}));
178
206
  export var JsonSchema;
179
-
180
- //# sourceMappingURL=JsonSchema.js.map
@@ -0,0 +1,137 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length)
3
+ len = arr.length;
4
+ for (var i = 0, arr2 = new Array(len); i < len; i++)
5
+ arr2[i] = arr[i];
6
+ return arr2;
7
+ }
8
+ function _array_with_holes(arr) {
9
+ if (Array.isArray(arr))
10
+ return arr;
11
+ }
12
+ function _iterable_to_array_limit(arr, i) {
13
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
14
+ if (_i == null)
15
+ return;
16
+ var _arr = [];
17
+ var _n = true;
18
+ var _d = false;
19
+ var _s, _e;
20
+ try {
21
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
22
+ _arr.push(_s.value);
23
+ if (i && _arr.length === i)
24
+ break;
25
+ }
26
+ }
27
+ catch (err) {
28
+ _d = true;
29
+ _e = err;
30
+ }
31
+ finally {
32
+ try {
33
+ if (!_n && _i["return"] != null)
34
+ _i["return"]();
35
+ }
36
+ finally {
37
+ if (_d)
38
+ throw _e;
39
+ }
40
+ }
41
+ return _arr;
42
+ }
43
+ function _non_iterable_rest() {
44
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
45
+ }
46
+ function _sliced_to_array(arr, i) {
47
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
48
+ }
49
+ function _unsupported_iterable_to_array(o, minLen) {
50
+ if (!o)
51
+ return;
52
+ if (typeof o === "string")
53
+ return _array_like_to_array(o, minLen);
54
+ var n = Object.prototype.toString.call(o).slice(8, -1);
55
+ if (n === "Object" && o.constructor)
56
+ n = o.constructor.name;
57
+ if (n === "Map" || n === "Set")
58
+ return Array.from(n);
59
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
60
+ return _array_like_to_array(o, minLen);
61
+ }
62
+ import { describe, expect, it } from "vitest";
63
+ import { JsonSchema } from "./JsonSchema.js";
64
+ describe("jsonschema", function () {
65
+ it("should create from schema", function () {
66
+ for (var _i = 0, _iter = [
67
+ [
68
+ {
69
+ type: "string"
70
+ },
71
+ ""
72
+ ],
73
+ [
74
+ {
75
+ type: "number"
76
+ },
77
+ 0
78
+ ],
79
+ [
80
+ {
81
+ type: "number",
82
+ default: 1
83
+ },
84
+ 1
85
+ ],
86
+ [
87
+ {
88
+ type: "integer"
89
+ },
90
+ 0
91
+ ],
92
+ [
93
+ {
94
+ type: "array"
95
+ },
96
+ []
97
+ ],
98
+ [
99
+ {
100
+ type: "object"
101
+ },
102
+ {}
103
+ ],
104
+ [
105
+ {
106
+ type: "object",
107
+ properties: {
108
+ a: {
109
+ type: "string"
110
+ }
111
+ },
112
+ required: [
113
+ "a"
114
+ ]
115
+ },
116
+ {
117
+ a: ""
118
+ }
119
+ ]
120
+ ]; _i < _iter.length; _i++) {
121
+ var _iter__i = _sliced_to_array(_iter[_i], 2), a = _iter__i[0], b = _iter__i[1];
122
+ expect(JsonSchema.create(a)).toEqual(b);
123
+ }
124
+ });
125
+ it("should match typebox types", function () {
126
+ var a;
127
+ var b;
128
+ a = b;
129
+ });
130
+ it("should match ajv types", function () {
131
+ var a;
132
+ var b;
133
+ var c;
134
+ a = b;
135
+ // a = c;
136
+ });
137
+ });
@@ -1,2 +1 @@
1
1
  export { JsonSchema } from "./JsonSchema.js";
2
- //# sourceMappingURL=index.js.map
@@ -1,3 +1,5 @@
1
- export { };
2
-
3
- //# sourceMappingURL=types.d.js.map
1
+ /**
2
+ * JSON Schema Definition
3
+ *
4
+ * @see https://json-schema.org/specification-links.html
5
+ */ export { };
@@ -1,5 +1,91 @@
1
- let _all = [];
2
- export function defineFileType({ type = '', types = [], extension = '', extensions = [], ...opts }) {
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_without_holes(arr) {
7
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
8
+ }
9
+ function _define_property(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value: value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
19
+ }
20
+ return obj;
21
+ }
22
+ function _iterable_to_array(iter) {
23
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
24
+ }
25
+ function _non_iterable_spread() {
26
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
27
+ }
28
+ function _object_spread(target) {
29
+ for(var i = 1; i < arguments.length; i++){
30
+ var source = arguments[i] != null ? arguments[i] : {};
31
+ var ownKeys = Object.keys(source);
32
+ if (typeof Object.getOwnPropertySymbols === "function") {
33
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
34
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
35
+ }));
36
+ }
37
+ ownKeys.forEach(function(key) {
38
+ _define_property(target, key, source[key]);
39
+ });
40
+ }
41
+ return target;
42
+ }
43
+ function _object_without_properties(source, excluded) {
44
+ if (source == null) return {};
45
+ var target = _object_without_properties_loose(source, excluded);
46
+ var key, i;
47
+ if (Object.getOwnPropertySymbols) {
48
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
49
+ for(i = 0; i < sourceSymbolKeys.length; i++){
50
+ key = sourceSymbolKeys[i];
51
+ if (excluded.indexOf(key) >= 0) continue;
52
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
53
+ target[key] = source[key];
54
+ }
55
+ }
56
+ return target;
57
+ }
58
+ function _object_without_properties_loose(source, excluded) {
59
+ if (source == null) return {};
60
+ var target = {};
61
+ var sourceKeys = Object.keys(source);
62
+ var key, i;
63
+ for(i = 0; i < sourceKeys.length; i++){
64
+ key = sourceKeys[i];
65
+ if (excluded.indexOf(key) >= 0) continue;
66
+ target[key] = source[key];
67
+ }
68
+ return target;
69
+ }
70
+ function _to_consumable_array(arr) {
71
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
72
+ }
73
+ function _unsupported_iterable_to_array(o, minLen) {
74
+ if (!o) return;
75
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
76
+ var n = Object.prototype.toString.call(o).slice(8, -1);
77
+ if (n === "Object" && o.constructor) n = o.constructor.name;
78
+ if (n === "Map" || n === "Set") return Array.from(n);
79
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
80
+ }
81
+ var _all = [];
82
+ export function defineFileType(_param) {
83
+ var _param_type = _param.type, type = _param_type === void 0 ? '' : _param_type, _param_types = _param.types, types = _param_types === void 0 ? [] : _param_types, _param_extension = _param.extension, extension = _param_extension === void 0 ? '' : _param_extension, _param_extensions = _param.extensions, extensions = _param_extensions === void 0 ? [] : _param_extensions, opts = _object_without_properties(_param, [
84
+ "type",
85
+ "types",
86
+ "extension",
87
+ "extensions"
88
+ ]);
3
89
  if (!type) {
4
90
  type = types[0] || '';
5
91
  }
@@ -8,30 +94,29 @@ export function defineFileType({ type = '', types = [], extension = '', extensio
8
94
  }
9
95
  if (!types.includes(type)) {
10
96
  types = [
11
- type,
12
- ...types
13
- ];
97
+ type
98
+ ].concat(_to_consumable_array(types));
14
99
  }
15
100
  if (!extensions.includes(extension)) {
16
101
  extensions = [
17
- extension,
18
- ...extensions
19
- ];
102
+ extension
103
+ ].concat(_to_consumable_array(extensions));
20
104
  }
21
- const def = {
105
+ var def = _object_spread({
22
106
  title: opts.title || opts.name,
23
- type,
24
- extension,
25
- types,
26
- extensions,
107
+ type: type,
108
+ extension: extension,
109
+ types: types,
110
+ extensions: extensions,
27
111
  tags: [],
28
- metadata: {},
29
- ...opts
30
- };
31
- let idx = _all.findIndex((v)=>v.name === def.name);
112
+ metadata: {}
113
+ }, opts);
114
+ var idx = _all.findIndex(function(v) {
115
+ return v.name === def.name;
116
+ });
32
117
  if (idx >= 0) {
33
118
  _all[idx] = def;
34
- console.warn(`File type ${def.name} is redefined`);
119
+ console.warn("File type ".concat(def.name, " is redefined"));
35
120
  } else {
36
121
  _all.push(def);
37
122
  }
@@ -40,5 +125,3 @@ export function defineFileType({ type = '', types = [], extension = '', extensio
40
125
  export function getFileType() {
41
126
  return _all;
42
127
  }
43
-
44
- //# sourceMappingURL=defineFileType.js.map