exupery-core-dev 0.1.2 → 0.2.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,57 @@
|
|
|
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
|
+
const process_1 = require("process");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @returns the string on the specified line
|
|
10
|
+
*/
|
|
11
|
+
function get_line(e, depth) {
|
|
12
|
+
const regex = /\((.*)\)$/;
|
|
13
|
+
//const regex = /\((.*):(\d+):(\d+)\)$/ //further splitted; file,line,column,
|
|
14
|
+
if (e.stack === undefined) {
|
|
15
|
+
throw new Error("NO STACK INFO");
|
|
16
|
+
}
|
|
17
|
+
const line = e.stack.split("\n")[depth + 2];
|
|
18
|
+
const match = regex.exec(line);
|
|
19
|
+
//determine the path relative to the current working directory
|
|
20
|
+
return (0, path_1.relative)((0, process_1.cwd)(), (() => {
|
|
21
|
+
if (match === null) {
|
|
22
|
+
const begin = " at /";
|
|
23
|
+
if (line.startsWith(begin)) {
|
|
24
|
+
return (0, path_1.relative)((0, process_1.cwd)(), line.substring(begin.length - 1));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error(`COULD NOT PARSE STACK LINE: ${line}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return match[1];
|
|
32
|
+
}
|
|
33
|
+
})());
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* provides the source location (filepath and line number) of the source code file where this function is called,
|
|
37
|
+
* or if the depth is bigger than 0, the source location of the function at that stack depth
|
|
38
|
+
* @param depth
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
function get_location_info(depth) {
|
|
42
|
+
//we create an error, not to be thrown but to be disected for its stack
|
|
43
|
+
const e = new Error(); //don't move this statement to another function, it will change the depth of its stack
|
|
44
|
+
const line = get_line(e, depth);
|
|
45
|
+
const split = line.split(":");
|
|
46
|
+
if (split.length !== 3) {
|
|
47
|
+
throw new Error(`UNEXPECTED LOCATION FORMAT (CHECK THE DEPTH PARAMETER): ${line} (Expected 'file:line:column')`);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
'file': split[0],
|
|
51
|
+
'line': Number(split[1]),
|
|
52
|
+
'column': Number(split[2]),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function location_to_string(location) {
|
|
56
|
+
return `${location.file}:${location.line}:${location.column}`;
|
|
57
|
+
}
|
|
@@ -1,30 +1,7 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.implement_me = implement_me;
|
|
27
|
-
const
|
|
4
|
+
const get_location_info_1 = require("../get_location_info");
|
|
28
5
|
/**
|
|
29
6
|
* use this function as a placeholder when you want to compile but have not fully developed all functionality yet.
|
|
30
7
|
*
|
|
@@ -33,5 +10,5 @@ const pi = __importStar(require("exupery-core-internals"));
|
|
|
33
10
|
* @param message the string to be printed to stderr
|
|
34
11
|
*/
|
|
35
12
|
function implement_me() {
|
|
36
|
-
throw new Error(`IMPLEMENT ME @ ${
|
|
13
|
+
throw new Error(`IMPLEMENT ME @ ${(0, get_location_info_1.location_to_string)((0, get_location_info_1.get_location_info)(1))}`);
|
|
37
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exupery-core-dev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"description": "a exupery package that contains functions that are useful during development",
|
|
6
6
|
"author": "Corno",
|
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"url": "git+https://github.com/corno/exupery-core.git"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"exupery-core-internals": "^0.
|
|
27
|
+
"exupery-core-internals": "^0.2.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^24.9.1"
|
|
28
31
|
}
|
|
29
32
|
}
|