@chevrotain/utils 9.0.0 → 10.1.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/lib/src/api.d.ts +3 -74
- package/lib/src/api.js +8 -453
- package/lib/src/api.js.map +1 -0
- package/lib/src/print.d.ts +2 -0
- package/lib/src/print.js +19 -0
- package/lib/src/print.js.map +1 -0
- package/lib/src/timer.d.ts +4 -0
- package/lib/src/timer.js +12 -0
- package/lib/src/timer.js.map +1 -0
- package/lib/src/to-fast-properties.d.ts +1 -0
- package/lib/src/to-fast-properties.js +24 -0
- package/lib/src/to-fast-properties.js.map +1 -0
- package/package.json +7 -10
package/lib/src/api.d.ts
CHANGED
|
@@ -1,74 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export declare function mapValues<I, O>(obj: Object, callback: (value: I, key?: string) => O): O[];
|
|
5
|
-
export declare function map<I, O>(arr: I[], callback: (I: any, idx?: number) => O): O[];
|
|
6
|
-
export declare function flatten<T>(arr: any[]): T[];
|
|
7
|
-
export declare function first<T>(arr: T[]): T;
|
|
8
|
-
export declare function last<T>(arr: T[]): T;
|
|
9
|
-
export declare function forEach(collection: any, iteratorCallback: Function): void;
|
|
10
|
-
export declare function isString(item: any): boolean;
|
|
11
|
-
export declare function isUndefined(item: any): boolean;
|
|
12
|
-
export declare function isFunction(item: any): boolean;
|
|
13
|
-
export declare function drop<T>(arr: T[], howMuch?: number): T[];
|
|
14
|
-
export declare function dropRight<T>(arr: T[], howMuch?: number): T[];
|
|
15
|
-
export declare function filter<T>(arr: T[], predicate: (T: any) => boolean): T[];
|
|
16
|
-
export declare function reject<T>(arr: T[], predicate: (T: any) => boolean): T[];
|
|
17
|
-
export declare function pick(obj: Object, predicate: (item: any) => boolean): {};
|
|
18
|
-
export declare function has(obj: any, prop: string): boolean;
|
|
19
|
-
export declare function contains<T>(arr: T[], item: any): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* shallow clone
|
|
22
|
-
*/
|
|
23
|
-
export declare function cloneArr<T>(arr: T[]): T[];
|
|
24
|
-
/**
|
|
25
|
-
* shallow clone
|
|
26
|
-
*/
|
|
27
|
-
export declare function cloneObj(obj: Object): any;
|
|
28
|
-
export declare function find<T>(arr: T[], predicate: (item: T) => boolean): T;
|
|
29
|
-
export declare function findAll<T>(arr: T[], predicate: (item: T) => boolean): T[];
|
|
30
|
-
export declare function reduce<T, A>(arrOrObj: Array<T> | Object, iterator: (result: A, item: any, idx?: any) => A, initial: A): A;
|
|
31
|
-
export declare function compact<T>(arr: T[]): T[];
|
|
32
|
-
export declare function uniq<T>(arr: T[], identity?: (item: T) => any): T[];
|
|
33
|
-
export declare function partial(func: Function, ...restArgs: any[]): Function;
|
|
34
|
-
export declare function isArray(obj: any): obj is any[];
|
|
35
|
-
export declare function isRegExp(obj: any): obj is RegExp;
|
|
36
|
-
export declare function isObject(obj: any): obj is Object;
|
|
37
|
-
export declare function every<T>(arr: T[], predicate: (item: T, idx?: any) => boolean): boolean;
|
|
38
|
-
export declare function difference<T>(arr: T[], values: T[]): T[];
|
|
39
|
-
export declare function some<T>(arr: T[], predicate: (item: T) => boolean): boolean;
|
|
40
|
-
export declare function indexOf<T>(arr: T[], value: T): number;
|
|
41
|
-
export declare function sortBy<T>(arr: T[], orderFunc: (item: T) => number): T[];
|
|
42
|
-
export declare function zipObject(keys: any[], values: any[]): Object;
|
|
43
|
-
/**
|
|
44
|
-
* mutates! (and returns) target
|
|
45
|
-
*/
|
|
46
|
-
export declare function assign(target: Object, ...sources: Object[]): Object;
|
|
47
|
-
/**
|
|
48
|
-
* mutates! (and returns) target
|
|
49
|
-
*/
|
|
50
|
-
export declare function assignNoOverwrite(target: Object, ...sources: Object[]): Object;
|
|
51
|
-
export declare function defaults(...sources: any[]): any;
|
|
52
|
-
export declare function groupBy<T>(arr: T[], groupKeyFunc: (item: T) => string): {
|
|
53
|
-
[groupKey: string]: T[];
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Merge obj2 into obj1.
|
|
57
|
-
* Will overwrite existing properties with the same name
|
|
58
|
-
*/
|
|
59
|
-
export declare function merge(obj1: Object, obj2: Object): any;
|
|
60
|
-
export declare function NOOP(): void;
|
|
61
|
-
export declare function IDENTITY(item: any): any;
|
|
62
|
-
/**
|
|
63
|
-
* Will return a new packed array with same values.
|
|
64
|
-
*/
|
|
65
|
-
export declare function packArray<T>(holeyArr: T[]): T[];
|
|
66
|
-
export declare function PRINT_ERROR(msg: any): void;
|
|
67
|
-
export declare function PRINT_WARNING(msg: any): void;
|
|
68
|
-
export declare function isES2015MapSupported(): boolean;
|
|
69
|
-
export declare function peek<T>(arr: T[]): T;
|
|
70
|
-
export declare function timer<T>(func: () => T): {
|
|
71
|
-
time: number;
|
|
72
|
-
value: T;
|
|
73
|
-
};
|
|
74
|
-
export declare function toFastProperties(toBecomeFast: any): any;
|
|
1
|
+
export { PRINT_WARNING, PRINT_ERROR } from "./print";
|
|
2
|
+
export { timer } from "./timer";
|
|
3
|
+
export { toFastProperties } from "./to-fast-properties";
|
package/lib/src/api.js
CHANGED
|
@@ -1,456 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Utils using lodash style API. (not necessarily 100% compliant) for functional and other utils.
|
|
4
|
-
These utils should replace usage of lodash in the production code base. not because they are any better...
|
|
5
|
-
but for the purpose of being a dependency free library.
|
|
6
|
-
|
|
7
|
-
The hotspots in the code are already written in imperative style for performance reasons.
|
|
8
|
-
so writing several dozen utils which may be slower than the original lodash, does not matter as much
|
|
9
|
-
considering they will not be invoked in hotspots...
|
|
10
|
-
*/
|
|
11
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
12
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
13
|
-
to[j] = from[i];
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.toFastProperties = exports.timer = exports.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return Object.keys(obj);
|
|
27
|
-
}
|
|
28
|
-
exports.keys = keys;
|
|
29
|
-
function values(obj) {
|
|
30
|
-
var vals = [];
|
|
31
|
-
var keys = Object.keys(obj);
|
|
32
|
-
for (var i = 0; i < keys.length; i++) {
|
|
33
|
-
vals.push(obj[keys[i]]);
|
|
34
|
-
}
|
|
35
|
-
return vals;
|
|
36
|
-
}
|
|
37
|
-
exports.values = values;
|
|
38
|
-
function mapValues(obj, callback) {
|
|
39
|
-
var result = [];
|
|
40
|
-
var objKeys = keys(obj);
|
|
41
|
-
for (var idx = 0; idx < objKeys.length; idx++) {
|
|
42
|
-
var currKey = objKeys[idx];
|
|
43
|
-
result.push(callback.call(null, obj[currKey], currKey));
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
exports.mapValues = mapValues;
|
|
48
|
-
function map(arr, callback) {
|
|
49
|
-
var result = [];
|
|
50
|
-
for (var idx = 0; idx < arr.length; idx++) {
|
|
51
|
-
result.push(callback.call(null, arr[idx], idx));
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
exports.map = map;
|
|
56
|
-
function flatten(arr) {
|
|
57
|
-
var result = [];
|
|
58
|
-
for (var idx = 0; idx < arr.length; idx++) {
|
|
59
|
-
var currItem = arr[idx];
|
|
60
|
-
if (Array.isArray(currItem)) {
|
|
61
|
-
result = result.concat(flatten(currItem));
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
result.push(currItem);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
exports.flatten = flatten;
|
|
70
|
-
function first(arr) {
|
|
71
|
-
return isEmpty(arr) ? undefined : arr[0];
|
|
72
|
-
}
|
|
73
|
-
exports.first = first;
|
|
74
|
-
function last(arr) {
|
|
75
|
-
var len = arr && arr.length;
|
|
76
|
-
return len ? arr[len - 1] : undefined;
|
|
77
|
-
}
|
|
78
|
-
exports.last = last;
|
|
79
|
-
function forEach(collection, iteratorCallback) {
|
|
80
|
-
/* istanbul ignore else */
|
|
81
|
-
if (Array.isArray(collection)) {
|
|
82
|
-
for (var i = 0; i < collection.length; i++) {
|
|
83
|
-
iteratorCallback.call(null, collection[i], i);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else if (isObject(collection)) {
|
|
87
|
-
var colKeys = keys(collection);
|
|
88
|
-
for (var i = 0; i < colKeys.length; i++) {
|
|
89
|
-
var key = colKeys[i];
|
|
90
|
-
var value = collection[key];
|
|
91
|
-
iteratorCallback.call(null, value, key);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
throw Error("non exhaustive match");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.forEach = forEach;
|
|
99
|
-
function isString(item) {
|
|
100
|
-
return typeof item === "string";
|
|
101
|
-
}
|
|
102
|
-
exports.isString = isString;
|
|
103
|
-
function isUndefined(item) {
|
|
104
|
-
return item === undefined;
|
|
105
|
-
}
|
|
106
|
-
exports.isUndefined = isUndefined;
|
|
107
|
-
function isFunction(item) {
|
|
108
|
-
return item instanceof Function;
|
|
109
|
-
}
|
|
110
|
-
exports.isFunction = isFunction;
|
|
111
|
-
function drop(arr, howMuch) {
|
|
112
|
-
if (howMuch === void 0) { howMuch = 1; }
|
|
113
|
-
return arr.slice(howMuch, arr.length);
|
|
114
|
-
}
|
|
115
|
-
exports.drop = drop;
|
|
116
|
-
function dropRight(arr, howMuch) {
|
|
117
|
-
if (howMuch === void 0) { howMuch = 1; }
|
|
118
|
-
return arr.slice(0, arr.length - howMuch);
|
|
119
|
-
}
|
|
120
|
-
exports.dropRight = dropRight;
|
|
121
|
-
function filter(arr, predicate) {
|
|
122
|
-
var result = [];
|
|
123
|
-
if (Array.isArray(arr)) {
|
|
124
|
-
for (var i = 0; i < arr.length; i++) {
|
|
125
|
-
var item = arr[i];
|
|
126
|
-
if (predicate.call(null, item)) {
|
|
127
|
-
result.push(item);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return result;
|
|
132
|
-
}
|
|
133
|
-
exports.filter = filter;
|
|
134
|
-
function reject(arr, predicate) {
|
|
135
|
-
return filter(arr, function (item) { return !predicate(item); });
|
|
136
|
-
}
|
|
137
|
-
exports.reject = reject;
|
|
138
|
-
function pick(obj, predicate) {
|
|
139
|
-
var keys = Object.keys(obj);
|
|
140
|
-
var result = {};
|
|
141
|
-
for (var i = 0; i < keys.length; i++) {
|
|
142
|
-
var currKey = keys[i];
|
|
143
|
-
var currItem = obj[currKey];
|
|
144
|
-
if (predicate(currItem)) {
|
|
145
|
-
result[currKey] = currItem;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return result;
|
|
149
|
-
}
|
|
150
|
-
exports.pick = pick;
|
|
151
|
-
function has(obj, prop) {
|
|
152
|
-
if (isObject(obj)) {
|
|
153
|
-
return obj.hasOwnProperty(prop);
|
|
154
|
-
}
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
exports.has = has;
|
|
158
|
-
function contains(arr, item) {
|
|
159
|
-
return find(arr, function (currItem) { return currItem === item; }) !== undefined ? true : false;
|
|
160
|
-
}
|
|
161
|
-
exports.contains = contains;
|
|
162
|
-
/**
|
|
163
|
-
* shallow clone
|
|
164
|
-
*/
|
|
165
|
-
function cloneArr(arr) {
|
|
166
|
-
var newArr = [];
|
|
167
|
-
for (var i = 0; i < arr.length; i++) {
|
|
168
|
-
newArr.push(arr[i]);
|
|
169
|
-
}
|
|
170
|
-
return newArr;
|
|
171
|
-
}
|
|
172
|
-
exports.cloneArr = cloneArr;
|
|
173
|
-
/**
|
|
174
|
-
* shallow clone
|
|
175
|
-
*/
|
|
176
|
-
function cloneObj(obj) {
|
|
177
|
-
var clonedObj = {};
|
|
178
|
-
for (var key in obj) {
|
|
179
|
-
/* istanbul ignore else */
|
|
180
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
181
|
-
clonedObj[key] = obj[key];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return clonedObj;
|
|
185
|
-
}
|
|
186
|
-
exports.cloneObj = cloneObj;
|
|
187
|
-
function find(arr, predicate) {
|
|
188
|
-
for (var i = 0; i < arr.length; i++) {
|
|
189
|
-
var item = arr[i];
|
|
190
|
-
if (predicate.call(null, item)) {
|
|
191
|
-
return item;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return undefined;
|
|
195
|
-
}
|
|
196
|
-
exports.find = find;
|
|
197
|
-
function findAll(arr, predicate) {
|
|
198
|
-
var found = [];
|
|
199
|
-
for (var i = 0; i < arr.length; i++) {
|
|
200
|
-
var item = arr[i];
|
|
201
|
-
if (predicate.call(null, item)) {
|
|
202
|
-
found.push(item);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return found;
|
|
206
|
-
}
|
|
207
|
-
exports.findAll = findAll;
|
|
208
|
-
function reduce(arrOrObj, iterator, initial) {
|
|
209
|
-
var isArr = Array.isArray(arrOrObj);
|
|
210
|
-
var vals = isArr ? arrOrObj : values(arrOrObj);
|
|
211
|
-
var objKeys = isArr ? [] : keys(arrOrObj);
|
|
212
|
-
var accumulator = initial;
|
|
213
|
-
for (var i = 0; i < vals.length; i++) {
|
|
214
|
-
accumulator = iterator.call(null, accumulator, vals[i], isArr ? i : objKeys[i]);
|
|
215
|
-
}
|
|
216
|
-
return accumulator;
|
|
217
|
-
}
|
|
218
|
-
exports.reduce = reduce;
|
|
219
|
-
function compact(arr) {
|
|
220
|
-
return reject(arr, function (item) { return item === null || item === undefined; });
|
|
221
|
-
}
|
|
222
|
-
exports.compact = compact;
|
|
223
|
-
function uniq(arr, identity) {
|
|
224
|
-
if (identity === void 0) { identity = function (item) { return item; }; }
|
|
225
|
-
var identities = [];
|
|
226
|
-
return reduce(arr, function (result, currItem) {
|
|
227
|
-
var currIdentity = identity(currItem);
|
|
228
|
-
if (contains(identities, currIdentity)) {
|
|
229
|
-
return result;
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
identities.push(currIdentity);
|
|
233
|
-
return result.concat(currItem);
|
|
234
|
-
}
|
|
235
|
-
}, []);
|
|
236
|
-
}
|
|
237
|
-
exports.uniq = uniq;
|
|
238
|
-
function partial(func) {
|
|
239
|
-
var restArgs = [];
|
|
240
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
241
|
-
restArgs[_i - 1] = arguments[_i];
|
|
242
|
-
}
|
|
243
|
-
var firstArg = [null];
|
|
244
|
-
var allArgs = firstArg.concat(restArgs);
|
|
245
|
-
return Function.bind.apply(func, allArgs);
|
|
246
|
-
}
|
|
247
|
-
exports.partial = partial;
|
|
248
|
-
function isArray(obj) {
|
|
249
|
-
return Array.isArray(obj);
|
|
250
|
-
}
|
|
251
|
-
exports.isArray = isArray;
|
|
252
|
-
function isRegExp(obj) {
|
|
253
|
-
return obj instanceof RegExp;
|
|
254
|
-
}
|
|
255
|
-
exports.isRegExp = isRegExp;
|
|
256
|
-
function isObject(obj) {
|
|
257
|
-
return obj instanceof Object;
|
|
258
|
-
}
|
|
259
|
-
exports.isObject = isObject;
|
|
260
|
-
function every(arr, predicate) {
|
|
261
|
-
for (var i = 0; i < arr.length; i++) {
|
|
262
|
-
if (!predicate(arr[i], i)) {
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return true;
|
|
267
|
-
}
|
|
268
|
-
exports.every = every;
|
|
269
|
-
function difference(arr, values) {
|
|
270
|
-
return reject(arr, function (item) { return contains(values, item); });
|
|
271
|
-
}
|
|
272
|
-
exports.difference = difference;
|
|
273
|
-
function some(arr, predicate) {
|
|
274
|
-
for (var i = 0; i < arr.length; i++) {
|
|
275
|
-
if (predicate(arr[i])) {
|
|
276
|
-
return true;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
exports.some = some;
|
|
282
|
-
function indexOf(arr, value) {
|
|
283
|
-
for (var i = 0; i < arr.length; i++) {
|
|
284
|
-
if (arr[i] === value) {
|
|
285
|
-
return i;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return -1;
|
|
289
|
-
}
|
|
290
|
-
exports.indexOf = indexOf;
|
|
291
|
-
function sortBy(arr, orderFunc) {
|
|
292
|
-
var result = cloneArr(arr);
|
|
293
|
-
result.sort(function (a, b) { return orderFunc(a) - orderFunc(b); });
|
|
294
|
-
return result;
|
|
295
|
-
}
|
|
296
|
-
exports.sortBy = sortBy;
|
|
297
|
-
function zipObject(keys, values) {
|
|
298
|
-
if (keys.length !== values.length) {
|
|
299
|
-
throw Error("can't zipObject with different number of keys and values!");
|
|
300
|
-
}
|
|
301
|
-
var result = {};
|
|
302
|
-
for (var i = 0; i < keys.length; i++) {
|
|
303
|
-
result[keys[i]] = values[i];
|
|
304
|
-
}
|
|
305
|
-
return result;
|
|
306
|
-
}
|
|
307
|
-
exports.zipObject = zipObject;
|
|
308
|
-
/**
|
|
309
|
-
* mutates! (and returns) target
|
|
310
|
-
*/
|
|
311
|
-
function assign(target) {
|
|
312
|
-
var sources = [];
|
|
313
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
314
|
-
sources[_i - 1] = arguments[_i];
|
|
315
|
-
}
|
|
316
|
-
for (var i = 0; i < sources.length; i++) {
|
|
317
|
-
var curSource = sources[i];
|
|
318
|
-
var currSourceKeys = keys(curSource);
|
|
319
|
-
for (var j = 0; j < currSourceKeys.length; j++) {
|
|
320
|
-
var currKey = currSourceKeys[j];
|
|
321
|
-
target[currKey] = curSource[currKey];
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return target;
|
|
325
|
-
}
|
|
326
|
-
exports.assign = assign;
|
|
327
|
-
/**
|
|
328
|
-
* mutates! (and returns) target
|
|
329
|
-
*/
|
|
330
|
-
function assignNoOverwrite(target) {
|
|
331
|
-
var sources = [];
|
|
332
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
333
|
-
sources[_i - 1] = arguments[_i];
|
|
334
|
-
}
|
|
335
|
-
for (var i = 0; i < sources.length; i++) {
|
|
336
|
-
var curSource = sources[i];
|
|
337
|
-
var currSourceKeys = keys(curSource);
|
|
338
|
-
for (var j = 0; j < currSourceKeys.length; j++) {
|
|
339
|
-
var currKey = currSourceKeys[j];
|
|
340
|
-
if (!has(target, currKey)) {
|
|
341
|
-
target[currKey] = curSource[currKey];
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
return target;
|
|
346
|
-
}
|
|
347
|
-
exports.assignNoOverwrite = assignNoOverwrite;
|
|
348
|
-
function defaults() {
|
|
349
|
-
var sources = [];
|
|
350
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
351
|
-
sources[_i] = arguments[_i];
|
|
352
|
-
}
|
|
353
|
-
return assignNoOverwrite.apply(void 0, __spreadArray([{}], sources));
|
|
354
|
-
}
|
|
355
|
-
exports.defaults = defaults;
|
|
356
|
-
function groupBy(arr, groupKeyFunc) {
|
|
357
|
-
var result = {};
|
|
358
|
-
forEach(arr, function (item) {
|
|
359
|
-
var currGroupKey = groupKeyFunc(item);
|
|
360
|
-
var currGroupArr = result[currGroupKey];
|
|
361
|
-
if (currGroupArr) {
|
|
362
|
-
currGroupArr.push(item);
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
result[currGroupKey] = [item];
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
return result;
|
|
369
|
-
}
|
|
370
|
-
exports.groupBy = groupBy;
|
|
371
|
-
/**
|
|
372
|
-
* Merge obj2 into obj1.
|
|
373
|
-
* Will overwrite existing properties with the same name
|
|
374
|
-
*/
|
|
375
|
-
function merge(obj1, obj2) {
|
|
376
|
-
var result = cloneObj(obj1);
|
|
377
|
-
var keys2 = keys(obj2);
|
|
378
|
-
for (var i = 0; i < keys2.length; i++) {
|
|
379
|
-
var key = keys2[i];
|
|
380
|
-
var value = obj2[key];
|
|
381
|
-
result[key] = value;
|
|
382
|
-
}
|
|
383
|
-
return result;
|
|
384
|
-
}
|
|
385
|
-
exports.merge = merge;
|
|
386
|
-
function NOOP() { }
|
|
387
|
-
exports.NOOP = NOOP;
|
|
388
|
-
function IDENTITY(item) {
|
|
389
|
-
return item;
|
|
390
|
-
}
|
|
391
|
-
exports.IDENTITY = IDENTITY;
|
|
392
|
-
/**
|
|
393
|
-
* Will return a new packed array with same values.
|
|
394
|
-
*/
|
|
395
|
-
function packArray(holeyArr) {
|
|
396
|
-
var result = [];
|
|
397
|
-
for (var i = 0; i < holeyArr.length; i++) {
|
|
398
|
-
var orgValue = holeyArr[i];
|
|
399
|
-
result.push(orgValue !== undefined ? orgValue : undefined);
|
|
400
|
-
}
|
|
401
|
-
return result;
|
|
402
|
-
}
|
|
403
|
-
exports.packArray = packArray;
|
|
404
|
-
function PRINT_ERROR(msg) {
|
|
405
|
-
/* istanbul ignore else - can't override global.console in node.js */
|
|
406
|
-
if (console && console.error) {
|
|
407
|
-
console.error("Error: " + msg);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
exports.PRINT_ERROR = PRINT_ERROR;
|
|
411
|
-
function PRINT_WARNING(msg) {
|
|
412
|
-
/* istanbul ignore else - can't override global.console in node.js*/
|
|
413
|
-
if (console && console.warn) {
|
|
414
|
-
// TODO: modify docs accordingly
|
|
415
|
-
console.warn("Warning: " + msg);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
exports.PRINT_WARNING = PRINT_WARNING;
|
|
419
|
-
function isES2015MapSupported() {
|
|
420
|
-
return typeof Map === "function";
|
|
421
|
-
}
|
|
422
|
-
exports.isES2015MapSupported = isES2015MapSupported;
|
|
423
|
-
function peek(arr) {
|
|
424
|
-
return arr[arr.length - 1];
|
|
425
|
-
}
|
|
426
|
-
exports.peek = peek;
|
|
427
|
-
/* istanbul ignore next - for performance tracing*/
|
|
428
|
-
function timer(func) {
|
|
429
|
-
var start = new Date().getTime();
|
|
430
|
-
var val = func();
|
|
431
|
-
var end = new Date().getTime();
|
|
432
|
-
var total = end - start;
|
|
433
|
-
return { time: total, value: val };
|
|
434
|
-
}
|
|
435
|
-
exports.timer = timer;
|
|
436
|
-
// based on: https://github.com/petkaantonov/bluebird/blob/b97c0d2d487e8c5076e8bd897e0dcd4622d31846/src/util.js#L201-L216
|
|
437
|
-
function toFastProperties(toBecomeFast) {
|
|
438
|
-
function FakeConstructor() { }
|
|
439
|
-
// If our object is used as a constructor it would receive
|
|
440
|
-
FakeConstructor.prototype = toBecomeFast;
|
|
441
|
-
var fakeInstance = new FakeConstructor();
|
|
442
|
-
function fakeAccess() {
|
|
443
|
-
return typeof fakeInstance.bar;
|
|
444
|
-
}
|
|
445
|
-
// help V8 understand this is a "real" prototype by actually using
|
|
446
|
-
// the fake instance.
|
|
447
|
-
fakeAccess();
|
|
448
|
-
fakeAccess();
|
|
449
|
-
return toBecomeFast;
|
|
450
|
-
// Eval prevents optimization of this method (even though this is dead code)
|
|
451
|
-
/* istanbul ignore next */
|
|
452
|
-
// tslint:disable-next-line
|
|
453
|
-
eval(toBecomeFast);
|
|
454
|
-
}
|
|
455
|
-
exports.toFastProperties = toFastProperties;
|
|
3
|
+
exports.toFastProperties = exports.timer = exports.PRINT_ERROR = exports.PRINT_WARNING = void 0;
|
|
4
|
+
var print_1 = require("./print");
|
|
5
|
+
Object.defineProperty(exports, "PRINT_WARNING", { enumerable: true, get: function () { return print_1.PRINT_WARNING; } });
|
|
6
|
+
Object.defineProperty(exports, "PRINT_ERROR", { enumerable: true, get: function () { return print_1.PRINT_ERROR; } });
|
|
7
|
+
var timer_1 = require("./timer");
|
|
8
|
+
Object.defineProperty(exports, "timer", { enumerable: true, get: function () { return timer_1.timer; } });
|
|
9
|
+
var to_fast_properties_1 = require("./to-fast-properties");
|
|
10
|
+
Object.defineProperty(exports, "toFastProperties", { enumerable: true, get: function () { return to_fast_properties_1.toFastProperties; } });
|
|
456
11
|
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":";;;AAAA,iCAAoD;AAA3C,sGAAA,aAAa,OAAA;AAAE,oGAAA,WAAW,OAAA;AACnC,iCAA+B;AAAtB,8FAAA,KAAK,OAAA;AACd,2DAAuD;AAA9C,sHAAA,gBAAgB,OAAA"}
|
package/lib/src/print.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PRINT_WARNING = exports.PRINT_ERROR = void 0;
|
|
4
|
+
function PRINT_ERROR(msg) {
|
|
5
|
+
/* istanbul ignore else - can't override global.console in node.js */
|
|
6
|
+
if (console && console.error) {
|
|
7
|
+
console.error("Error: ".concat(msg));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.PRINT_ERROR = PRINT_ERROR;
|
|
11
|
+
function PRINT_WARNING(msg) {
|
|
12
|
+
/* istanbul ignore else - can't override global.console in node.js*/
|
|
13
|
+
if (console && console.warn) {
|
|
14
|
+
// TODO: modify docs accordingly
|
|
15
|
+
console.warn("Warning: ".concat(msg));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.PRINT_WARNING = PRINT_WARNING;
|
|
19
|
+
//# sourceMappingURL=print.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.js","sourceRoot":"","sources":["../../src/print.ts"],"names":[],"mappings":";;;AAAA,SAAgB,WAAW,CAAC,GAAW;IACrC,qEAAqE;IACrE,IAAI,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE;QAC5B,OAAO,CAAC,KAAK,CAAC,iBAAU,GAAG,CAAE,CAAC,CAAA;KAC/B;AACH,CAAC;AALD,kCAKC;AAED,SAAgB,aAAa,CAAC,GAAW;IACvC,oEAAoE;IACpE,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE;QAC3B,gCAAgC;QAChC,OAAO,CAAC,IAAI,CAAC,mBAAY,GAAG,CAAE,CAAC,CAAA;KAChC;AACH,CAAC;AAND,sCAMC"}
|
package/lib/src/timer.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.timer = void 0;
|
|
4
|
+
function timer(func) {
|
|
5
|
+
var start = new Date().getTime();
|
|
6
|
+
var val = func();
|
|
7
|
+
var end = new Date().getTime();
|
|
8
|
+
var total = end - start;
|
|
9
|
+
return { time: total, value: val };
|
|
10
|
+
}
|
|
11
|
+
exports.timer = timer;
|
|
12
|
+
//# sourceMappingURL=timer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/timer.ts"],"names":[],"mappings":";;;AAAA,SAAgB,KAAK,CAAI,IAAa;IACpC,IAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;IAClC,IAAM,GAAG,GAAG,IAAI,EAAE,CAAA;IAClB,IAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;IAChC,IAAM,KAAK,GAAG,GAAG,GAAG,KAAK,CAAA;IACzB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;AACpC,CAAC;AAND,sBAMC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toFastProperties(toBecomeFast: any): any;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toFastProperties = void 0;
|
|
4
|
+
// based on: https://github.com/petkaantonov/bluebird/blob/b97c0d2d487e8c5076e8bd897e0dcd4622d31846/src/util.js#L201-L216
|
|
5
|
+
function toFastProperties(toBecomeFast) {
|
|
6
|
+
function FakeConstructor() { }
|
|
7
|
+
// If our object is used as a constructor it would receive
|
|
8
|
+
FakeConstructor.prototype = toBecomeFast;
|
|
9
|
+
var fakeInstance = new FakeConstructor();
|
|
10
|
+
function fakeAccess() {
|
|
11
|
+
return typeof fakeInstance.bar;
|
|
12
|
+
}
|
|
13
|
+
// help V8 understand this is a "real" prototype by actually using
|
|
14
|
+
// the fake instance.
|
|
15
|
+
fakeAccess();
|
|
16
|
+
fakeAccess();
|
|
17
|
+
return toBecomeFast;
|
|
18
|
+
// Eval prevents optimization of this method (even though this is dead code)
|
|
19
|
+
/* istanbul ignore next */
|
|
20
|
+
// tslint:disable-next-line
|
|
21
|
+
eval(toBecomeFast);
|
|
22
|
+
}
|
|
23
|
+
exports.toFastProperties = toFastProperties;
|
|
24
|
+
//# sourceMappingURL=to-fast-properties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-fast-properties.js","sourceRoot":"","sources":["../../src/to-fast-properties.ts"],"names":[],"mappings":";;;AAAA,yHAAyH;AACzH,SAAgB,gBAAgB,CAAC,YAAiB;IAChD,SAAS,eAAe,KAAI,CAAC;IAE7B,0DAA0D;IAC1D,eAAe,CAAC,SAAS,GAAG,YAAY,CAAA;IACxC,IAAM,YAAY,GAAG,IAAK,eAAuB,EAAE,CAAA;IAEnD,SAAS,UAAU;QACjB,OAAO,OAAO,YAAY,CAAC,GAAG,CAAA;IAChC,CAAC;IAED,kEAAkE;IAClE,qBAAqB;IACrB,UAAU,EAAE,CAAA;IACZ,UAAU,EAAE,CAAA;IAEZ,OAAO,YAAY,CAAA;IACnB,4EAA4E;IAC5E,0BAA0B;IAC1B,2BAA2B;IAC3B,IAAI,CAAC,YAAY,CAAC,CAAA;AACpB,CAAC;AArBD,4CAqBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chevrotain/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "common utilities",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"bugs": {
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"author": {
|
|
11
11
|
"name": "Shahar Soel"
|
|
12
12
|
},
|
|
13
|
-
"typings": "api.d.ts",
|
|
13
|
+
"typings": "lib/src/api.d.ts",
|
|
14
14
|
"main": "lib/src/api.js",
|
|
15
15
|
"files": [
|
|
16
|
-
"lib/src
|
|
17
|
-
"lib/src
|
|
18
|
-
"lib/src
|
|
16
|
+
"lib/src/**/*.js",
|
|
17
|
+
"lib/src/**/*.d.ts",
|
|
18
|
+
"lib/src/**/*.js.map",
|
|
19
19
|
"README.md",
|
|
20
20
|
"LICENSE.TXT"
|
|
21
21
|
],
|
|
@@ -28,16 +28,13 @@
|
|
|
28
28
|
"build": "npm-run-all clean compile",
|
|
29
29
|
"test": "npm-run-all coverage",
|
|
30
30
|
"---------- BUILD STEPS --------": "",
|
|
31
|
-
"clean": "shx rm -rf
|
|
31
|
+
"clean": "shx rm -rf lib coverage",
|
|
32
32
|
"compile:watch": "tsc -w",
|
|
33
33
|
"compile": "tsc",
|
|
34
34
|
"coverage": "nyc mocha"
|
|
35
35
|
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@types/chai": "^4.2.15"
|
|
38
|
-
},
|
|
39
36
|
"publishConfig": {
|
|
40
37
|
"access": "public"
|
|
41
38
|
},
|
|
42
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "21d2467a0bac7d8f7f54806972a5f489bed9611f"
|
|
43
40
|
}
|