pareto-core-dev 0.11.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.
@@ -0,0 +1,13 @@
1
+ export type Source_Location = {
2
+ 'file': string;
3
+ 'line': number;
4
+ 'column': number;
5
+ };
6
+ /**
7
+ * provides the source location (filepath and line number) of the source code file where this function is called,
8
+ * or if the depth is bigger than 0, the source location of the function at that stack depth
9
+ * @param depth
10
+ * @returns
11
+ */
12
+ export declare function get_location_info(depth: number): Source_Location;
13
+ export declare function location_to_string(location: Source_Location): string;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.get_location_info = get_location_info;
4
+ exports.location_to_string = location_to_string;
5
+ /**
6
+ * provides the source location (filepath and line number) of the source code file where this function is called,
7
+ * or if the depth is bigger than 0, the source location of the function at that stack depth
8
+ * @param depth
9
+ * @returns
10
+ */
11
+ function get_location_info(depth) {
12
+ //we create an error, not to be thrown but to be disected for its stack
13
+ const e = new Error(); //don't move this statement to another function, it will change the depth of its stack
14
+ function get_line(e, depth) {
15
+ if (e.stack === undefined) {
16
+ throw new Error(`NO STACK INFO`);
17
+ }
18
+ const line = e.stack.split("\n")[depth + 2]; //get the right line from the stack (the first two lines are "Error" and this function call)
19
+ const regex = /\((.*)\)$/; //matches the content inside parentheses at the end of a line (the file path with line and column)
20
+ const match = regex.exec(line);
21
+ if (match !== null) {
22
+ //we have a match
23
+ return match[1];
24
+ }
25
+ const begin = " at /";
26
+ if (line.startsWith(begin)) {
27
+ return line.substring(begin.length - 1);
28
+ }
29
+ throw new Error(`COULD NOT PARSE STACK LINE: ${line}`);
30
+ }
31
+ const line = get_line(e, depth);
32
+ const split = line.split(":");
33
+ if (split.length !== 3) {
34
+ throw new Error(`UNEXPECTED LOCATION FORMAT (CHECK THE DEPTH PARAMETER): ${line} (Expected 'file:line:column')`);
35
+ }
36
+ return {
37
+ 'file': split[0],
38
+ 'line': Number(split[1]),
39
+ 'column': Number(split[2]),
40
+ };
41
+ }
42
+ function location_to_string(location) {
43
+ return `${location.file}:${location.line}:${location.column}`;
44
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./public/implement_me";
2
+ export * from "./public/log_debug_message";
package/dist/index.js ADDED
@@ -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("./public/implement_me"), exports);
18
+ __exportStar(require("./public/log_debug_message"), exports);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * use this function as a placeholder when you want to compile but have not fully developed all functionality yet.
3
+ *
4
+ * this function should only be called from code that is in the development phase,
5
+ * before publishing, the usages should be removed
6
+ * @param message the string to be printed to stderr
7
+ */
8
+ export declare function implement_me(marker: string): never;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.implement_me = implement_me;
4
+ const get_location_info_1 = require("../get_location_info");
5
+ /**
6
+ * use this function as a placeholder when you want to compile but have not fully developed all functionality yet.
7
+ *
8
+ * this function should only be called from code that is in the development phase,
9
+ * before publishing, the usages should be removed
10
+ * @param message the string to be printed to stderr
11
+ */
12
+ function implement_me(marker) {
13
+ throw new Error(`IMPLEMENT ME ${marker ? `: '${marker}'` : ''}@ ${(0, get_location_info_1.location_to_string)((0, get_location_info_1.get_location_info)(1))}`);
14
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * logs a debug message
3
+ * this function should only be called from code that is in the development phase,
4
+ * before publishing, the usages should be removed
5
+ * @param message the string to be printed to stdout
6
+ */
7
+ export declare function log_debug_message<T>(message: string, handler: () => T): T;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.log_debug_message = log_debug_message;
4
+ /**
5
+ * logs a debug message
6
+ * this function should only be called from code that is in the development phase,
7
+ * before publishing, the usages should be removed
8
+ * @param message the string to be printed to stdout
9
+ */
10
+ function log_debug_message(message, handler) {
11
+ console.log("DEBUG", message);
12
+ return handler();
13
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "pareto-core-dev",
3
+ "version": "0.11.0",
4
+ "license": "ISC",
5
+ "description": "a pareto package that contains functions that are useful during development",
6
+ "author": "Corno",
7
+ "keywords": [
8
+ "pareto",
9
+ "development",
10
+ "log_debug_message",
11
+ "implement_me"
12
+ ],
13
+ "homepage": "https://github.com/corno/pareto-core-dev#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/corno/pareto-core-dev/issues"
16
+ },
17
+ "main": "./dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/corno/pareto-core-dev.git"
25
+ },
26
+ "dependencies": {}
27
+ }