@e-mc/types 0.9.4 → 0.9.6

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/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.9.4/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.6/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogArguments } from "./lib/logger";
@@ -194,8 +194,8 @@ const IMPORT_MAP: Record<string, string | undefined>;
194
194
 
195
195
  ## References
196
196
 
197
- - https://www.unpkg.com/@e-mc/types@0.9.4/lib/logger.d.ts
198
- - https://www.unpkg.com/@e-mc/types@0.9.4/lib/module.d.ts
197
+ - https://www.unpkg.com/@e-mc/types@0.9.6/lib/logger.d.ts
198
+ - https://www.unpkg.com/@e-mc/types@0.9.6/lib/module.d.ts
199
199
 
200
200
  * https://nodejs.org/api/perf_hooks.html
201
201
  * https://www.npmjs.com/package/@types/bytes
package/constant.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const enum INTERNAL {
2
- VERSION = '0.9.4',
2
+ VERSION = '0.9.6',
3
3
  TEMP_DIR = 'tmp',
4
4
  CJS = '__cjs__'
5
5
  }
package/index.d.ts CHANGED
@@ -311,7 +311,7 @@ declare namespace types {
311
311
  function getEncoding(value: unknown, fallback?: BufferEncoding): BufferEncoding;
312
312
  function encryptUTF8(algorithm: CipherGCMTypes, key: BinaryLike, iv: BinaryLike, data: string, encoding?: Encoding): Undef<string>;
313
313
  function decryptUTF8(algorithm: CipherGCMTypes, key: BinaryLike, iv: BinaryLike, data: string, encoding?: Encoding): Undef<string>;
314
- /* @deprecated - crypto.randomUUID */
314
+ /** @deprecated crypto.randomUUID */
315
315
  function generateUUID(): string;
316
316
  function incrementUUID(restart?: boolean): string;
317
317
  function validateUUID(value: unknown): boolean;
package/index.js CHANGED
@@ -145,6 +145,63 @@ function recurseObject(data, parseString, completed, cache) {
145
145
  }
146
146
  return data;
147
147
  }
148
+ function mergedArray(target, attr, data, type) {
149
+ const prop = target[attr];
150
+ if (type && Array.isArray(prop) && Array.isArray(data)) {
151
+ let arg1, arg2;
152
+ if (Array.isArray(type)) {
153
+ [type, arg1, arg2] = type;
154
+ }
155
+ switch (type) {
156
+ case 'concat':
157
+ target[attr] = prop.concat(data);
158
+ break;
159
+ case 'concat-pre':
160
+ target[attr] = data.concat(prop);
161
+ break;
162
+ case 'push':
163
+ case 'unshift':
164
+ case 'includes':
165
+ for (let i = 0, length = data.length; i < length; ++i) {
166
+ if (type !== 'includes' || !prop.includes(data[i])) {
167
+ prop[type](data[i]);
168
+ }
169
+ }
170
+ break;
171
+ case 'flat':
172
+ target[attr] = data.flat(arg1);
173
+ case 'join':
174
+ target[attr] = data.join(arg1);
175
+ break;
176
+ case 'slice':
177
+ target[attr] = data.slice(arg1, arg2);
178
+ break;
179
+ case 'reverse':
180
+ target[attr] = data.slice(0).reverse();
181
+ break;
182
+ default:
183
+ return false;
184
+ }
185
+ return true;
186
+ }
187
+ return false;
188
+ }
189
+ function getProperties(obj, inherited, nonenumerable, symbol) {
190
+ let attrs;
191
+ if (inherited === false) {
192
+ attrs = nonenumerable ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
193
+ }
194
+ else {
195
+ attrs = [];
196
+ for (const attr in obj) {
197
+ attrs.push(attr);
198
+ }
199
+ if (nonenumerable) {
200
+ attrs = Array.from(new Set(attrs.concat(Object.getOwnPropertyNames(obj))));
201
+ }
202
+ }
203
+ return symbol ? attrs.concat(Object.getOwnPropertySymbols(obj)) : attrs;
204
+ }
148
205
  const convertScrypt = (key, iv, data) => crypto.scryptSync(key, iv, Math.ceil(data.length / 16) * 16);
149
206
  const isFunction = (value) => typeof value === 'function';
150
207
  var LOG_TYPE;
@@ -653,7 +710,7 @@ function cascadeObject(data, query, fallback) {
653
710
  }
654
711
  exports.cascadeObject = cascadeObject;
655
712
  function cloneObject(data, options) {
656
- let target, deep, deepIgnore, typedArray, inherited, nonenumerable, symbol, preserve;
713
+ let target, deep, deepIgnore, mergeArray, mergeDepth = Infinity, typedArray, inherited, nonenumerable, symbol, preserve;
657
714
  if (options === true) {
658
715
  deep = true;
659
716
  }
@@ -662,23 +719,30 @@ function cloneObject(data, options) {
662
719
  deepIgnore = options;
663
720
  }
664
721
  else if (options) {
665
- ({ target, deep, deepIgnore, typedArray, inherited, nonenumerable, symbol, preserve } = options);
722
+ ({ target, deep, deepIgnore, mergeArray, typedArray, inherited, nonenumerable, symbol, preserve } = options);
723
+ if (options.mergeDepth !== undefined) {
724
+ mergeDepth = options.mergeDepth - 1;
725
+ }
666
726
  }
667
727
  let nested;
668
728
  if (deep) {
669
729
  deepIgnore || (deepIgnore = new WeakSet());
670
- nested = { deep, deepIgnore, typedArray, preserve };
730
+ nested = { deep, deepIgnore, mergeArray, mergeDepth, typedArray, preserve };
671
731
  }
672
732
  if (Array.isArray(data)) {
673
- if (deepIgnore) {
674
- deepIgnore.add(data);
675
- }
733
+ deepIgnore?.add(data);
676
734
  const length = data.length;
677
- if (!target || !Array.isArray(target)) {
678
- target = new Array(length);
735
+ if (Array.isArray(target)) {
736
+ if (mergeArray && mergeDepth >= 0 && !(mergeArray === 'join' || Array.isArray(mergeArray) && mergeArray[0] === 'join')) {
737
+ const out = { target };
738
+ if (mergedArray(out, 'target', data, mergeArray)) {
739
+ return out.target;
740
+ }
741
+ }
742
+ target.length = 0;
679
743
  }
680
744
  else {
681
- target.length = 0;
745
+ target = new Array(length);
682
746
  }
683
747
  for (let i = 0; i < length; ++i) {
684
748
  const value = data[i];
@@ -691,29 +755,11 @@ function cloneObject(data, options) {
691
755
  }
692
756
  }
693
757
  else if (isObject(data)) {
694
- if (deepIgnore) {
695
- deepIgnore.add(data);
696
- }
697
- if (!target || !isObject(target)) {
758
+ deepIgnore?.add(data);
759
+ if (!isObject(target)) {
698
760
  target = {};
699
761
  }
700
- const getProperties = (obj) => {
701
- let attrs;
702
- if (inherited === false) {
703
- attrs = nonenumerable ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
704
- }
705
- else {
706
- attrs = [];
707
- for (const attr in obj) {
708
- attrs.push(attr);
709
- }
710
- if (nonenumerable) {
711
- attrs = Array.from(new Set(attrs.concat(Object.getOwnPropertyNames(obj))));
712
- }
713
- }
714
- return symbol ? attrs.concat(Object.getOwnPropertySymbols(obj)) : attrs;
715
- };
716
- for (const attr of getProperties(data)) {
762
+ for (const attr of getProperties(data, inherited, nonenumerable, symbol)) {
717
763
  const value = data[attr];
718
764
  let merge;
719
765
  if (deepIgnore) {
@@ -722,23 +768,24 @@ function cloneObject(data, options) {
722
768
  else {
723
769
  merge = Array.isArray(value) ? value.slice(0) : value;
724
770
  }
725
- if (preserve && isPlainObject(target[attr]) && isPlainObject(merge)) {
771
+ const prop = target[attr];
772
+ if (preserve && isPlainObject(prop) && isPlainObject(merge)) {
726
773
  (function recurse(current, next) {
727
- for (const item of getProperties(next)) {
774
+ for (const item of getProperties(next, inherited, nonenumerable, symbol)) {
728
775
  const b = next[item];
729
- if (!(item in current)) {
730
- current[item] = b;
731
- }
732
- else {
776
+ if (item in current) {
733
777
  const a = current[item];
734
778
  if (isPlainObject(a) && isPlainObject(b)) {
735
779
  recurse(a, b);
736
780
  }
737
781
  }
782
+ else if (!(mergeArray && mergeDepth >= 0 && mergedArray(current, item, b, mergeArray))) {
783
+ current[item] = b;
784
+ }
738
785
  }
739
- })(target[attr], merge);
786
+ })(prop, merge);
740
787
  }
741
- else {
788
+ else if (!(mergeArray && mergeDepth >= 0 && mergedArray(target, attr, merge, mergeArray))) {
742
789
  target[attr] = merge;
743
790
  }
744
791
  }
package/lib/compress.d.ts CHANGED
@@ -2,7 +2,10 @@ import type { CompressFormat as ICompressFormat } from './squared';
2
2
 
3
3
  import type { LogBaseOptions, LogTime } from './logger';
4
4
 
5
- interface CompressFormat extends ICompressFormat, LogBaseOptions {
5
+ type ResultCallback<T = Null<Buffer | Uint8Array>> = (err: unknown, data?: T, ext?: string) => void;
6
+ type ResultData = Null<Buffer | Uint8Array> | string;
7
+
8
+ export interface CompressFormat extends ICompressFormat, LogBaseOptions {
6
9
  filename?: string;
7
10
  startTime?: LogTime;
8
11
  etag?: string;
@@ -11,14 +14,11 @@ interface CompressFormat extends ICompressFormat, LogBaseOptions {
11
14
  outFile?: string;
12
15
  }
13
16
 
14
- interface Woff {
17
+ export interface Woff {
15
18
  toWoff(this: void, data: BufferLike): Buffer;
16
19
  toSfnt(this: void, data: BufferLike): Buffer;
17
20
  }
18
21
 
19
- type ResultCallback<T = Null<Buffer | Uint8Array>> = (err: unknown, data?: T, ext?: string) => void;
20
- type ResultData = Null<Buffer | Uint8Array> | string;
21
-
22
22
  export type BufferLike = Buffer | Uint8Array | ArrayBuffer | SharedArrayBuffer | readonly number[];
23
23
  export type TryFileCompressor = (data: string | Buffer, output: string, config: CompressFormat, callback?: ResultCallback<ResultData>) => Void<Promise<ResultData>>;
24
24
  export type TryFileCompressorAsync = (data: string | Buffer, output: string, config: CompressFormat) => Promise<ResultData>;
package/lib/index.d.ts CHANGED
@@ -106,7 +106,7 @@ declare namespace functions {
106
106
 
107
107
  interface ImageConstructor<T extends IHost = IHost, U extends ImageModule = ImageModule> extends ModuleConstructor {
108
108
  readonly REGEXP_SIZERANGE: RegExp;
109
- transform<V extends TransformOptions>(file: string, command: string, options?: V): Promise<U extends { tempFile: true } ? string : Null<Buffer>>;
109
+ transform<V extends TransformOptions>(file: string, command: string, options?: V): Promise<V extends { tempFile: true } ? string : Null<Buffer>>;
110
110
  clamp(value: unknown, min?: number, max?: number): number;
111
111
  isBinary(mime: unknown): mime is string;
112
112
  toABGR(buffer: Uint8Array | Buffer): Buffer;
@@ -255,9 +255,9 @@ declare namespace functions {
255
255
 
256
256
  interface DocumentConstructor<T extends IFileManager<U>, U extends ExternalAsset = ExternalAsset, V extends ClientModule = DocumentModule, W extends DocumentComponent = DocumentComponent, X extends DocumentComponentOption = DocumentComponentOption, Y extends ICloud = ICloud<T>> extends ModuleConstructor {
257
257
  finalize(this: T, instance: IDocument<T, U, V, W, X, Y>): Promise<unknown>;
258
- /* @deprecated */
258
+ /** @deprecated */
259
259
  createSourceMap(code: string, remove: boolean): SourceMap;
260
- /* @deprecated */
260
+ /** @deprecated */
261
261
  createSourceMap(code: string, uri?: string, remove?: boolean): SourceMap;
262
262
  writeSourceMap(uri: string, data: SourceCode, options?: SourceMapOptions): Undef<string>;
263
263
  updateGradle(source: string, namespaces: string[], value: string, upgrade: boolean): string;
@@ -579,7 +579,7 @@ declare namespace functions {
579
579
  interface IModule<T extends IHost = IHost> extends EventEmitter, IAbortComponent {
580
580
  readonly status: LogStatus<StatusType>[];
581
581
  readonly errors: unknown[];
582
- /* @deprecated */
582
+ /** @deprecated */
583
583
  supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
584
584
  supports(name: string, value?: boolean): boolean;
585
585
  getTempDir(options: GetTempDirOptions): string;
package/lib/module.d.ts CHANGED
@@ -71,6 +71,8 @@ export interface CloneObjectOptions<T = unknown> {
71
71
  deep?: boolean;
72
72
  deepIgnore?: WeakSet<object>;
73
73
  typedArray?: boolean;
74
+ mergeArray?: MergeArrayMethod;
75
+ mergeDepth?: number;
74
76
  symbol?: boolean;
75
77
  inherited?: boolean;
76
78
  nonenumerable?: boolean;
@@ -138,4 +140,5 @@ export interface IncludeAction<T = string[]> {
138
140
  export type NormalizeFlags = typeof NORMALIZE_FLAGS[keyof typeof NORMALIZE_FLAGS];
139
141
  export type ReadTextOptions = ReadBufferOptions;
140
142
  export type ReadFileCallback<T extends Bufferable = Bufferable> = (err: Null<NodeJS.ErrnoException>, data?: T) => void;
141
- export type ProtocolType = "http" | "https" | "http/s" | "ftp" | "sftp" | "s/ftp" | "torrent" | "unc";
143
+ export type ProtocolType = "http" | "https" | "http/s" | "ftp" | "sftp" | "s/ftp" | "torrent" | "unc" | "file";
144
+ export type MergeArrayMethod = "concat" | "concat-pre" | "includes" | "unshift" | "push" | "flat" | "join" | "slice" | "reverse" | ["flat", number] | ["join", string] | ["slice", number, number?];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/types",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
4
4
  "description": "Type definitions for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",