@xylabs/function-name 5.0.83 → 5.0.84
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/README.md
CHANGED
|
@@ -37,16 +37,22 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
37
37
|
function functionName(depth?): string;
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
Returns the name of the calling function by inspecting the stack trace.
|
|
41
|
+
|
|
40
42
|
## Parameters
|
|
41
43
|
|
|
42
44
|
### depth?
|
|
43
45
|
|
|
44
46
|
`number` = `2`
|
|
45
47
|
|
|
48
|
+
The stack frame depth to read the function name from (default: 2).
|
|
49
|
+
|
|
46
50
|
## Returns
|
|
47
51
|
|
|
48
52
|
`string`
|
|
49
53
|
|
|
54
|
+
The function name, or '<unknown>' if it cannot be determined.
|
|
55
|
+
|
|
50
56
|
|
|
51
57
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
|
52
58
|
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the name of the calling function by inspecting the stack trace.
|
|
3
|
+
* @param depth - The stack frame depth to read the function name from (default: 2).
|
|
4
|
+
* @returns The function name, or '<unknown>' if it cannot be determined.
|
|
5
|
+
*/
|
|
1
6
|
export declare const functionName: (depth?: number) => string;
|
|
2
7
|
//# sourceMappingURL=functionName.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functionName.d.ts","sourceRoot":"","sources":["../../src/functionName.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,GAAI,cAAS,WAoBrC,CAAA"}
|
|
1
|
+
{"version":3,"file":"functionName.d.ts","sourceRoot":"","sources":["../../src/functionName.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,cAAS,WAoBrC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/functionName.ts"],"sourcesContent":["import { handleError } from '@xylabs/error'\nimport { isNumber } from '@xylabs/typeof'\n\nexport const functionName = (depth = 2) => {\n try {\n throw new Error('Getting function name')\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | undefined\n const stackParts = error.stack?.split('\\n')[depth].split(' ')\n const funcName\n = stackParts?.find((item, index) => {\n if (item.length > 0 && item !== 'at') {\n // check if constructor\n if (item === 'new') {\n newIndex = index\n }\n return true\n }\n }) ?? '<unknown>'\n return isNumber(newIndex) ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;
|
|
1
|
+
{"version":3,"sources":["../../src/functionName.ts"],"sourcesContent":["import { handleError } from '@xylabs/error'\nimport { isNumber } from '@xylabs/typeof'\n\n/**\n * Returns the name of the calling function by inspecting the stack trace.\n * @param depth - The stack frame depth to read the function name from (default: 2).\n * @returns The function name, or '<unknown>' if it cannot be determined.\n */\nexport const functionName = (depth = 2) => {\n try {\n throw new Error('Getting function name')\n } catch (ex) {\n return handleError(ex, (error) => {\n let newIndex: number | undefined\n const stackParts = error.stack?.split('\\n')[depth].split(' ')\n const funcName\n = stackParts?.find((item, index) => {\n if (item.length > 0 && item !== 'at') {\n // check if constructor\n if (item === 'new') {\n newIndex = index\n }\n return true\n }\n }) ?? '<unknown>'\n return isNumber(newIndex) ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n })\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAOlB,IAAM,eAAe,CAAC,QAAQ,MAAM;AACzC,MAAI;AACF,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACzC,SAAS,IAAI;AACX,WAAO,YAAY,IAAI,CAAC,UAAU;AAChC,UAAI;AACJ,YAAM,aAAa,MAAM,OAAO,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG;AAC5D,YAAM,WACF,YAAY,KAAK,CAAC,MAAM,UAAU;AAClC,YAAI,KAAK,SAAS,KAAK,SAAS,MAAM;AAEpC,cAAI,SAAS,OAAO;AAClB,uBAAW;AAAA,UACb;AACA,iBAAO;AAAA,QACT;AAAA,MACF,CAAC,KAAK;AACR,aAAO,SAAS,QAAQ,IAAI,GAAG,QAAQ,IAAI,aAAa,WAAW,CAAC,CAAC,KAAK;AAAA,IAC5E,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/function-name",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.84",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"function",
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"!**/*.test.*"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@xylabs/error": "~5.0.
|
|
47
|
-
"@xylabs/typeof": "~5.0.
|
|
46
|
+
"@xylabs/error": "~5.0.84",
|
|
47
|
+
"@xylabs/typeof": "~5.0.84"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
51
|
-
"@xylabs/tsconfig": "~7.4.
|
|
50
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.13",
|
|
51
|
+
"@xylabs/tsconfig": "~7.4.13",
|
|
52
52
|
"typescript": "~5.9.3",
|
|
53
53
|
"vitest": "~4.0.18"
|
|
54
54
|
},
|