@hybridly/utils 0.0.1-alpha.1 → 0.0.1-alpha.10

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.cjs CHANGED
@@ -3,11 +3,13 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const baseMerge = require('deepmerge');
6
+ const lodash_clonedeep = require('lodash.clonedeep');
6
7
  const makeDebugger = require('debug');
7
8
 
8
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
9
10
 
10
11
  const baseMerge__default = /*#__PURE__*/_interopDefaultLegacy(baseMerge);
12
+ const lodash_clonedeep__default = /*#__PURE__*/_interopDefaultLegacy(lodash_clonedeep);
11
13
  const makeDebugger__default = /*#__PURE__*/_interopDefaultLegacy(makeDebugger);
12
14
 
13
15
  function hasFiles(data) {
@@ -298,33 +300,6 @@ function when(condition, data, _default) {
298
300
  }
299
301
  return data;
300
302
  }
301
- function clone(val) {
302
- let k, out, tmp;
303
- if (Array.isArray(val)) {
304
- out = Array(k = val.length);
305
- while (k--) {
306
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? clone(tmp) : tmp;
307
- }
308
- return out;
309
- }
310
- if (Object.prototype.toString.call(val) === "[object Object]") {
311
- out = {};
312
- for (k in val) {
313
- if (k === "__proto__") {
314
- Object.defineProperty(out, k, {
315
- value: clone(val[k]),
316
- configurable: true,
317
- enumerable: true,
318
- writable: true
319
- });
320
- } else {
321
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? clone(tmp) : tmp;
322
- }
323
- }
324
- return out;
325
- }
326
- return val;
327
- }
328
303
  function merge(x, y) {
329
304
  return baseMerge__default(x, y, { arrayMerge: (_, s) => s });
330
305
  }
@@ -341,7 +316,7 @@ const debug = {
341
316
  adapter: (name, ...args) => makeDebugger__default("hybridly:adapter").extend(name)(args.shift(), ...args)
342
317
  };
343
318
 
344
- exports.clone = clone;
319
+ exports.clone = lodash_clonedeep__default;
345
320
  exports.debounce = debounce;
346
321
  exports.debug = debug;
347
322
  exports.hasFiles = hasFiles;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import makeDebugger from 'debug';
2
+ export { default as clone } from 'lodash.clonedeep';
2
3
 
3
4
  declare type RequestData = Record<string, FormDataConvertible> | FormDataConvertible | FormData;
4
5
  declare type FormDataConvertible = {
@@ -32,11 +33,11 @@ declare function showResponseErrorModal(response: string): Modal;
32
33
  declare function showPageComponentErrorModal(response: string): Modal;
33
34
 
34
35
  declare function random(length?: number): string;
36
+ /** Simple pattern matching util. */
35
37
  declare function match<TValue extends string | number = string, TReturnValue = unknown>(value: TValue, lookup: Record<TValue | 'default', TReturnValue | ((...args: any[]) => TReturnValue)>, ...args: any[]): TReturnValue | Promise<TReturnValue>;
36
38
  declare function debounce<F extends (...params: any[]) => ReturnType<F>>(fn: F, delay: number): F;
37
39
  declare function value<T>(value: T | (() => T)): T;
38
40
  declare function when<T, D>(condition: any, data: T, _default?: D): T | D | undefined;
39
- declare function clone<T>(val: T): T;
40
41
  declare function merge<T>(x: Partial<T>, y: Partial<T>): T;
41
42
 
42
43
  declare const debug: {
@@ -51,4 +52,4 @@ declare const debug: {
51
52
  adapter: (name: string, ...args: any[]) => void;
52
53
  };
53
54
 
54
- export { FormDataConvertible, RequestData, clone, debounce, debug, hasFiles, match, merge, objectToFormData, random, showPageComponentErrorModal, showResponseErrorModal, value, when };
55
+ export { FormDataConvertible, RequestData, debounce, debug, hasFiles, match, merge, objectToFormData, random, showPageComponentErrorModal, showResponseErrorModal, value, when };
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import baseMerge from 'deepmerge';
2
+ export { default as clone } from 'lodash.clonedeep';
2
3
  import makeDebugger from 'debug';
3
4
 
4
5
  function hasFiles(data) {
@@ -289,33 +290,6 @@ function when(condition, data, _default) {
289
290
  }
290
291
  return data;
291
292
  }
292
- function clone(val) {
293
- let k, out, tmp;
294
- if (Array.isArray(val)) {
295
- out = Array(k = val.length);
296
- while (k--) {
297
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? clone(tmp) : tmp;
298
- }
299
- return out;
300
- }
301
- if (Object.prototype.toString.call(val) === "[object Object]") {
302
- out = {};
303
- for (k in val) {
304
- if (k === "__proto__") {
305
- Object.defineProperty(out, k, {
306
- value: clone(val[k]),
307
- configurable: true,
308
- enumerable: true,
309
- writable: true
310
- });
311
- } else {
312
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? clone(tmp) : tmp;
313
- }
314
- }
315
- return out;
316
- }
317
- return val;
318
- }
319
293
  function merge(x, y) {
320
294
  return baseMerge(x, y, { arrayMerge: (_, s) => s });
321
295
  }
@@ -332,4 +306,4 @@ const debug = {
332
306
  adapter: (name, ...args) => makeDebugger("hybridly:adapter").extend(name)(args.shift(), ...args)
333
307
  };
334
308
 
335
- export { clone, debounce, debug, hasFiles, match, merge, objectToFormData, random, showPageComponentErrorModal, showResponseErrorModal, value, when };
309
+ export { debounce, debug, hasFiles, match, merge, objectToFormData, random, showPageComponentErrorModal, showResponseErrorModal, value, when };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hybridly/utils",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1-alpha.10",
4
4
  "description": "A solution to develop server-driven, client-rendered applications",
5
5
  "keywords": [
6
6
  "hybridly",
@@ -34,7 +34,8 @@
34
34
  "types": "dist/index.d.ts",
35
35
  "dependencies": {
36
36
  "debug": "^4.3.4",
37
- "deepmerge": "^4.2.2"
37
+ "deepmerge": "^4.2.2",
38
+ "lodash.clonedeep": "^4.5.0"
38
39
  },
39
40
  "scripts": {
40
41
  "build": "unbuild",