@pluslabs/utils 0.0.1 → 0.1.2

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,2 @@
1
+ export * from './stamp';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -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("./stamp"), 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,23 @@
1
+ type context = {
2
+ id: string;
3
+ idx: string;
4
+ step: number;
5
+ now: number;
6
+ end: () => void;
7
+ };
8
+ /**
9
+ * The idea is that you can create a stamp with an id, and then use that id to mark different steps in your code.
10
+ * `createStamp` should be called at the beginning of the execution context and then createStamp
11
+ * @param id String to identify the stamp
12
+ * @returns
13
+ */
14
+ export declare const createStamp: (id?: string) => {
15
+ stamp: (name: string) => context;
16
+ end: () => context;
17
+ };
18
+ export declare function stamp(this: context, name: string): context;
19
+ export declare namespace stamp {
20
+ var end: (this: context) => context;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"AAGA,KAAK,OAAO,GAAG;IACX,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;CAiBvB,CAAC;AAEF,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAahD;yBAbe,KAAK"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ // Copy/pasta from https://github.com/pluslabs/magic-professional/blob/main/packages/stamp/index.ts
3
+ // since yarn cant do subdirectories from a monorepo
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.stamp = exports.createStamp = void 0;
6
+ /**
7
+ * The idea is that you can create a stamp with an id, and then use that id to mark different steps in your code.
8
+ * `createStamp` should be called at the beginning of the execution context and then createStamp
9
+ * @param id String to identify the stamp
10
+ * @returns
11
+ */
12
+ const createStamp = (id = '') => {
13
+ const ctx = {
14
+ id,
15
+ idx: (Date.now() * Math.random() * 1e6).toString(36),
16
+ now: Date.now(),
17
+ step: Date.now(),
18
+ end: () => { }
19
+ };
20
+ // Bind the end function to the context
21
+ // so we can curry it
22
+ ctx.end = end.bind(ctx);
23
+ return {
24
+ stamp: stamp.bind(ctx),
25
+ end: end.bind(ctx)
26
+ };
27
+ };
28
+ exports.createStamp = createStamp;
29
+ function stamp(name) {
30
+ if (!this.id) {
31
+ return this;
32
+ }
33
+ const diff = Date.now() - this.step;
34
+ this.step = Date.now();
35
+ console.log(`[STAMP][${this.idx}][${this.id}] ${name} took ${diff}ms, total: ${Date.now() - this.now}ms`);
36
+ return this;
37
+ }
38
+ exports.stamp = stamp;
39
+ stamp.end = end;
40
+ function end() {
41
+ this.id = '';
42
+ this.now = 0;
43
+ this.step = 0;
44
+ const ctx = this;
45
+ return ctx;
46
+ }
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":";AAAA,mGAAmG;AACnG,oDAAoD;;;AAUpD;;;;;GAKG;AACI,MAAM,WAAW,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;IACnC,MAAM,GAAG,GAAG;QACR,EAAE;QACF,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE;QACf,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;QAChB,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;KACL,CAAC;IAEb,uCAAuC;IACvC,qBAAqB;IACrB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAExB,OAAO;QACH,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QACtB,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;KACrB,CAAC;AACN,CAAC,CAAC;AAjBW,QAAA,WAAW,eAiBtB;AAEF,SAAgB,KAAK,CAAgB,IAAY;IAC7C,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;QACV,OAAO,IAAI,CAAC;KACf;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;IACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAEvB,OAAO,CAAC,GAAG,CACP,WAAW,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,EAAE,KAAK,IAAI,SAAS,IAAI,cAAc,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAC/F,CAAC;IAEF,OAAO,IAAI,CAAC;AAChB,CAAC;AAbD,sBAaC;AAED,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;AAEhB,SAAS,GAAG;IACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IACb,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IAEd,MAAM,GAAG,GAAG,IAAe,CAAC;IAE5B,OAAO,GAAG,CAAC;AACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './stamp';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './stamp';
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,23 @@
1
+ type context = {
2
+ id: string;
3
+ idx: string;
4
+ step: number;
5
+ now: number;
6
+ end: () => void;
7
+ };
8
+ /**
9
+ * The idea is that you can create a stamp with an id, and then use that id to mark different steps in your code.
10
+ * `createStamp` should be called at the beginning of the execution context and then createStamp
11
+ * @param id String to identify the stamp
12
+ * @returns
13
+ */
14
+ export declare const createStamp: (id?: string) => {
15
+ stamp: (name: string) => context;
16
+ end: () => context;
17
+ };
18
+ export declare function stamp(this: context, name: string): context;
19
+ export declare namespace stamp {
20
+ var end: (this: context) => context;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stamp/index.ts"],"names":[],"mappings":"AAGA,KAAK,OAAO,GAAG;IACX,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;CAiBvB,CAAC;AAEF,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAahD;yBAbe,KAAK"}
@@ -0,0 +1,42 @@
1
+ // Copy/pasta from https://github.com/pluslabs/magic-professional/blob/main/packages/stamp/index.ts
2
+ // since yarn cant do subdirectories from a monorepo
3
+ /**
4
+ * The idea is that you can create a stamp with an id, and then use that id to mark different steps in your code.
5
+ * `createStamp` should be called at the beginning of the execution context and then createStamp
6
+ * @param id String to identify the stamp
7
+ * @returns
8
+ */
9
+ export const createStamp = (id = '') => {
10
+ const ctx = {
11
+ id,
12
+ idx: (Date.now() * Math.random() * 1e6).toString(36),
13
+ now: Date.now(),
14
+ step: Date.now(),
15
+ end: () => { }
16
+ };
17
+ // Bind the end function to the context
18
+ // so we can curry it
19
+ ctx.end = end.bind(ctx);
20
+ return {
21
+ stamp: stamp.bind(ctx),
22
+ end: end.bind(ctx)
23
+ };
24
+ };
25
+ export function stamp(name) {
26
+ if (!this.id) {
27
+ return this;
28
+ }
29
+ const diff = Date.now() - this.step;
30
+ this.step = Date.now();
31
+ console.log(`[STAMP][${this.idx}][${this.id}] ${name} took ${diff}ms, total: ${Date.now() - this.now}ms`);
32
+ return this;
33
+ }
34
+ stamp.end = end;
35
+ function end() {
36
+ this.id = '';
37
+ this.now = 0;
38
+ this.step = 0;
39
+ const ctx = this;
40
+ return ctx;
41
+ }
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":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S,GAAG;IACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IACb,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IAEd,MAAM,GAAG,GAAG,IAAe,CAAC;IAE5B,OAAO,GAAG,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluslabs/utils",
3
- "version": "0.0.1",
3
+ "version": "0.1.2",
4
4
  "description": "A set of utilities used across projects",
5
5
  "keywords": [
6
6
  "javascript",
@@ -1,13 +1,12 @@
1
- const context: {
1
+ // Copy/pasta from https://github.com/pluslabs/magic-professional/blob/main/packages/stamp/index.ts
2
+ // since yarn cant do subdirectories from a monorepo
3
+
4
+ type context = {
2
5
  id: string;
3
6
  idx: string;
4
7
  step: number;
5
8
  now: number;
6
- } = {
7
- id: '',
8
- idx: '',
9
- step: 0,
10
- now: 0
9
+ end: () => void;
11
10
  };
12
11
 
13
12
  /**
@@ -17,33 +16,47 @@ const context: {
17
16
  * @returns
18
17
  */
19
18
  export const createStamp = (id = '') => {
20
- if (!context.id) {
21
- context.id = id;
22
- context.idx = (Date.now() * Math.random() * 1e6).toString(36);
23
- context.now = Date.now();
24
- context.step = Date.now();
25
- }
19
+ const ctx = {
20
+ id,
21
+ idx: (Date.now() * Math.random() * 1e6).toString(36),
22
+ now: Date.now(),
23
+ step: Date.now(),
24
+ end: () => {}
25
+ } as context;
26
26
 
27
- return stamp;
27
+ // Bind the end function to the context
28
+ // so we can curry it
29
+ ctx.end = end.bind(ctx);
30
+
31
+ return {
32
+ stamp: stamp.bind(ctx),
33
+ end: end.bind(ctx)
34
+ };
28
35
  };
29
36
 
30
- export function stamp(name: string) {
31
- if (!context.id) {
32
- return;
37
+ export function stamp(this: context, name: string) {
38
+ if (!this.id) {
39
+ return this;
33
40
  }
34
41
 
35
- const diff = Date.now() - context.step;
36
- context.step = Date.now();
42
+ const diff = Date.now() - this.step;
43
+ this.step = Date.now();
37
44
 
38
45
  console.log(
39
- `[STAMP][${context.idx}][${context.id}] ${name} took ${diff}ms, total: ${
40
- Date.now() - context.now
41
- }ms`
46
+ `[STAMP][${this.idx}][${this.id}] ${name} took ${diff}ms, total: ${Date.now() - this.now}ms`
42
47
  );
48
+
49
+ return this;
43
50
  }
44
51
 
45
- export function end() {
46
- context.id = '';
47
- context.now = 0;
48
- context.step = 0;
52
+ stamp.end = end;
53
+
54
+ function end(this: context) {
55
+ this.id = '';
56
+ this.now = 0;
57
+ this.step = 0;
58
+
59
+ const ctx = this as context;
60
+
61
+ return ctx;
49
62
  }