topkat-utils 1.1.9 → 1.1.11

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 (80) hide show
  1. package/index.js +1 -0
  2. package/index.ts +1 -1
  3. package/package.json +3 -2
  4. package/src/{private/config.ts → config.ts} +8 -8
  5. package/src/logger-utils.ts +1 -1
  6. package/src/loop-utils.ts +6 -6
  7. package/src/validation-utils.ts +1 -1
  8. package/tsconfig.json +4 -2
  9. package/dist/index.d.ts +0 -36
  10. package/dist/index.js +0 -58
  11. package/dist/index.js.map +0 -1
  12. package/dist/src/array-utils.d.ts +0 -56
  13. package/dist/src/array-utils.js +0 -138
  14. package/dist/src/array-utils.js.map +0 -1
  15. package/dist/src/date-utils.d.ts +0 -100
  16. package/dist/src/date-utils.js +0 -357
  17. package/dist/src/date-utils.js.map +0 -1
  18. package/dist/src/env-utils.d.ts +0 -8
  19. package/dist/src/env-utils.js +0 -38
  20. package/dist/src/env-utils.js.map +0 -1
  21. package/dist/src/error-utils.d.ts +0 -8
  22. package/dist/src/error-utils.js +0 -88
  23. package/dist/src/error-utils.js.map +0 -1
  24. package/dist/src/is-empty.d.ts +0 -1
  25. package/dist/src/is-empty.js +0 -13
  26. package/dist/src/is-empty.js.map +0 -1
  27. package/dist/src/is-object.d.ts +0 -2
  28. package/dist/src/is-object.js +0 -7
  29. package/dist/src/is-object.js.map +0 -1
  30. package/dist/src/isset.d.ts +0 -1
  31. package/dist/src/isset.js +0 -8
  32. package/dist/src/isset.js.map +0 -1
  33. package/dist/src/logger-utils.d.ts +0 -76
  34. package/dist/src/logger-utils.js +0 -355
  35. package/dist/src/logger-utils.js.map +0 -1
  36. package/dist/src/loop-utils.d.ts +0 -40
  37. package/dist/src/loop-utils.js +0 -96
  38. package/dist/src/loop-utils.js.map +0 -1
  39. package/dist/src/math-utils.d.ts +0 -23
  40. package/dist/src/math-utils.js +0 -43
  41. package/dist/src/math-utils.js.map +0 -1
  42. package/dist/src/mongo-utils.d.ts +0 -11
  43. package/dist/src/mongo-utils.js +0 -49
  44. package/dist/src/mongo-utils.js.map +0 -1
  45. package/dist/src/object-utils.d.ts +0 -96
  46. package/dist/src/object-utils.js +0 -369
  47. package/dist/src/object-utils.js.map +0 -1
  48. package/dist/src/private/config.d.ts +0 -44
  49. package/dist/src/private/config.js +0 -64
  50. package/dist/src/private/config.js.map +0 -1
  51. package/dist/src/private/error-handler.d.ts +0 -10
  52. package/dist/src/private/error-handler.js +0 -21
  53. package/dist/src/private/error-handler.js.map +0 -1
  54. package/dist/src/private/types.d.ts +0 -5
  55. package/dist/src/private/types.js +0 -3
  56. package/dist/src/private/types.js.map +0 -1
  57. package/dist/src/regexp-utils.d.ts +0 -12
  58. package/dist/src/regexp-utils.js +0 -44
  59. package/dist/src/regexp-utils.js.map +0 -1
  60. package/dist/src/remove-circular-json-stringify.d.ts +0 -1
  61. package/dist/src/remove-circular-json-stringify.js +0 -20
  62. package/dist/src/remove-circular-json-stringify.js.map +0 -1
  63. package/dist/src/string-utils.d.ts +0 -77
  64. package/dist/src/string-utils.js +0 -214
  65. package/dist/src/string-utils.js.map +0 -1
  66. package/dist/src/tests-utils.d.ts +0 -21
  67. package/dist/src/tests-utils.js +0 -77
  68. package/dist/src/tests-utils.js.map +0 -1
  69. package/dist/src/timer-utils.d.ts +0 -16
  70. package/dist/src/timer-utils.js +0 -62
  71. package/dist/src/timer-utils.js.map +0 -1
  72. package/dist/src/transaction-utils.d.ts +0 -14
  73. package/dist/src/transaction-utils.js +0 -72
  74. package/dist/src/transaction-utils.js.map +0 -1
  75. package/dist/src/validation-utils.d.ts +0 -80
  76. package/dist/src/validation-utils.js +0 -195
  77. package/dist/src/validation-utils.js.map +0 -1
  78. package/dist/src/wtf-utils.d.ts +0 -7
  79. package/dist/src/wtf-utils.js +0 -83
  80. package/dist/src/wtf-utils.js.map +0 -1
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/src')
package/index.ts CHANGED
@@ -18,7 +18,7 @@ export * from './src/remove-circular-json-stringify'
18
18
  export * from './src/is-object'
19
19
  export * from './src/regexp-utils'
20
20
  export * from './src/private/error-handler'
21
- export { registerConfig } from './src/private/config'
21
+ export { registerConfig } from './src/config'
22
22
 
23
23
  import { moyenne } from './src/math-utils'
24
24
  import { kebabCase, snakeCase } from './src/string-utils'
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "topkat-utils",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "type": "commonjs",
5
+ "types": "index.ts",
5
6
  "private": false,
6
7
  "description": "FAST AND FUNCTIONAL UTILS",
7
8
  "author": "topkat",
8
9
  "license": "ISC",
9
- "main": "dist/index.js",
10
+ "main": ".",
10
11
  "repository": {
11
12
  "type": "git",
12
13
  "url": "https://github.com/top-kat/utils"
@@ -1,7 +1,7 @@
1
- import { Color } from './types'
2
- import { isset } from '../isset'
1
+ import { Color } from './private/types'
2
+ import { isset } from './isset'
3
3
 
4
- export type Config = {
4
+ export type TopkatUtilConfig = {
5
5
  env: string
6
6
  isProd: boolean
7
7
  nbOfLogsToKeep: number
@@ -14,16 +14,16 @@ export type Config = {
14
14
  shade1: Color,
15
15
  shade2: Color,
16
16
  bgColor?: Color
17
- paddingX: number
18
- paddingY: number
17
+ paddingX?: number
18
+ paddingY?: number
19
19
  fontColor?: Color
20
- pageWidth: number
21
- debugModeColor: Color,
20
+ pageWidth?: number
21
+ debugModeColor?: Color,
22
22
  }
23
23
  },
24
24
  }
25
25
 
26
- let config: Config = {
26
+ let config: TopkatUtilConfig = {
27
27
  env: 'development',
28
28
  isProd: false,
29
29
  nbOfLogsToKeep: 25,
@@ -1,7 +1,7 @@
1
1
  //----------------------------------------
2
2
  // LOGGER
3
3
  //----------------------------------------
4
- import { configFn } from "./private/config"
4
+ import { configFn } from "./config"
5
5
  import { isset } from "./isset"
6
6
  import { Color } from "./private/types"
7
7
  import { removeCircularJSONstringify } from "./remove-circular-json-stringify"
package/src/loop-utils.ts CHANGED
@@ -41,7 +41,7 @@ export type RecursiveConfig = { disableCircularDependencyRemoval?: boolean }
41
41
  * NOTE: will remove circular references
42
42
  * /!\ check return values
43
43
  */
44
- export async function recursiveGenericFunction(item: ObjectGeneric | any[], callback: RecursiveCallback, config?: RecursiveConfig, addr$ = '', lastElementKey: string | number = '', parent?, techFieldToAvoidCircularDependency = []) {
44
+ export async function recursiveGenericFunction(item: ObjectGeneric | any[], callback: RecursiveCallback, config: RecursiveConfig = {}, addr$ = '', lastElementKey: string | number = '', parent?, techFieldToAvoidCircularDependency = []) {
45
45
  err500IfNotSet({ callback })
46
46
 
47
47
  if (!techFieldToAvoidCircularDependency.includes(item)) {
@@ -50,12 +50,12 @@ export async function recursiveGenericFunction(item: ObjectGeneric | any[], call
50
50
  if (result !== false) {
51
51
  const addr = addr$ ? addr$ + '.' : ''
52
52
  if (Array.isArray(item)) {
53
- if (config.disableCircularDependencyRemoval !== true) techFieldToAvoidCircularDependency.push(item)
53
+ if (config?.disableCircularDependencyRemoval !== true) techFieldToAvoidCircularDependency.push(item)
54
54
  await Promise.all(item.map(
55
55
  (e, i) => recursiveGenericFunction(e, callback, config, addr + '[' + i + ']', i, item, techFieldToAvoidCircularDependency)
56
56
  ))
57
57
  } else if (isObject(item)) {
58
- if (config.disableCircularDependencyRemoval !== true) techFieldToAvoidCircularDependency.push(item)
58
+ if (config?.disableCircularDependencyRemoval !== true) techFieldToAvoidCircularDependency.push(item)
59
59
  await Promise.all(Object.entries(item).map(
60
60
  ([key, val]) => recursiveGenericFunction(val, callback, config, addr + key.replace(/\./g, '%'), key, item, techFieldToAvoidCircularDependency)
61
61
  ))
@@ -81,7 +81,7 @@ export async function recursiveGenericFunction(item: ObjectGeneric | any[], call
81
81
  * NOTE: will remove circular references
82
82
  * /!\ check return values
83
83
  */
84
- export function recursiveGenericFunctionSync(item: ObjectGeneric | any[], callback: RecursiveCallback, config?: RecursiveConfig, addr$ = '', lastElementKey: string | number = '', parent?, techFieldToAvoidCircularDependency = []) {
84
+ export function recursiveGenericFunctionSync(item: ObjectGeneric | any[], callback: RecursiveCallback, config: RecursiveConfig = {}, addr$ = '', lastElementKey: string | number = '', parent?, techFieldToAvoidCircularDependency = []) {
85
85
  err500IfNotSet({ callback })
86
86
 
87
87
  if (!techFieldToAvoidCircularDependency.includes(item)) {
@@ -90,10 +90,10 @@ export function recursiveGenericFunctionSync(item: ObjectGeneric | any[], callba
90
90
  if (result !== false) {
91
91
  const addr = addr$ ? addr$ + '.' : ''
92
92
  if (Array.isArray(item)) {
93
- if (config.disableCircularDependencyRemoval !== true) techFieldToAvoidCircularDependency.push(item) // do not up one level
93
+ if (config?.disableCircularDependencyRemoval !== true) techFieldToAvoidCircularDependency.push(item) // do not up one level
94
94
  item.forEach((e, i) => recursiveGenericFunctionSync(e, callback, config, addr + '[' + i + ']', i, item, techFieldToAvoidCircularDependency))
95
95
  } else if (isObject(item)) {
96
- if (config.disableCircularDependencyRemoval !== true) techFieldToAvoidCircularDependency.push(item)
96
+ if (config?.disableCircularDependencyRemoval !== true) techFieldToAvoidCircularDependency.push(item)
97
97
  Object.entries(item).forEach(([key, val]) => recursiveGenericFunctionSync(val, callback, config, addr + key.replace(/\./g, '%'), key, item, techFieldToAvoidCircularDependency))
98
98
  }
99
99
  }
@@ -5,7 +5,7 @@ import { dataValidationUtilErrorHandler } from "./private/error-handler"
5
5
  import { isset } from "./isset"
6
6
  import { isDateIsoOrObjectValid, isDateIntOrStringValid, isTimeStringValid } from "./date-utils"
7
7
  import { asArray } from "./array-utils"
8
- import { configFn } from "./private/config"
8
+ import { configFn } from "./config"
9
9
  import { isEmpty } from "./is-empty"
10
10
  import { removeCircularJSONstringify } from "./remove-circular-json-stringify"
11
11
 
package/tsconfig.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2018",
3
+ "target": "ES5",
4
4
  "module": "commonjs",
5
+ "esModuleInterop": true,
5
6
  "allowSyntheticDefaultImports": true,
6
7
  "noImplicitAny": false,
7
8
  "declaration": true,
@@ -15,6 +16,7 @@
15
16
  ]
16
17
  },
17
18
  "include": [
18
- "./**/*.ts"
19
+ "./**/*.ts",
20
+ "index.ts"
19
21
  ],
20
22
  }
package/dist/index.d.ts DELETED
@@ -1,36 +0,0 @@
1
- export * from './src/array-utils';
2
- export * from './src/date-utils';
3
- export * from './src/env-utils';
4
- export * from './src/error-utils';
5
- export * from './src/isset';
6
- export * from './src/logger-utils';
7
- export * from './src/loop-utils';
8
- export * from './src/math-utils';
9
- export * from './src/mongo-utils';
10
- export * from './src/object-utils';
11
- export * from './src/string-utils';
12
- export * from './src/wtf-utils';
13
- export * from './src/validation-utils';
14
- export * from './src/transaction-utils';
15
- export * from './src/timer-utils';
16
- export * from './src/is-empty';
17
- export * from './src/remove-circular-json-stringify';
18
- export * from './src/is-object';
19
- export * from './src/regexp-utils';
20
- export * from './src/private/error-handler';
21
- export { registerConfig } from './src/private/config';
22
- import { moyenne } from './src/math-utils';
23
- import { kebabCase, snakeCase } from './src/string-utils';
24
- import { shuffleArray, noDuplicateFilter } from './src/array-utils';
25
- import { issetOr, validator } from './src/validation-utils';
26
- import { objFilterUndefinedRecursive } from './src/object-utils';
27
- export declare const int: typeof parseInt;
28
- export declare const average: typeof moyenne;
29
- export declare const arrayUniqueValue: typeof noDuplicateFilter;
30
- export declare const JSONstringyParse: (o: any) => any;
31
- export declare const removeUndefinedKeys: typeof objFilterUndefinedRecursive;
32
- export declare const randomizeArray: typeof shuffleArray;
33
- export declare const dashCase: typeof kebabCase;
34
- export declare const underscoreCase: typeof snakeCase;
35
- export declare const required: typeof validator;
36
- export declare const orIsset: typeof issetOr;
package/dist/index.js DELETED
@@ -1,58 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.orIsset = exports.required = exports.underscoreCase = exports.dashCase = exports.randomizeArray = exports.removeUndefinedKeys = exports.JSONstringyParse = exports.arrayUniqueValue = exports.average = exports.int = exports.registerConfig = void 0;
18
- __exportStar(require("./src/array-utils"), exports);
19
- __exportStar(require("./src/date-utils"), exports);
20
- __exportStar(require("./src/env-utils"), exports);
21
- __exportStar(require("./src/error-utils"), exports);
22
- __exportStar(require("./src/isset"), exports);
23
- __exportStar(require("./src/logger-utils"), exports);
24
- __exportStar(require("./src/loop-utils"), exports);
25
- __exportStar(require("./src/math-utils"), exports);
26
- __exportStar(require("./src/mongo-utils"), exports);
27
- __exportStar(require("./src/object-utils"), exports);
28
- __exportStar(require("./src/string-utils"), exports);
29
- __exportStar(require("./src/wtf-utils"), exports);
30
- __exportStar(require("./src/validation-utils"), exports);
31
- __exportStar(require("./src/transaction-utils"), exports);
32
- __exportStar(require("./src/timer-utils"), exports);
33
- __exportStar(require("./src/is-empty"), exports);
34
- __exportStar(require("./src/remove-circular-json-stringify"), exports);
35
- __exportStar(require("./src/is-object"), exports);
36
- __exportStar(require("./src/regexp-utils"), exports);
37
- __exportStar(require("./src/private/error-handler"), exports);
38
- var config_1 = require("./src/private/config");
39
- Object.defineProperty(exports, "registerConfig", { enumerable: true, get: function () { return config_1.registerConfig; } });
40
- const math_utils_1 = require("./src/math-utils");
41
- const string_utils_1 = require("./src/string-utils");
42
- const array_utils_1 = require("./src/array-utils");
43
- const validation_utils_1 = require("./src/validation-utils");
44
- const object_utils_1 = require("./src/object-utils");
45
- const remove_circular_json_stringify_1 = require("./src/remove-circular-json-stringify");
46
- // ALIASES
47
- exports.int = parseInt;
48
- exports.average = math_utils_1.moyenne;
49
- exports.arrayUniqueValue = array_utils_1.noDuplicateFilter;
50
- const JSONstringyParse = o => JSON.parse((0, remove_circular_json_stringify_1.removeCircularJSONstringify)(o));
51
- exports.JSONstringyParse = JSONstringyParse;
52
- exports.removeUndefinedKeys = object_utils_1.objFilterUndefinedRecursive;
53
- exports.randomizeArray = array_utils_1.shuffleArray;
54
- exports.dashCase = string_utils_1.kebabCase;
55
- exports.underscoreCase = string_utils_1.snakeCase;
56
- exports.required = validation_utils_1.validator; // alias for readability
57
- exports.orIsset = validation_utils_1.issetOr;
58
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,mDAAgC;AAChC,kDAA+B;AAC/B,oDAAiC;AACjC,8CAA2B;AAC3B,qDAAkC;AAClC,mDAAgC;AAChC,mDAAgC;AAChC,oDAAiC;AACjC,qDAAkC;AAClC,qDAAkC;AAClC,kDAA+B;AAC/B,yDAAsC;AACtC,0DAAuC;AACvC,oDAAiC;AACjC,iDAA8B;AAC9B,uEAAoD;AACpD,kDAA+B;AAC/B,qDAAkC;AAClC,8DAA2C;AAC3C,+CAAqD;AAA5C,wGAAA,cAAc,OAAA;AAEvB,iDAA0C;AAC1C,qDAAyD;AACzD,mDAAmE;AACnE,6DAA2D;AAC3D,qDAAgE;AAChE,yFAAkF;AAElF,UAAU;AACG,QAAA,GAAG,GAAG,QAAQ,CAAA;AACd,QAAA,OAAO,GAAG,oBAAO,CAAA;AACjB,QAAA,gBAAgB,GAAG,+BAAiB,CAAA;AAC1C,MAAM,gBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAA,4DAA2B,EAAC,CAAC,CAAC,CAAC,CAAA;AAAlE,QAAA,gBAAgB,oBAAkD;AAClE,QAAA,mBAAmB,GAAG,0CAA2B,CAAA;AACjD,QAAA,cAAc,GAAG,0BAAY,CAAA;AAC7B,QAAA,QAAQ,GAAG,wBAAS,CAAA;AACpB,QAAA,cAAc,GAAG,wBAAS,CAAA;AAC1B,QAAA,QAAQ,GAAG,4BAAS,CAAA,CAAC,wBAAwB;AAC7C,QAAA,OAAO,GAAG,0BAAO,CAAA"}
@@ -1,56 +0,0 @@
1
- export declare function shuffleArray(array: any): any;
2
- /**
3
- * Maye sure obj[addr] is an array and push a value to it
4
- * @param {Object} obj parent object
5
- * @param {String} addr field name in parent
6
- * @param {Any} valToPush
7
- * @param {Boolean} onlyUniqueValues default:false; may be true or a comparision function; (a,b) => return true if they are the same like (a, b) => a.name === b.name
8
- * @return obj[addr] eventually processed by the callback
9
- */
10
- export declare function ensureIsArrayAndPush(obj: object, addr: string, valToPush: any, onlyUniqueValues: Function): any;
11
- /** If a string is provided, return it as array else return the value */
12
- export declare function strAsArray(arrOrStr: any): any;
13
- /** If not an array provided, return the array with the value
14
- * /!\ NOTE /!\ In case the value is null or undefined, it will return that value
15
- */
16
- export declare function asArray<T extends any[] | any>(item: T): T extends undefined ? undefined : T extends any[] ? T : T[];
17
- /** Array comparison
18
- * @return {object} { inCommon, notInB, notInA }
19
- */
20
- export declare function compareArrays(arrayA: any[], arrayB: any[], compare?: (a: any, b: any) => boolean): {
21
- inCommon: any[];
22
- notInB: any[];
23
- notInA: any[];
24
- };
25
- /**
26
- * @return [] only elements that are both in arrayA and arrayB
27
- */
28
- export declare function getArrayInCommon(arrayA?: any[], arrayB?: any[], compare?: (a: any, b: any) => boolean): any[];
29
- /**
30
- * @return [] only elements that are in arrayB and not in arrayA
31
- */
32
- export declare function getNotInArrayA(arrayA?: any[], arrayB?: any[], compare?: (a: any, b: any) => boolean): any[];
33
- /**
34
- * @return [] only elements that are in neither arrayA and arrayB
35
- */
36
- export declare function getArrayDiff(arrayA?: any[], arrayB?: any[], compare?: (a: any, b: any) => boolean): any[];
37
- /** filter duplicate values in an array
38
- * @param {function} comparisonFn default:(a, b) => a === b. A function that shall return true if two values are considered equal
39
- * @return {array|function}
40
- */
41
- export declare function noDuplicateFilter(arr: any, comparisonFn?: (a: any, b: any) => boolean): any[];
42
- /** Count number of occurence of item in array */
43
- export declare function arrayCount(item: any, arr: any[]): number;
44
- /**
45
- * Sort an array in an object of subArrays, no duplicate.
46
- * @param {Array} array
47
- * @param {function} getFieldFromItem (itemOfArray) => field[String|Number]
48
- * tell me how you want to sort your Array
49
- */
50
- export declare function arrayToObjectSorted(array: any, getFieldFromItem: any): {};
51
- /**
52
- * @param {Function} comparisonFunction default: (itemToPush, itemAlreadyInArray) => itemToPush === itemAlreadyInArray; comparison function to consider the added item duplicate
53
- */
54
- export declare function pushIfNotExist(arrayToPushInto: any, valueOrArrayOfValuesToBePushed: any, comparisonFunction?: (a: any, b: any) => boolean): any[];
55
- export declare function isNotEmptyArray(arr: any): boolean;
56
- export declare function randomItemInArray<T>(array: T[]): T;
@@ -1,138 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomItemInArray = exports.isNotEmptyArray = exports.pushIfNotExist = exports.arrayToObjectSorted = exports.arrayCount = exports.noDuplicateFilter = exports.getArrayDiff = exports.getNotInArrayA = exports.getArrayInCommon = exports.compareArrays = exports.asArray = exports.strAsArray = exports.ensureIsArrayAndPush = exports.shuffleArray = void 0;
4
- //----------------------------------------
5
- // ARRAY UTILS
6
- //----------------------------------------
7
- const object_utils_1 = require("./object-utils");
8
- const isset_1 = require("./isset");
9
- function shuffleArray(array) {
10
- for (let i = array.length - 1; i > 0; i--) {
11
- const j = Math.floor(Math.random() * (i + 1));
12
- [array[i], array[j]] = [array[j], array[i]];
13
- }
14
- return array;
15
- }
16
- exports.shuffleArray = shuffleArray;
17
- /**
18
- * Maye sure obj[addr] is an array and push a value to it
19
- * @param {Object} obj parent object
20
- * @param {String} addr field name in parent
21
- * @param {Any} valToPush
22
- * @param {Boolean} onlyUniqueValues default:false; may be true or a comparision function; (a,b) => return true if they are the same like (a, b) => a.name === b.name
23
- * @return obj[addr] eventually processed by the callback
24
- */
25
- function ensureIsArrayAndPush(obj, addr, valToPush, onlyUniqueValues) {
26
- return (0, object_utils_1.ensureObjectProp)(obj, addr, [], objValue => {
27
- if ((0, isset_1.isset)(onlyUniqueValues)) {
28
- let duplicateFound = false;
29
- if (typeof onlyUniqueValues === 'function')
30
- duplicateFound = objValue.some(a => onlyUniqueValues(a, valToPush));
31
- else
32
- duplicateFound = objValue.includes(valToPush);
33
- if (!duplicateFound)
34
- objValue.push(valToPush);
35
- }
36
- else
37
- objValue.push(valToPush);
38
- });
39
- }
40
- exports.ensureIsArrayAndPush = ensureIsArrayAndPush;
41
- /** If a string is provided, return it as array else return the value */
42
- function strAsArray(arrOrStr) {
43
- return typeof arrOrStr === 'string' ? [arrOrStr] : arrOrStr;
44
- }
45
- exports.strAsArray = strAsArray;
46
- /** If not an array provided, return the array with the value
47
- * /!\ NOTE /!\ In case the value is null or undefined, it will return that value
48
- */
49
- function asArray(item) {
50
- return (typeof item === 'undefined' ? item : Array.isArray(item) ? item : [item]);
51
- }
52
- exports.asArray = asArray;
53
- /** Array comparison
54
- * @return {object} { inCommon, notInB, notInA }
55
- */
56
- function compareArrays(arrayA, arrayB, compare = (a, b) => a === b) {
57
- return {
58
- inCommon: getArrayInCommon(arrayA, arrayB, compare),
59
- notInB: getNotInArrayA(arrayB, arrayA, compare),
60
- notInA: getNotInArrayA(arrayA, arrayB, compare),
61
- };
62
- }
63
- exports.compareArrays = compareArrays;
64
- /**
65
- * @return [] only elements that are both in arrayA and arrayB
66
- */
67
- function getArrayInCommon(arrayA = [], arrayB = [], compare = (a, b) => a === b) {
68
- if (!Array.isArray(arrayA) || !Array.isArray(arrayB))
69
- return [];
70
- else
71
- return arrayA.filter(a => arrayB.some(b => compare(a, b)));
72
- }
73
- exports.getArrayInCommon = getArrayInCommon;
74
- /**
75
- * @return [] only elements that are in arrayB and not in arrayA
76
- */
77
- function getNotInArrayA(arrayA = [], arrayB = [], compare = (a, b) => a === b) {
78
- if (!Array.isArray(arrayA) && Array.isArray(arrayB))
79
- return arrayB;
80
- else if (!Array.isArray(arrayB))
81
- return [];
82
- else
83
- return arrayB.filter(b => !arrayA.some(a => compare(a, b)));
84
- }
85
- exports.getNotInArrayA = getNotInArrayA;
86
- /**
87
- * @return [] only elements that are in neither arrayA and arrayB
88
- */
89
- function getArrayDiff(arrayA = [], arrayB = [], compare = (a, b) => a === b) {
90
- return [...getNotInArrayA(arrayA, arrayB, compare), ...getNotInArrayA(arrayB, arrayA, compare)];
91
- }
92
- exports.getArrayDiff = getArrayDiff;
93
- /** filter duplicate values in an array
94
- * @param {function} comparisonFn default:(a, b) => a === b. A function that shall return true if two values are considered equal
95
- * @return {array|function}
96
- */
97
- function noDuplicateFilter(arr, comparisonFn = (a, b) => a === b) {
98
- return arr.filter((a, i, arr) => arr.findIndex(b => comparisonFn(a, b)) === i);
99
- }
100
- exports.noDuplicateFilter = noDuplicateFilter;
101
- /** Count number of occurence of item in array */
102
- function arrayCount(item, arr) {
103
- return arr.reduce((total, item2) => item === item2 ? total + 1 : total, 0);
104
- }
105
- exports.arrayCount = arrayCount;
106
- /**
107
- * Sort an array in an object of subArrays, no duplicate.
108
- * @param {Array} array
109
- * @param {function} getFieldFromItem (itemOfArray) => field[String|Number]
110
- * tell me how you want to sort your Array
111
- */
112
- function arrayToObjectSorted(array, getFieldFromItem) {
113
- const res = {};
114
- array.forEach(item => {
115
- (0, object_utils_1.objForceWriteIfNotSet)(res, getFieldFromItem(item), []);
116
- res[getFieldFromItem(item)].push(item);
117
- });
118
- return res;
119
- }
120
- exports.arrayToObjectSorted = arrayToObjectSorted;
121
- /**
122
- * @param {Function} comparisonFunction default: (itemToPush, itemAlreadyInArray) => itemToPush === itemAlreadyInArray; comparison function to consider the added item duplicate
123
- */
124
- function pushIfNotExist(arrayToPushInto, valueOrArrayOfValuesToBePushed, comparisonFunction = (a, b) => a === b) {
125
- const valuesToPush = asArray(valueOrArrayOfValuesToBePushed).filter(a => !arrayToPushInto.some(b => comparisonFunction(a, b)));
126
- arrayToPushInto.push(...valuesToPush);
127
- return arrayToPushInto;
128
- }
129
- exports.pushIfNotExist = pushIfNotExist;
130
- function isNotEmptyArray(arr) {
131
- return Array.isArray(arr) && !!arr.length;
132
- }
133
- exports.isNotEmptyArray = isNotEmptyArray;
134
- function randomItemInArray(array) {
135
- return array[Math.floor(Math.random() * array.length)];
136
- }
137
- exports.randomItemInArray = randomItemInArray;
138
- //# sourceMappingURL=array-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"array-utils.js","sourceRoot":"","sources":["../../src/array-utils.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,cAAc;AACd,0CAA0C;AAC1C,iDAAwE;AACxE,mCAA+B;AAE/B,SAAgB,YAAY,CAAC,KAAK;IAC9B,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QACvC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;KAC9C;IACD,OAAO,KAAK,CAAA;AAChB,CAAC;AAND,oCAMC;AAGD;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAAC,GAAW,EAAE,IAAY,EAAE,SAAS,EAAE,gBAA0B;IACjG,OAAO,IAAA,+BAAgB,EAAC,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ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;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,eAAe,EAAE,8BAA8B,EAAE,kBAAkB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC;IAClH,MAAM,YAAY,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9H,eAAe,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAA;IACrC,OAAO,eAAe,CAAA;AAC1B,CAAC;AAJD,wCAIC;AAED,SAAgB,eAAe,CAAC,GAAG;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAA;AAC7C,CAAC;AAFD,0CAEC;AAED,SAAgB,iBAAiB,CAAI,KAAU;IAC3C,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;AAC1D,CAAC;AAFD,8CAEC"}
@@ -1,100 +0,0 @@
1
- export declare function getDateAsInt12(dateAllFormat?: Date | string | number, errIfNotValid?: any): string;
2
- export declare function humanReadableTimestamp(dateAllFormat: any): number;
3
- /** format for 6/8/2018 => 20180806
4
- * @param dateAllFormat multiple format allowed 2012, 20120101, 201201011200, new Date(), "2019-12-08T16:19:10.341Z" and all string that new Date() can parse
5
- */
6
- export declare function getDateAsInt(dateAllFormat?: Date | string | number, errIfNotValid$?: boolean, withHoursAndMinutes$?: boolean): string;
7
- export declare function getMonthAsInt(dateAllFormat?: Date | string | number): number;
8
- /**
9
- * @param dateAllFormat multiple format allowed 2012, 20120101, 201201011200, new Date(), "2019-12-08T16:19:10.341Z" and all string that new Date() can parse
10
- */
11
- export declare function getDateAsObject(dateAllFormat?: any, errIfNotValid$?: boolean): Date;
12
- /** [2018,01,06] */
13
- export declare function dateStringToArray(strOrInt: any): any[];
14
- /**
15
- * @param dateAllFormat default: actualDate
16
- * @returns ['01', '01', '2019'] OR **string** if separator is provided */
17
- export declare function dateArray(dateAllFormat?: Date | string | number): [string, string, string];
18
- /**
19
- * @param dateAllFormat default: actualDate
20
- * @returns ['01', '01', '2019'] OR **string** if separator is provided */
21
- export declare function dateArrayInt(dateAllFormat?: Date | string | number): [number, number, number];
22
- /**
23
- * @return 01/01/2012 (alias of dateArrayFormatted(date, '/'))
24
- */
25
- export declare function dateFormatted(dateAllFormat: Date | string | number, separator?: string): string;
26
- /** Date with custom offset (Ex: +2 for France) */
27
- export declare function dateOffset(offsetHours: any, dateObj?: Date): Date;
28
- /** */
29
- export declare function getTimeAsInt(timeOrDateInt?: any): number | "dateInvalid";
30
- /**
31
- * @param {timeInt|dateInt12} Eg: 2222 OR 201201012222. Default, actual dateInt12
32
- * @param {String} separator default: ":"
33
- */
34
- export declare function getIntAsTime(intOrDateTimeInt?: string, separator?: string): string;
35
- export declare function isTimeStringValid(timeStr: any, outputAnError$?: boolean): boolean;
36
- export declare function getDuration(startDate: any, endDate: any, inMinutes?: boolean): number | number[];
37
- /** compare two object with DATE INT, if they overlap return true
38
- * @param {Object} event1 {startDate, endDate}
39
- * @param {Object} event2 {startDate, endDate}
40
- * @param {String} fieldNameForStartDate$ replace startDate with this string
41
- * @param {String} fieldNameForEndDate$ replace endDate with this string
42
- * @param {Boolean} allowNull$ if false, retrun false if any of the startdates or enddates are not set
43
- * @param {Boolean} strict$ if true,
44
- */
45
- export declare function doDateOverlap(event1: any, event2: any, fieldNameForStartDate$?: string, fieldNameForEndDate$?: string, allowNull$?: boolean, strict$?: boolean): boolean;
46
- declare type DateAllFormat = DateObjectFormat | DateStringFormats;
47
- declare type DateStringFormats = 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp';
48
- declare type DateObjectFormat = 'date';
49
- export declare function nextWeekDay(fromDate: any, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat?: DateStringFormats, sameDayAllowed?: boolean): number;
50
- export declare function nextWeekDay(fromDate: any, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat?: DateObjectFormat, sameDayAllowed?: boolean): Date;
51
- /**
52
- * @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
53
- */
54
- export declare function addDays(dateAllFormat?: Date | string | number, numberOfDays?: number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string;
55
- export declare function addDays(dateAllFormat?: Date | string | number, numberOfDays?: number, outputFormat?: 'date'): Date;
56
- /**
57
- * @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
58
- */
59
- export declare function addMinutes(dateAllFormat?: Date | string | number, numberOfMinutes?: number, outputFormat?: DateStringFormats): string;
60
- export declare function addMinutes(dateAllFormat?: Date | string | number, numberOfMinutes?: number, outputFormat?: DateObjectFormat): Date;
61
- /**
62
- * @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
63
- */
64
- export declare function addHours(dateAllFormat?: Date | string | number, numberOfHours?: number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string;
65
- export declare function addHours(dateAllFormat?: Date | string | number, numberOfHours?: number, outputFormat?: 'date'): Date;
66
- /**
67
- * @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
68
- */
69
- export declare function addMonths(dateAllFormat?: Date | string | number, numberOfMonths?: number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string;
70
- export declare function addMonths(dateAllFormat?: Date | string | number, numberOfMonths?: number, outputFormat?: 'date'): Date;
71
- /**
72
- * @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
73
- */
74
- export declare function addYears(dateAllFormat?: Date | string | number, numberOfYears?: number, outputFormat?: DateAllFormat): Date;
75
- export declare function getDayOfMonth(dateAllFormat?: Date | string | number): any;
76
- export declare function getYear(dateAllFormat?: Date | string | number): any;
77
- export declare function getHours(dateAllFormat?: Date | string | number): any;
78
- export declare function getMinutes(dateAllFormat?: Date | string | number): any;
79
- /**
80
- * @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
81
- */
82
- export declare function lastDayOfMonth(dateAllFormat?: Date | string | number, outputFormat?: DateAllFormat): Date;
83
- /**
84
- * @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
85
- */
86
- export declare function firstDayOfMonth(dateAllFormat?: Date | string | number, outputFormat?: DateAllFormat): Date;
87
- export declare function differenceInMilliseconds(startDateAllFormat: any, endDateAllFormat: any): number;
88
- export declare function differenceInSeconds(startDateAllFormat: any, endDateAllFormat: any): number;
89
- export declare function differenceInMinutes(startDateAllFormat: any, endDateAllFormat: any): number;
90
- export declare function differenceInHours(startDateAllFormat: any, endDateAllFormat: any): number;
91
- export declare function differenceInDays(startDateAllFormat: any, endDateAllFormat: any): number;
92
- export declare function differenceInWeeks(startDateAllFormat: any, endDateAllFormat: any): number;
93
- /**
94
- * @param {String} outputDateFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
95
- */
96
- export declare function getDateAs(dateAllFormat?: Date | string | number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string;
97
- export declare function getDateAs(dateAllFormat?: Date | string | number, outputFormat?: 'date'): Date;
98
- export declare function isDateIntOrStringValid(dateStringOrInt: any, outputAnError?: boolean, length?: any): boolean;
99
- export declare function isDateIsoOrObjectValid(dateIsoOrObj: any, outputAnError?: boolean): boolean;
100
- export {};