@chevrotain/utils 11.0.1 → 11.0.3

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"print.js","sourceRoot":"","sources":["../../src/print.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,qEAAqE;IACrE,IAAI,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE;QAC5B,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,EAAE,CAAC,CAAC;KAChC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,oEAAoE;IACpE,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE;QAC3B,gCAAgC;QAChC,OAAO,CAAC,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC,CAAC;KACjC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/timer.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAI,IAAa;IACpC,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,EAAE,CAAC;IACnB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;IACjC,MAAM,KAAK,GAAG,GAAG,GAAG,KAAK,CAAC;IAC1B,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AACrC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-fast-properties.js","sourceRoot":"","sources":["../../src/to-fast-properties.ts"],"names":[],"mappings":"AAAA,yHAAyH;AACzH,MAAM,UAAU,gBAAgB,CAAC,YAAiB;IAChD,SAAS,eAAe,KAAI,CAAC;IAE7B,2DAA2D;IAC3D,eAAe,CAAC,SAAS,GAAG,YAAY,CAAC;IACzC,MAAM,YAAY,GAAG,IAAK,eAAuB,EAAE,CAAC;IAEpD,SAAS,UAAU;QACjB,OAAO,OAAO,YAAY,CAAC,GAAG,CAAC;IACjC,CAAC;IAED,kEAAkE;IAClE,qBAAqB;IACrB,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,CAAC;IAEb,uEAAuE;IACvE,iCAAiC;IACjC,IAAI,CAAC;QAAE,OAAO,YAAY,CAAC;IAE3B,4EAA4E;IAC5E,yDAAyD;IACzD,0BAA0B;IAC1B,2BAA2B;IAC3B,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC;AAC1B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chevrotain/utils",
3
- "version": "11.0.1",
3
+ "version": "11.0.3",
4
4
  "description": "common utilities",
5
5
  "keywords": [],
6
6
  "bugs": {
@@ -20,9 +20,9 @@
20
20
  },
21
21
  "files": [
22
22
  "lib/src/**/*.js",
23
+ "lib/src/**/*.map",
23
24
  "lib/src/**/*.d.ts",
24
- "README.md",
25
- "LICENSE.TXT"
25
+ "src/**/*.ts"
26
26
  ],
27
27
  "repository": {
28
28
  "type": "git",
@@ -42,5 +42,5 @@
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "12069a985026730a11a16a9b5d371c9ac9b96430"
45
+ "gitHead": "ac5806631779035c2c1955744a47d8ed4f25a175"
46
46
  }
package/src/api.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { PRINT_WARNING, PRINT_ERROR } from "./print.js";
2
+ export { timer } from "./timer.js";
3
+ export { toFastProperties } from "./to-fast-properties.js";
package/src/print.ts ADDED
@@ -0,0 +1,14 @@
1
+ export function PRINT_ERROR(msg: string) {
2
+ /* istanbul ignore else - can't override global.console in node.js */
3
+ if (console && console.error) {
4
+ console.error(`Error: ${msg}`);
5
+ }
6
+ }
7
+
8
+ export function PRINT_WARNING(msg: string) {
9
+ /* istanbul ignore else - can't override global.console in node.js*/
10
+ if (console && console.warn) {
11
+ // TODO: modify docs accordingly
12
+ console.warn(`Warning: ${msg}`);
13
+ }
14
+ }
package/src/timer.ts ADDED
@@ -0,0 +1,7 @@
1
+ export function timer<T>(func: () => T): { time: number; value: T } {
2
+ const start = new Date().getTime();
3
+ const val = func();
4
+ const end = new Date().getTime();
5
+ const total = end - start;
6
+ return { time: total, value: val };
7
+ }
@@ -0,0 +1,27 @@
1
+ // based on: https://github.com/petkaantonov/bluebird/blob/b97c0d2d487e8c5076e8bd897e0dcd4622d31846/src/util.js#L201-L216
2
+ export function toFastProperties(toBecomeFast: any) {
3
+ function FakeConstructor() {}
4
+
5
+ // If our object is used as a constructor, it would receive
6
+ FakeConstructor.prototype = toBecomeFast;
7
+ const fakeInstance = new (FakeConstructor as any)();
8
+
9
+ function fakeAccess() {
10
+ return typeof fakeInstance.bar;
11
+ }
12
+
13
+ // help V8 understand this is a "real" prototype by actually using
14
+ // the fake instance.
15
+ fakeAccess();
16
+ fakeAccess();
17
+
18
+ // Always true condition to suppress the Firefox warning of unreachable
19
+ // code after a return statement.
20
+ if (1) return toBecomeFast;
21
+
22
+ // Eval prevents optimization of this method (even though this is dead code)
23
+ // - https://esbuild.github.io/content-types/#direct-eval
24
+ /* istanbul ignore next */
25
+ // tslint:disable-next-line
26
+ (0, eval)(toBecomeFast);
27
+ }