@slickgrid-universal/utils 1.3.0

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2020-2022, Ghislain B. - Slickgrid-Universal
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
2
+ [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
3
+ [![lerna--lite](https://img.shields.io/badge/maintained%20with-lerna--lite-d428ff)](https://github.com/ghiscoding/lerna-lite)
4
+ [![npm](https://img.shields.io/npm/v/@slickgrid-universal/utils.svg?color=forest)](https://www.npmjs.com/package/@slickgrid-universal/utils)
5
+ [![npm](https://img.shields.io/npm/dy/@slickgrid-universal/utils?color=forest)](https://www.npmjs.com/package/@slickgrid-universal/utils)
6
+
7
+ [![Actions Status](https://github.com/ghiscoding/slickgrid-universal/workflows/CI%20Build/badge.svg)](https://github.com/ghiscoding/slickgrid-universal/actions)
8
+ [![Cypress.io](https://img.shields.io/badge/tested%20with-Cypress-04C38E.svg)](https://www.cypress.io/)
9
+ [![jest](https://jestjs.io/img/jest-badge.svg)](https://github.com/facebook/jest)
10
+ [![codecov](https://codecov.io/gh/ghiscoding/slickgrid-universal/branch/master/graph/badge.svg)](https://codecov.io/gh/ghiscoding/slickgrid-universal)
11
+
12
+ ## Common Utils
13
+ #### @slickgrid-universal/utils
14
+
15
+ A set of small common utils that can be installed separately and that do not have any dependencies.
16
+
17
+ ### External Dependencies
18
+ - [DOM Purify](https://github.com/cure53/DOMPurify) to sanitize HTML text
19
+
20
+ ### Installation
21
+ Follow the instruction provided in the main [README](https://github.com/ghiscoding/slickgrid-universal#installation)
@@ -0,0 +1 @@
1
+ export * from './utils';
@@ -0,0 +1,18 @@
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
+ __exportStar(require("./utils"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Add an item to an array only when the item does not exists, when the item is an object we will be using their "id" to compare
3
+ * @param inputArray
4
+ * @param inputItem
5
+ * @param itemIdPropName
6
+ */
7
+ export declare function addToArrayWhenNotExists<T = any>(inputArray: T[], inputItem: T, itemIdPropName?: string): void;
8
+ /**
9
+ * Simple function to which will loop and create as demanded the number of white spaces,
10
+ * this is used in the CSV export
11
+ * @param {Number} nbSpaces - number of white spaces to create
12
+ * @param {String} spaceChar - optionally provide character to use as a space (could be override to use &nbsp; in html)
13
+ */
14
+ export declare function addWhiteSpaces(nbSpaces: number, spaceChar?: string): string;
15
+ /**
16
+ * Remove a column from the grid by it's index in the grid
17
+ * @param array input
18
+ * @param index
19
+ */
20
+ export declare function arrayRemoveItemByIndex<T>(array: T[], index: number): T[];
21
+ /**
22
+ * Create an immutable clone of an array or object
23
+ * (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com
24
+ * @param {Array|Object} objectOrArray - the array or object to copy
25
+ * @return {Array|Object} - the clone of the array or object
26
+ */
27
+ export declare function deepCopy(objectOrArray: any | any[]): any | any[];
28
+ /**
29
+ * Performs a deep merge of objects and returns new object, it does not modify the source object, objects (immutable) and merges arrays via concatenation.
30
+ * Also, if first argument is undefined/null but next argument is an object then it will proceed and output will be an object
31
+ * @param {...object} objects - Objects to merge
32
+ * @returns {object} New object with merged key/values
33
+ */
34
+ export declare function deepMerge(target: any, ...sources: any[]): any;
35
+ /**
36
+ * Empty an object properties by looping through them all and deleting them
37
+ * @param obj - input object
38
+ */
39
+ export declare function emptyObject(obj: any): any;
40
+ /**
41
+ * Check if an object is empty
42
+ * @param obj - input object
43
+ * @returns - boolean
44
+ */
45
+ export declare function isEmptyObject(obj: any): boolean;
46
+ /**
47
+ * Simple object check.
48
+ * @param item
49
+ * @returns {boolean}
50
+ */
51
+ export declare function isObject(item: any): any;
52
+ /** Check if a value has any data (undefined, null or empty string will return false... but false boolean is consider as valid data) */
53
+ export declare function hasData(value: any): boolean;
54
+ /**
55
+ * Check if input value is a number, by default it won't be a strict checking
56
+ * but optionally we could check for strict equality, for example in strict "3" will return False but without strict it will return True
57
+ * @param value - input value of any type
58
+ * @param strict - when using strict it also check for strict equality, for example in strict "3" would return False but without strict it would return True
59
+ */
60
+ export declare function isNumber(value: any, strict?: boolean): boolean;
61
+ /** Check if an object is empty, it will also be considered empty when the input is null, undefined or isn't an object */
62
+ export declare function isObjectEmpty(obj: unknown): unknown;
63
+ /** Parse any input (bool, number, string) and return a boolean or False when not possible */
64
+ export declare function parseBoolean(input: any): boolean;
65
+ /**
66
+ * Remove any accents from a string by normalizing it
67
+ * @param {String} text - input text
68
+ * @param {Boolean} shouldLowerCase - should we also lowercase the string output?
69
+ * @returns
70
+ */
71
+ export declare function removeAccentFromText(text: string, shouldLowerCase?: boolean): string;
72
+ /** Set the object value of deeper node from a given dot (.) notation path (e.g.: "user.firstName") */
73
+ export declare function setDeepValue<T = any>(obj: T, path: string | string[], value: any): void;
74
+ /**
75
+ * Title case (or capitalize) first char of a string, for example "hello world" will become "Hello world"
76
+ * Change the string to be title case on the complete sentence (upper case first char of each word while changing everything else to lower case)
77
+ * @param inputStr
78
+ * @returns string
79
+ */
80
+ export declare function titleCase(inputStr: string, shouldTitleCaseEveryWords?: boolean): string;
81
+ /**
82
+ * Converts a string to camel case (camelCase), for example "hello-world" (or "hellow world") will become "helloWorld"
83
+ * @param inputStr the string to convert
84
+ * @return the string in camel case
85
+ */
86
+ export declare function toCamelCase(inputStr: string): string;
87
+ /**
88
+ * Converts a string to kebab (hypen) case, for example "helloWorld" will become "hello-world"
89
+ * @param str the string to convert
90
+ * @return the string in kebab case
91
+ */
92
+ export declare function toKebabCase(inputStr: string): string;
93
+ /**
94
+ * Converts a camelCase or kebab-case string to a sentence case, for example "helloWorld" will become "Hello World" and "hello-world" will become "Hello world"
95
+ * @param str the string to convert
96
+ * @return the string in kebab case
97
+ */
98
+ export declare function toSentenceCase(inputStr: string): string;
99
+ /**
100
+ * Converts a string from camelCase to snake_case (underscore) case
101
+ * @param str the string to convert
102
+ * @return the string in kebab case
103
+ */
104
+ export declare function toSnakeCase(inputStr: string): string;
105
+ /**
106
+ * Takes an input array and makes sure the array has unique values by removing duplicates
107
+ * @param array input with possible duplicates
108
+ * @return array output without duplicates
109
+ */
110
+ export declare function uniqueArray<T = any>(arr: T[]): T[];
111
+ /**
112
+ * Takes an input array of objects and makes sure the array has unique object values by removing duplicates
113
+ * it will loop through the array using a property name (or "id" when is not provided) to compare uniqueness
114
+ * @param array input with possible duplicates
115
+ * @param propertyName defaults to "id"
116
+ * @return array output without duplicates
117
+ */
118
+ export declare function uniqueObjectArray(arr: any[], propertyName?: string): any[];
@@ -0,0 +1,339 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uniqueObjectArray = exports.uniqueArray = exports.toSnakeCase = exports.toSentenceCase = exports.toKebabCase = exports.toCamelCase = exports.titleCase = exports.setDeepValue = exports.removeAccentFromText = exports.parseBoolean = exports.isObjectEmpty = exports.isNumber = exports.hasData = exports.isObject = exports.isEmptyObject = exports.emptyObject = exports.deepMerge = exports.deepCopy = exports.arrayRemoveItemByIndex = exports.addWhiteSpaces = exports.addToArrayWhenNotExists = void 0;
4
+ /**
5
+ * Add an item to an array only when the item does not exists, when the item is an object we will be using their "id" to compare
6
+ * @param inputArray
7
+ * @param inputItem
8
+ * @param itemIdPropName
9
+ */
10
+ function addToArrayWhenNotExists(inputArray, inputItem, itemIdPropName = 'id') {
11
+ let arrayRowIndex = -1;
12
+ if (typeof inputItem === 'object' && itemIdPropName in inputItem) {
13
+ arrayRowIndex = inputArray.findIndex((item) => item[itemIdPropName] === inputItem[itemIdPropName]);
14
+ }
15
+ else {
16
+ arrayRowIndex = inputArray.findIndex((item) => item === inputItem);
17
+ }
18
+ if (arrayRowIndex < 0) {
19
+ inputArray.push(inputItem);
20
+ }
21
+ }
22
+ exports.addToArrayWhenNotExists = addToArrayWhenNotExists;
23
+ /**
24
+ * Simple function to which will loop and create as demanded the number of white spaces,
25
+ * this is used in the CSV export
26
+ * @param {Number} nbSpaces - number of white spaces to create
27
+ * @param {String} spaceChar - optionally provide character to use as a space (could be override to use &nbsp; in html)
28
+ */
29
+ function addWhiteSpaces(nbSpaces, spaceChar = ' ') {
30
+ let result = '';
31
+ for (let i = 0; i < nbSpaces; i++) {
32
+ result += spaceChar;
33
+ }
34
+ return result;
35
+ }
36
+ exports.addWhiteSpaces = addWhiteSpaces;
37
+ /**
38
+ * Remove a column from the grid by it's index in the grid
39
+ * @param array input
40
+ * @param index
41
+ */
42
+ function arrayRemoveItemByIndex(array, index) {
43
+ return array.filter((_el, i) => index !== i);
44
+ }
45
+ exports.arrayRemoveItemByIndex = arrayRemoveItemByIndex;
46
+ /**
47
+ * Create an immutable clone of an array or object
48
+ * (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com
49
+ * @param {Array|Object} objectOrArray - the array or object to copy
50
+ * @return {Array|Object} - the clone of the array or object
51
+ */
52
+ function deepCopy(objectOrArray) {
53
+ /**
54
+ * Create an immutable copy of an object
55
+ * @return {Object}
56
+ */
57
+ const cloneObj = () => {
58
+ // Create new object
59
+ const clone = {};
60
+ // Loop through each item in the original
61
+ // Recursively copy it's value and add to the clone
62
+ for (const key in objectOrArray) {
63
+ if (Object.prototype.hasOwnProperty.call(objectOrArray, key)) {
64
+ clone[key] = deepCopy(objectOrArray[key]);
65
+ }
66
+ }
67
+ return clone;
68
+ };
69
+ /**
70
+ * Create an immutable copy of an array
71
+ * @return {Array}
72
+ */
73
+ const cloneArr = () => objectOrArray.map((item) => deepCopy(item));
74
+ // -- init --//
75
+ // Get object type
76
+ const type = Object.prototype.toString.call(objectOrArray).slice(8, -1).toLowerCase();
77
+ // If an object
78
+ if (type === 'object') {
79
+ return cloneObj();
80
+ }
81
+ // If an array
82
+ if (type === 'array') {
83
+ return cloneArr();
84
+ }
85
+ // Otherwise, return it as-is
86
+ return objectOrArray;
87
+ }
88
+ exports.deepCopy = deepCopy;
89
+ /**
90
+ * Performs a deep merge of objects and returns new object, it does not modify the source object, objects (immutable) and merges arrays via concatenation.
91
+ * Also, if first argument is undefined/null but next argument is an object then it will proceed and output will be an object
92
+ * @param {...object} objects - Objects to merge
93
+ * @returns {object} New object with merged key/values
94
+ */
95
+ function deepMerge(target, ...sources) {
96
+ if (!sources.length) {
97
+ return target;
98
+ }
99
+ const source = sources.shift();
100
+ // when target is not an object but source is an object, then we'll assign as object
101
+ target = (!isObject(target) && isObject(source)) ? {} : target;
102
+ if (isObject(target) && isObject(source)) {
103
+ for (const prop in source) {
104
+ if (source.hasOwnProperty(prop)) {
105
+ if (prop in target) {
106
+ // handling merging of two properties with equal names
107
+ if (typeof target[prop] !== 'object') {
108
+ target[prop] = source[prop];
109
+ }
110
+ else {
111
+ if (typeof source[prop] !== 'object') {
112
+ target[prop] = source[prop];
113
+ }
114
+ else {
115
+ if (target[prop].concat && source[prop].concat) {
116
+ // two arrays get concatenated
117
+ target[prop] = target[prop].concat(source[prop]);
118
+ }
119
+ else {
120
+ // two objects get merged recursively
121
+ target[prop] = deepMerge(target[prop], source[prop]);
122
+ }
123
+ }
124
+ }
125
+ }
126
+ else {
127
+ // new properties get added to target
128
+ target[prop] = source[prop];
129
+ }
130
+ }
131
+ }
132
+ }
133
+ return deepMerge(target, ...sources);
134
+ }
135
+ exports.deepMerge = deepMerge;
136
+ /**
137
+ * Empty an object properties by looping through them all and deleting them
138
+ * @param obj - input object
139
+ */
140
+ function emptyObject(obj) {
141
+ for (const key in obj) {
142
+ if (obj.hasOwnProperty(key)) {
143
+ delete obj[key];
144
+ }
145
+ }
146
+ obj = null;
147
+ obj = {};
148
+ return obj;
149
+ }
150
+ exports.emptyObject = emptyObject;
151
+ /**
152
+ * Check if an object is empty
153
+ * @param obj - input object
154
+ * @returns - boolean
155
+ */
156
+ function isEmptyObject(obj) {
157
+ if (obj === null || obj === undefined) {
158
+ return true;
159
+ }
160
+ return Object.entries(obj).length === 0;
161
+ }
162
+ exports.isEmptyObject = isEmptyObject;
163
+ /**
164
+ * Simple object check.
165
+ * @param item
166
+ * @returns {boolean}
167
+ */
168
+ function isObject(item) {
169
+ return (item && typeof item === 'object' && !Array.isArray(item));
170
+ }
171
+ exports.isObject = isObject;
172
+ /** Check if a value has any data (undefined, null or empty string will return false... but false boolean is consider as valid data) */
173
+ function hasData(value) {
174
+ return value !== undefined && value !== null && value !== '';
175
+ }
176
+ exports.hasData = hasData;
177
+ /**
178
+ * Check if input value is a number, by default it won't be a strict checking
179
+ * but optionally we could check for strict equality, for example in strict "3" will return False but without strict it will return True
180
+ * @param value - input value of any type
181
+ * @param strict - when using strict it also check for strict equality, for example in strict "3" would return False but without strict it would return True
182
+ */
183
+ function isNumber(value, strict = false) {
184
+ if (strict) {
185
+ return (value === null || value === undefined || typeof value === 'string') ? false : !isNaN(value);
186
+ }
187
+ return (value === null || value === undefined || value === '') ? false : !isNaN(+value);
188
+ }
189
+ exports.isNumber = isNumber;
190
+ /** Check if an object is empty, it will also be considered empty when the input is null, undefined or isn't an object */
191
+ function isObjectEmpty(obj) {
192
+ return !obj || (obj && typeof obj === 'object' && Object.keys(obj).length === 0);
193
+ }
194
+ exports.isObjectEmpty = isObjectEmpty;
195
+ /** Parse any input (bool, number, string) and return a boolean or False when not possible */
196
+ function parseBoolean(input) {
197
+ return /(true|1)/i.test(input + '');
198
+ }
199
+ exports.parseBoolean = parseBoolean;
200
+ /**
201
+ * Remove any accents from a string by normalizing it
202
+ * @param {String} text - input text
203
+ * @param {Boolean} shouldLowerCase - should we also lowercase the string output?
204
+ * @returns
205
+ */
206
+ function removeAccentFromText(text, shouldLowerCase = false) {
207
+ const normalizedText = (typeof text.normalize === 'function') ? text.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : text;
208
+ return shouldLowerCase ? normalizedText.toLowerCase() : normalizedText;
209
+ }
210
+ exports.removeAccentFromText = removeAccentFromText;
211
+ /** Set the object value of deeper node from a given dot (.) notation path (e.g.: "user.firstName") */
212
+ function setDeepValue(obj, path, value) {
213
+ if (typeof path === 'string') {
214
+ path = path.split('.');
215
+ }
216
+ if (path.length > 1) {
217
+ const e = path.shift();
218
+ if (obj && e !== undefined) {
219
+ setDeepValue(obj[e] = Object.prototype.toString.call(obj[e]) === '[object Object]' ? obj[e] : {}, path, value);
220
+ }
221
+ }
222
+ else if (obj && path[0]) {
223
+ obj[path[0]] = value;
224
+ }
225
+ }
226
+ exports.setDeepValue = setDeepValue;
227
+ /**
228
+ * Title case (or capitalize) first char of a string, for example "hello world" will become "Hello world"
229
+ * Change the string to be title case on the complete sentence (upper case first char of each word while changing everything else to lower case)
230
+ * @param inputStr
231
+ * @returns string
232
+ */
233
+ function titleCase(inputStr, shouldTitleCaseEveryWords = false) {
234
+ if (typeof inputStr === 'string') {
235
+ if (shouldTitleCaseEveryWords) {
236
+ return inputStr.replace(/\w\S*/g, (outputStr) => {
237
+ return outputStr.charAt(0).toUpperCase() + outputStr.substr(1).toLowerCase();
238
+ });
239
+ }
240
+ return inputStr.charAt(0).toUpperCase() + inputStr.slice(1);
241
+ }
242
+ return inputStr;
243
+ }
244
+ exports.titleCase = titleCase;
245
+ /**
246
+ * Converts a string to camel case (camelCase), for example "hello-world" (or "hellow world") will become "helloWorld"
247
+ * @param inputStr the string to convert
248
+ * @return the string in camel case
249
+ */
250
+ function toCamelCase(inputStr) {
251
+ if (typeof inputStr === 'string') {
252
+ return inputStr.replace(/(?:^\w|[A-Z]|\b\w|[\s+\-_\/])/g, (match, offset) => {
253
+ // remove white space or hypens or underscores
254
+ if (/[\s+\-_\/]/.test(match)) {
255
+ return '';
256
+ }
257
+ return offset === 0 ? match.toLowerCase() : match.toUpperCase();
258
+ });
259
+ }
260
+ return inputStr;
261
+ }
262
+ exports.toCamelCase = toCamelCase;
263
+ /**
264
+ * Converts a string to kebab (hypen) case, for example "helloWorld" will become "hello-world"
265
+ * @param str the string to convert
266
+ * @return the string in kebab case
267
+ */
268
+ function toKebabCase(inputStr) {
269
+ if (typeof inputStr === 'string') {
270
+ return toCamelCase(inputStr).replace(/([A-Z])/g, '-$1').toLowerCase();
271
+ }
272
+ return inputStr;
273
+ }
274
+ exports.toKebabCase = toKebabCase;
275
+ /**
276
+ * Converts a camelCase or kebab-case string to a sentence case, for example "helloWorld" will become "Hello World" and "hello-world" will become "Hello world"
277
+ * @param str the string to convert
278
+ * @return the string in kebab case
279
+ */
280
+ function toSentenceCase(inputStr) {
281
+ if (typeof inputStr === 'string') {
282
+ const result = inputStr.replace(/([A-Z])|(\-)/g, ' $1').replace(/\s+/g, ' ').trim();
283
+ return result.charAt(0).toUpperCase() + result.slice(1);
284
+ }
285
+ return inputStr;
286
+ }
287
+ exports.toSentenceCase = toSentenceCase;
288
+ /**
289
+ * Converts a string from camelCase to snake_case (underscore) case
290
+ * @param str the string to convert
291
+ * @return the string in kebab case
292
+ */
293
+ function toSnakeCase(inputStr) {
294
+ if (typeof inputStr === 'string') {
295
+ return toCamelCase(inputStr).replace(/([A-Z])/g, '_$1').toLowerCase();
296
+ }
297
+ return inputStr;
298
+ }
299
+ exports.toSnakeCase = toSnakeCase;
300
+ /**
301
+ * Takes an input array and makes sure the array has unique values by removing duplicates
302
+ * @param array input with possible duplicates
303
+ * @return array output without duplicates
304
+ */
305
+ function uniqueArray(arr) {
306
+ if (Array.isArray(arr) && arr.length > 0) {
307
+ return arr.filter((item, index) => {
308
+ return arr.indexOf(item) >= index;
309
+ });
310
+ }
311
+ return arr;
312
+ }
313
+ exports.uniqueArray = uniqueArray;
314
+ /**
315
+ * Takes an input array of objects and makes sure the array has unique object values by removing duplicates
316
+ * it will loop through the array using a property name (or "id" when is not provided) to compare uniqueness
317
+ * @param array input with possible duplicates
318
+ * @param propertyName defaults to "id"
319
+ * @return array output without duplicates
320
+ */
321
+ function uniqueObjectArray(arr, propertyName = 'id') {
322
+ if (Array.isArray(arr) && arr.length > 0) {
323
+ const result = [];
324
+ const map = new Map();
325
+ for (const item of arr) {
326
+ if (item && !map.has(item[propertyName])) {
327
+ map.set(item[propertyName], true); // set any value to Map
328
+ result.push({
329
+ id: item[propertyName],
330
+ name: item.name
331
+ });
332
+ }
333
+ }
334
+ return result;
335
+ }
336
+ return arr;
337
+ }
338
+ exports.uniqueObjectArray = uniqueObjectArray;
339
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAU,UAAe,EAAE,SAAY,EAAE,cAAc,GAAG,IAAI;IACnG,IAAI,aAAa,GAAG,CAAC,CAAC,CAAC;IACvB,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,cAAc,IAAI,SAAS,EAAE;QAChE,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAE,IAAY,CAAC,cAAc,CAAC,KAAM,SAAiB,CAAC,cAAc,CAAC,CAAC,CAAC;KACtH;SAAM;QACL,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;KACpE;IAED,IAAI,aAAa,GAAG,CAAC,EAAE;QACrB,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAC5B;AACH,CAAC;AAXD,0DAWC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,QAAgB,EAAE,SAAS,GAAG,GAAG;IAC9D,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE;QACjC,MAAM,IAAI,SAAS,CAAC;KACrB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAPD,wCAOC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB,CAAI,KAAU,EAAE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kCAKC;AAED;;;;GAIG;AACH,SAAgB,WAAW,CAAU,GAAQ;IAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;QACxC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,IAAO,EAAE,KAAa,EAAE,EAAE;YAC3C,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC;QACpC,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAPD,kCAOC;AAED;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,GAAU,EAAE,YAAY,GAAG,IAAI;IAC/D,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;QACxC,MAAM,MAAM,GAAG,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;QAEtB,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE;YACtB,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE;gBACxC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,CAAC,CAAI,uBAAuB;gBAC7D,MAAM,CAAC,IAAI,CAAC;oBACV,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC;oBACtB,IAAI,EAAE,IAAI,CAAC,IAAI;iBAChB,CAAC,CAAC;aACJ;SACF;QACD,OAAO,MAAM,CAAC;KACf;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAjBD,8CAiBC"}
@@ -0,0 +1 @@
1
+ export * from './utils';
@@ -0,0 +1,2 @@
1
+ export * from './utils';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Add an item to an array only when the item does not exists, when the item is an object we will be using their "id" to compare
3
+ * @param inputArray
4
+ * @param inputItem
5
+ * @param itemIdPropName
6
+ */
7
+ export declare function addToArrayWhenNotExists<T = any>(inputArray: T[], inputItem: T, itemIdPropName?: string): void;
8
+ /**
9
+ * Simple function to which will loop and create as demanded the number of white spaces,
10
+ * this is used in the CSV export
11
+ * @param {Number} nbSpaces - number of white spaces to create
12
+ * @param {String} spaceChar - optionally provide character to use as a space (could be override to use &nbsp; in html)
13
+ */
14
+ export declare function addWhiteSpaces(nbSpaces: number, spaceChar?: string): string;
15
+ /**
16
+ * Remove a column from the grid by it's index in the grid
17
+ * @param array input
18
+ * @param index
19
+ */
20
+ export declare function arrayRemoveItemByIndex<T>(array: T[], index: number): T[];
21
+ /**
22
+ * Create an immutable clone of an array or object
23
+ * (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com
24
+ * @param {Array|Object} objectOrArray - the array or object to copy
25
+ * @return {Array|Object} - the clone of the array or object
26
+ */
27
+ export declare function deepCopy(objectOrArray: any | any[]): any | any[];
28
+ /**
29
+ * Performs a deep merge of objects and returns new object, it does not modify the source object, objects (immutable) and merges arrays via concatenation.
30
+ * Also, if first argument is undefined/null but next argument is an object then it will proceed and output will be an object
31
+ * @param {...object} objects - Objects to merge
32
+ * @returns {object} New object with merged key/values
33
+ */
34
+ export declare function deepMerge(target: any, ...sources: any[]): any;
35
+ /**
36
+ * Empty an object properties by looping through them all and deleting them
37
+ * @param obj - input object
38
+ */
39
+ export declare function emptyObject(obj: any): any;
40
+ /**
41
+ * Check if an object is empty
42
+ * @param obj - input object
43
+ * @returns - boolean
44
+ */
45
+ export declare function isEmptyObject(obj: any): boolean;
46
+ /**
47
+ * Simple object check.
48
+ * @param item
49
+ * @returns {boolean}
50
+ */
51
+ export declare function isObject(item: any): any;
52
+ /** Check if a value has any data (undefined, null or empty string will return false... but false boolean is consider as valid data) */
53
+ export declare function hasData(value: any): boolean;
54
+ /**
55
+ * Check if input value is a number, by default it won't be a strict checking
56
+ * but optionally we could check for strict equality, for example in strict "3" will return False but without strict it will return True
57
+ * @param value - input value of any type
58
+ * @param strict - when using strict it also check for strict equality, for example in strict "3" would return False but without strict it would return True
59
+ */
60
+ export declare function isNumber(value: any, strict?: boolean): boolean;
61
+ /** Check if an object is empty, it will also be considered empty when the input is null, undefined or isn't an object */
62
+ export declare function isObjectEmpty(obj: unknown): unknown;
63
+ /** Parse any input (bool, number, string) and return a boolean or False when not possible */
64
+ export declare function parseBoolean(input: any): boolean;
65
+ /**
66
+ * Remove any accents from a string by normalizing it
67
+ * @param {String} text - input text
68
+ * @param {Boolean} shouldLowerCase - should we also lowercase the string output?
69
+ * @returns
70
+ */
71
+ export declare function removeAccentFromText(text: string, shouldLowerCase?: boolean): string;
72
+ /** Set the object value of deeper node from a given dot (.) notation path (e.g.: "user.firstName") */
73
+ export declare function setDeepValue<T = any>(obj: T, path: string | string[], value: any): void;
74
+ /**
75
+ * Title case (or capitalize) first char of a string, for example "hello world" will become "Hello world"
76
+ * Change the string to be title case on the complete sentence (upper case first char of each word while changing everything else to lower case)
77
+ * @param inputStr
78
+ * @returns string
79
+ */
80
+ export declare function titleCase(inputStr: string, shouldTitleCaseEveryWords?: boolean): string;
81
+ /**
82
+ * Converts a string to camel case (camelCase), for example "hello-world" (or "hellow world") will become "helloWorld"
83
+ * @param inputStr the string to convert
84
+ * @return the string in camel case
85
+ */
86
+ export declare function toCamelCase(inputStr: string): string;
87
+ /**
88
+ * Converts a string to kebab (hypen) case, for example "helloWorld" will become "hello-world"
89
+ * @param str the string to convert
90
+ * @return the string in kebab case
91
+ */
92
+ export declare function toKebabCase(inputStr: string): string;
93
+ /**
94
+ * Converts a camelCase or kebab-case string to a sentence case, for example "helloWorld" will become "Hello World" and "hello-world" will become "Hello world"
95
+ * @param str the string to convert
96
+ * @return the string in kebab case
97
+ */
98
+ export declare function toSentenceCase(inputStr: string): string;
99
+ /**
100
+ * Converts a string from camelCase to snake_case (underscore) case
101
+ * @param str the string to convert
102
+ * @return the string in kebab case
103
+ */
104
+ export declare function toSnakeCase(inputStr: string): string;
105
+ /**
106
+ * Takes an input array and makes sure the array has unique values by removing duplicates
107
+ * @param array input with possible duplicates
108
+ * @return array output without duplicates
109
+ */
110
+ export declare function uniqueArray<T = any>(arr: T[]): T[];
111
+ /**
112
+ * Takes an input array of objects and makes sure the array has unique object values by removing duplicates
113
+ * it will loop through the array using a property name (or "id" when is not provided) to compare uniqueness
114
+ * @param array input with possible duplicates
115
+ * @param propertyName defaults to "id"
116
+ * @return array output without duplicates
117
+ */
118
+ export declare function uniqueObjectArray(arr: any[], propertyName?: string): any[];
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Add an item to an array only when the item does not exists, when the item is an object we will be using their "id" to compare
3
+ * @param inputArray
4
+ * @param inputItem
5
+ * @param itemIdPropName
6
+ */
7
+ export function addToArrayWhenNotExists(inputArray, inputItem, itemIdPropName = 'id') {
8
+ let arrayRowIndex = -1;
9
+ if (typeof inputItem === 'object' && itemIdPropName in inputItem) {
10
+ arrayRowIndex = inputArray.findIndex((item) => item[itemIdPropName] === inputItem[itemIdPropName]);
11
+ }
12
+ else {
13
+ arrayRowIndex = inputArray.findIndex((item) => item === inputItem);
14
+ }
15
+ if (arrayRowIndex < 0) {
16
+ inputArray.push(inputItem);
17
+ }
18
+ }
19
+ /**
20
+ * Simple function to which will loop and create as demanded the number of white spaces,
21
+ * this is used in the CSV export
22
+ * @param {Number} nbSpaces - number of white spaces to create
23
+ * @param {String} spaceChar - optionally provide character to use as a space (could be override to use &nbsp; in html)
24
+ */
25
+ export function addWhiteSpaces(nbSpaces, spaceChar = ' ') {
26
+ let result = '';
27
+ for (let i = 0; i < nbSpaces; i++) {
28
+ result += spaceChar;
29
+ }
30
+ return result;
31
+ }
32
+ /**
33
+ * Remove a column from the grid by it's index in the grid
34
+ * @param array input
35
+ * @param index
36
+ */
37
+ export function arrayRemoveItemByIndex(array, index) {
38
+ return array.filter((_el, i) => index !== i);
39
+ }
40
+ /**
41
+ * Create an immutable clone of an array or object
42
+ * (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com
43
+ * @param {Array|Object} objectOrArray - the array or object to copy
44
+ * @return {Array|Object} - the clone of the array or object
45
+ */
46
+ export function deepCopy(objectOrArray) {
47
+ /**
48
+ * Create an immutable copy of an object
49
+ * @return {Object}
50
+ */
51
+ const cloneObj = () => {
52
+ // Create new object
53
+ const clone = {};
54
+ // Loop through each item in the original
55
+ // Recursively copy it's value and add to the clone
56
+ for (const key in objectOrArray) {
57
+ if (Object.prototype.hasOwnProperty.call(objectOrArray, key)) {
58
+ clone[key] = deepCopy(objectOrArray[key]);
59
+ }
60
+ }
61
+ return clone;
62
+ };
63
+ /**
64
+ * Create an immutable copy of an array
65
+ * @return {Array}
66
+ */
67
+ const cloneArr = () => objectOrArray.map((item) => deepCopy(item));
68
+ // -- init --//
69
+ // Get object type
70
+ const type = Object.prototype.toString.call(objectOrArray).slice(8, -1).toLowerCase();
71
+ // If an object
72
+ if (type === 'object') {
73
+ return cloneObj();
74
+ }
75
+ // If an array
76
+ if (type === 'array') {
77
+ return cloneArr();
78
+ }
79
+ // Otherwise, return it as-is
80
+ return objectOrArray;
81
+ }
82
+ /**
83
+ * Performs a deep merge of objects and returns new object, it does not modify the source object, objects (immutable) and merges arrays via concatenation.
84
+ * Also, if first argument is undefined/null but next argument is an object then it will proceed and output will be an object
85
+ * @param {...object} objects - Objects to merge
86
+ * @returns {object} New object with merged key/values
87
+ */
88
+ export function deepMerge(target, ...sources) {
89
+ if (!sources.length) {
90
+ return target;
91
+ }
92
+ const source = sources.shift();
93
+ // when target is not an object but source is an object, then we'll assign as object
94
+ target = (!isObject(target) && isObject(source)) ? {} : target;
95
+ if (isObject(target) && isObject(source)) {
96
+ for (const prop in source) {
97
+ if (source.hasOwnProperty(prop)) {
98
+ if (prop in target) {
99
+ // handling merging of two properties with equal names
100
+ if (typeof target[prop] !== 'object') {
101
+ target[prop] = source[prop];
102
+ }
103
+ else {
104
+ if (typeof source[prop] !== 'object') {
105
+ target[prop] = source[prop];
106
+ }
107
+ else {
108
+ if (target[prop].concat && source[prop].concat) {
109
+ // two arrays get concatenated
110
+ target[prop] = target[prop].concat(source[prop]);
111
+ }
112
+ else {
113
+ // two objects get merged recursively
114
+ target[prop] = deepMerge(target[prop], source[prop]);
115
+ }
116
+ }
117
+ }
118
+ }
119
+ else {
120
+ // new properties get added to target
121
+ target[prop] = source[prop];
122
+ }
123
+ }
124
+ }
125
+ }
126
+ return deepMerge(target, ...sources);
127
+ }
128
+ /**
129
+ * Empty an object properties by looping through them all and deleting them
130
+ * @param obj - input object
131
+ */
132
+ export function emptyObject(obj) {
133
+ for (const key in obj) {
134
+ if (obj.hasOwnProperty(key)) {
135
+ delete obj[key];
136
+ }
137
+ }
138
+ obj = null;
139
+ obj = {};
140
+ return obj;
141
+ }
142
+ /**
143
+ * Check if an object is empty
144
+ * @param obj - input object
145
+ * @returns - boolean
146
+ */
147
+ export function isEmptyObject(obj) {
148
+ if (obj === null || obj === undefined) {
149
+ return true;
150
+ }
151
+ return Object.entries(obj).length === 0;
152
+ }
153
+ /**
154
+ * Simple object check.
155
+ * @param item
156
+ * @returns {boolean}
157
+ */
158
+ export function isObject(item) {
159
+ return (item && typeof item === 'object' && !Array.isArray(item));
160
+ }
161
+ /** Check if a value has any data (undefined, null or empty string will return false... but false boolean is consider as valid data) */
162
+ export function hasData(value) {
163
+ return value !== undefined && value !== null && value !== '';
164
+ }
165
+ /**
166
+ * Check if input value is a number, by default it won't be a strict checking
167
+ * but optionally we could check for strict equality, for example in strict "3" will return False but without strict it will return True
168
+ * @param value - input value of any type
169
+ * @param strict - when using strict it also check for strict equality, for example in strict "3" would return False but without strict it would return True
170
+ */
171
+ export function isNumber(value, strict = false) {
172
+ if (strict) {
173
+ return (value === null || value === undefined || typeof value === 'string') ? false : !isNaN(value);
174
+ }
175
+ return (value === null || value === undefined || value === '') ? false : !isNaN(+value);
176
+ }
177
+ /** Check if an object is empty, it will also be considered empty when the input is null, undefined or isn't an object */
178
+ export function isObjectEmpty(obj) {
179
+ return !obj || (obj && typeof obj === 'object' && Object.keys(obj).length === 0);
180
+ }
181
+ /** Parse any input (bool, number, string) and return a boolean or False when not possible */
182
+ export function parseBoolean(input) {
183
+ return /(true|1)/i.test(input + '');
184
+ }
185
+ /**
186
+ * Remove any accents from a string by normalizing it
187
+ * @param {String} text - input text
188
+ * @param {Boolean} shouldLowerCase - should we also lowercase the string output?
189
+ * @returns
190
+ */
191
+ export function removeAccentFromText(text, shouldLowerCase = false) {
192
+ const normalizedText = (typeof text.normalize === 'function') ? text.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : text;
193
+ return shouldLowerCase ? normalizedText.toLowerCase() : normalizedText;
194
+ }
195
+ /** Set the object value of deeper node from a given dot (.) notation path (e.g.: "user.firstName") */
196
+ export function setDeepValue(obj, path, value) {
197
+ if (typeof path === 'string') {
198
+ path = path.split('.');
199
+ }
200
+ if (path.length > 1) {
201
+ const e = path.shift();
202
+ if (obj && e !== undefined) {
203
+ setDeepValue(obj[e] = Object.prototype.toString.call(obj[e]) === '[object Object]' ? obj[e] : {}, path, value);
204
+ }
205
+ }
206
+ else if (obj && path[0]) {
207
+ obj[path[0]] = value;
208
+ }
209
+ }
210
+ /**
211
+ * Title case (or capitalize) first char of a string, for example "hello world" will become "Hello world"
212
+ * Change the string to be title case on the complete sentence (upper case first char of each word while changing everything else to lower case)
213
+ * @param inputStr
214
+ * @returns string
215
+ */
216
+ export function titleCase(inputStr, shouldTitleCaseEveryWords = false) {
217
+ if (typeof inputStr === 'string') {
218
+ if (shouldTitleCaseEveryWords) {
219
+ return inputStr.replace(/\w\S*/g, (outputStr) => {
220
+ return outputStr.charAt(0).toUpperCase() + outputStr.substr(1).toLowerCase();
221
+ });
222
+ }
223
+ return inputStr.charAt(0).toUpperCase() + inputStr.slice(1);
224
+ }
225
+ return inputStr;
226
+ }
227
+ /**
228
+ * Converts a string to camel case (camelCase), for example "hello-world" (or "hellow world") will become "helloWorld"
229
+ * @param inputStr the string to convert
230
+ * @return the string in camel case
231
+ */
232
+ export function toCamelCase(inputStr) {
233
+ if (typeof inputStr === 'string') {
234
+ return inputStr.replace(/(?:^\w|[A-Z]|\b\w|[\s+\-_\/])/g, (match, offset) => {
235
+ // remove white space or hypens or underscores
236
+ if (/[\s+\-_\/]/.test(match)) {
237
+ return '';
238
+ }
239
+ return offset === 0 ? match.toLowerCase() : match.toUpperCase();
240
+ });
241
+ }
242
+ return inputStr;
243
+ }
244
+ /**
245
+ * Converts a string to kebab (hypen) case, for example "helloWorld" will become "hello-world"
246
+ * @param str the string to convert
247
+ * @return the string in kebab case
248
+ */
249
+ export function toKebabCase(inputStr) {
250
+ if (typeof inputStr === 'string') {
251
+ return toCamelCase(inputStr).replace(/([A-Z])/g, '-$1').toLowerCase();
252
+ }
253
+ return inputStr;
254
+ }
255
+ /**
256
+ * Converts a camelCase or kebab-case string to a sentence case, for example "helloWorld" will become "Hello World" and "hello-world" will become "Hello world"
257
+ * @param str the string to convert
258
+ * @return the string in kebab case
259
+ */
260
+ export function toSentenceCase(inputStr) {
261
+ if (typeof inputStr === 'string') {
262
+ const result = inputStr.replace(/([A-Z])|(\-)/g, ' $1').replace(/\s+/g, ' ').trim();
263
+ return result.charAt(0).toUpperCase() + result.slice(1);
264
+ }
265
+ return inputStr;
266
+ }
267
+ /**
268
+ * Converts a string from camelCase to snake_case (underscore) case
269
+ * @param str the string to convert
270
+ * @return the string in kebab case
271
+ */
272
+ export function toSnakeCase(inputStr) {
273
+ if (typeof inputStr === 'string') {
274
+ return toCamelCase(inputStr).replace(/([A-Z])/g, '_$1').toLowerCase();
275
+ }
276
+ return inputStr;
277
+ }
278
+ /**
279
+ * Takes an input array and makes sure the array has unique values by removing duplicates
280
+ * @param array input with possible duplicates
281
+ * @return array output without duplicates
282
+ */
283
+ export function uniqueArray(arr) {
284
+ if (Array.isArray(arr) && arr.length > 0) {
285
+ return arr.filter((item, index) => {
286
+ return arr.indexOf(item) >= index;
287
+ });
288
+ }
289
+ return arr;
290
+ }
291
+ /**
292
+ * Takes an input array of objects and makes sure the array has unique object values by removing duplicates
293
+ * it will loop through the array using a property name (or "id" when is not provided) to compare uniqueness
294
+ * @param array input with possible duplicates
295
+ * @param propertyName defaults to "id"
296
+ * @return array output without duplicates
297
+ */
298
+ export function uniqueObjectArray(arr, propertyName = 'id') {
299
+ if (Array.isArray(arr) && arr.length > 0) {
300
+ const result = [];
301
+ const map = new Map();
302
+ for (const item of arr) {
303
+ if (item && !map.has(item[propertyName])) {
304
+ map.set(item[propertyName], true); // set any value to Map
305
+ result.push({
306
+ id: item[propertyName],
307
+ name: item.name
308
+ });
309
+ }
310
+ }
311
+ return result;
312
+ }
313
+ return arr;
314
+ }
315
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAU,UAAe,EAAE,SAAY,EAAE,cAAc,GAAG,IAAI;IACnG,IAAI,aAAa,GAAG,CAAC,CAAC,CAAC;IACvB,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,cAAc,IAAI,SAAS,EAAE;QAChE,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAE,IAAY,CAAC,cAAc,CAAC,KAAM,SAAiB,CAAC,cAAc,CAAC,CAAC,CAAC;KACtH;SAAM;QACL,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;KACpE;IAED,IAAI,aAAa,GAAG,CAAC,EAAE;QACrB,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAC5B;AACH,CAAC;AAED;;;;;GAKG;AACH,MA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{
2
+ "name": "@slickgrid-universal/utils",
3
+ "version": "1.3.0",
4
+ "description": "Common set of small utilities",
5
+ "main": "dist/commonjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/commonjs/index.d.ts",
8
+ "typings": "dist/commonjs/index.d.ts",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "files": [
13
+ "/dist"
14
+ ],
15
+ "scripts": {
16
+ "build": "pnpm run bundle:commonjs",
17
+ "build:watch": "tsc --incremental --watch",
18
+ "dev": "pnpm run bundle:commonjs",
19
+ "dev:watch": "tsc --incremental --watch",
20
+ "bundle": "run-p bundle:commonjs bundle:esm --npm-path npm",
21
+ "bundle:commonjs": "tsc --project tsconfig.bundle.json --outDir dist/commonjs --module commonjs",
22
+ "bundle:esm": "tsc --project tsconfig.bundle.json --outDir dist/esm --module esnext --target es2018",
23
+ "package:add-browser-prop": "cross-env node ../change-package-browser.js --add-browser=true --folder-name=utils",
24
+ "package:remove-browser-prop": "cross-env node ../change-package-browser.js --remove-browser=true --folder-name=utils"
25
+ },
26
+ "license": "MIT",
27
+ "author": "Ghislain B.",
28
+ "homepage": "https://github.com/ghiscoding/slickgrid-universal",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/ghiscoding/slickgrid-universal.git",
32
+ "directory": "packages/utils"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/ghiscoding/slickgrid-universal/issues"
36
+ },
37
+ "browserslist": [
38
+ "last 2 version",
39
+ "> 1%",
40
+ "not dead"
41
+ ],
42
+ "devDependencies": {
43
+ "cross-env": "^7.0.3",
44
+ "npm-run-all2": "^6.0.1"
45
+ },
46
+ "gitHead": "e36e97bc03591af0e15c50397aadf34530e58156"
47
+ }