@bbn/bbn 1.0.87 → 1.0.88
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/dist/bundle.d.ts +8 -0
- package/dist/bundle.js +55 -29
- package/dist/fn/misc/analyzeFunction.d.ts +8 -0
- package/dist/fn/misc/analyzeFunction.js +55 -29
- package/package.json +4 -1
package/dist/bundle.d.ts
CHANGED
|
@@ -1591,6 +1591,14 @@ declare module "fn/ajax/ajax" {
|
|
|
1591
1591
|
export { ajax };
|
|
1592
1592
|
}
|
|
1593
1593
|
declare module "fn/misc/analyzeFunction" {
|
|
1594
|
+
/**
|
|
1595
|
+
* Analyzes the given function and extracts details about its structure.
|
|
1596
|
+
*
|
|
1597
|
+
* @function analyzeFunction
|
|
1598
|
+
* @param {Function} fn - The function to analyze.
|
|
1599
|
+
* @returns {Object} An object containing details about the function.
|
|
1600
|
+
* @throws {Error} When unexpected syntax is encountered while parsing.
|
|
1601
|
+
*/
|
|
1594
1602
|
const analyzeFunction: (fn: any) => {
|
|
1595
1603
|
body: any;
|
|
1596
1604
|
args: any[];
|
package/dist/bundle.js
CHANGED
|
@@ -3212,9 +3212,19 @@
|
|
|
3212
3212
|
"use strict";
|
|
3213
3213
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3214
3214
|
exports.analyzeFunction = void 0;
|
|
3215
|
+
/**
|
|
3216
|
+
* Analyzes the given function and extracts details about its structure.
|
|
3217
|
+
*
|
|
3218
|
+
* @function analyzeFunction
|
|
3219
|
+
* @param {Function} fn - The function to analyze.
|
|
3220
|
+
* @returns {Object} An object containing details about the function.
|
|
3221
|
+
* @throws {Error} When unexpected syntax is encountered while parsing.
|
|
3222
|
+
*/
|
|
3215
3223
|
const analyzeFunction = function (fn) {
|
|
3216
|
-
const
|
|
3217
|
-
|
|
3224
|
+
const all = typeof fn === 'function' ? fn.toString() : fn;
|
|
3225
|
+
if (typeof all !== 'string') {
|
|
3226
|
+
throw Error('Unexpected type ' + typeof fn + ' while parsing function');
|
|
3227
|
+
}
|
|
3218
3228
|
let exp = '';
|
|
3219
3229
|
let isArrow = false;
|
|
3220
3230
|
let isAsync = false;
|
|
@@ -3229,12 +3239,33 @@
|
|
|
3229
3239
|
let escapable = ['"', "'", '`'];
|
|
3230
3240
|
let isEscaped = false;
|
|
3231
3241
|
let settingDefault = false;
|
|
3242
|
+
let isComment = false;
|
|
3243
|
+
let isCommentLine = false;
|
|
3232
3244
|
for (let i = 0; i < all.length; i++) {
|
|
3233
|
-
|
|
3245
|
+
// Handle string literals
|
|
3246
|
+
if (!isComment && all[i] === '/' && all[i + 1] === '*') {
|
|
3247
|
+
isComment = true;
|
|
3248
|
+
exp = '';
|
|
3249
|
+
}
|
|
3250
|
+
else if (all[i] === '*' && all[i + 1] === '/') {
|
|
3251
|
+
isComment = false;
|
|
3252
|
+
}
|
|
3253
|
+
else if (!isCommentLine && all[i] === '/' && all[i + 1] === '/') {
|
|
3254
|
+
isCommentLine = true;
|
|
3255
|
+
exp = '';
|
|
3256
|
+
}
|
|
3257
|
+
else if (all[i] === '\n') {
|
|
3258
|
+
isCommentLine = false;
|
|
3259
|
+
}
|
|
3260
|
+
else if (isComment || isCommentLine) {
|
|
3261
|
+
continue;
|
|
3262
|
+
}
|
|
3263
|
+
else if (all[i] === currentQuote && !isEscaped && currentQuote) {
|
|
3234
3264
|
currentQuote = '';
|
|
3235
3265
|
exp += all[i];
|
|
3236
3266
|
}
|
|
3237
3267
|
else if (currentQuote) {
|
|
3268
|
+
isEscaped = all[i] === '\\' && !isEscaped;
|
|
3238
3269
|
exp += all[i];
|
|
3239
3270
|
}
|
|
3240
3271
|
else if (escapable.includes(all[i]) && !isEscaped) {
|
|
@@ -3256,13 +3287,13 @@
|
|
|
3256
3287
|
else if (all[i] === ')') {
|
|
3257
3288
|
if (parOpened === parClosed + 1) {
|
|
3258
3289
|
if (settingDefault) {
|
|
3259
|
-
currentArg
|
|
3290
|
+
currentArg['default'] = exp.trim();
|
|
3260
3291
|
settingDefault = false;
|
|
3261
3292
|
}
|
|
3262
3293
|
else if (exp) {
|
|
3263
|
-
currentArg
|
|
3294
|
+
currentArg['name'] = exp.trim();
|
|
3264
3295
|
}
|
|
3265
|
-
if (currentArg
|
|
3296
|
+
if (currentArg['name'] || currentArg['default']) {
|
|
3266
3297
|
args.push(currentArg);
|
|
3267
3298
|
currentArg = {};
|
|
3268
3299
|
}
|
|
@@ -3270,37 +3301,32 @@
|
|
|
3270
3301
|
}
|
|
3271
3302
|
parClosed++;
|
|
3272
3303
|
}
|
|
3273
|
-
else if (all[i] === '=') {
|
|
3274
|
-
if (
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
currentArg = {};
|
|
3279
|
-
exp = '';
|
|
3280
|
-
}
|
|
3281
|
-
isArrow = true;
|
|
3282
|
-
i++;
|
|
3283
|
-
continue;
|
|
3284
|
-
}
|
|
3285
|
-
else if (parOpened > parClosed && !settingDefault) {
|
|
3286
|
-
currentArg.name = exp.trim();
|
|
3304
|
+
else if (all[i] === '=' && all[i + 1] === '>') {
|
|
3305
|
+
if (exp.trim() !== '' && parOpened === parClosed) {
|
|
3306
|
+
currentArg['name'] = exp.trim();
|
|
3307
|
+
args.push(currentArg);
|
|
3308
|
+
currentArg = {};
|
|
3287
3309
|
exp = '';
|
|
3288
|
-
settingDefault = true;
|
|
3289
|
-
}
|
|
3290
|
-
else {
|
|
3291
|
-
exp += all[i];
|
|
3292
3310
|
}
|
|
3311
|
+
isArrow = true;
|
|
3312
|
+
i++;
|
|
3313
|
+
continue;
|
|
3314
|
+
}
|
|
3315
|
+
else if (all[i] === '=' && parOpened > parClosed && !settingDefault) {
|
|
3316
|
+
currentArg['name'] = exp.trim();
|
|
3317
|
+
exp = '';
|
|
3318
|
+
settingDefault = true;
|
|
3293
3319
|
}
|
|
3294
3320
|
else if (all[i] === ',') {
|
|
3295
3321
|
if (parOpened > parClosed) {
|
|
3296
3322
|
if (settingDefault) {
|
|
3297
|
-
currentArg
|
|
3323
|
+
currentArg['default'] = exp.trim();
|
|
3298
3324
|
settingDefault = false;
|
|
3299
3325
|
}
|
|
3300
3326
|
else if (exp) {
|
|
3301
|
-
currentArg
|
|
3327
|
+
currentArg['name'] = exp.trim();
|
|
3302
3328
|
}
|
|
3303
|
-
if (currentArg
|
|
3329
|
+
if (currentArg['name'] || currentArg['default']) {
|
|
3304
3330
|
args.push(currentArg);
|
|
3305
3331
|
currentArg = {};
|
|
3306
3332
|
}
|
|
@@ -3311,11 +3337,11 @@
|
|
|
3311
3337
|
}
|
|
3312
3338
|
}
|
|
3313
3339
|
else if (all[i] === '{' || all[i] === '}') {
|
|
3314
|
-
body =
|
|
3340
|
+
body = all.substring(i).trim();
|
|
3315
3341
|
break;
|
|
3316
3342
|
}
|
|
3317
3343
|
else if (isArrow) {
|
|
3318
|
-
body =
|
|
3344
|
+
body = all.substring(all.indexOf('=>') + 2).trim();
|
|
3319
3345
|
break;
|
|
3320
3346
|
}
|
|
3321
3347
|
else if (all[i] === ' ') {
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analyzes the given function and extracts details about its structure.
|
|
3
|
+
*
|
|
4
|
+
* @function analyzeFunction
|
|
5
|
+
* @param {Function} fn - The function to analyze.
|
|
6
|
+
* @returns {Object} An object containing details about the function.
|
|
7
|
+
* @throws {Error} When unexpected syntax is encountered while parsing.
|
|
8
|
+
*/
|
|
1
9
|
declare const analyzeFunction: (fn: any) => {
|
|
2
10
|
body: any;
|
|
3
11
|
args: any[];
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { md5 } from '../string/md5';
|
|
2
|
+
/**
|
|
3
|
+
* Analyzes the given function and extracts details about its structure.
|
|
4
|
+
*
|
|
5
|
+
* @function analyzeFunction
|
|
6
|
+
* @param {Function} fn - The function to analyze.
|
|
7
|
+
* @returns {Object} An object containing details about the function.
|
|
8
|
+
* @throws {Error} When unexpected syntax is encountered while parsing.
|
|
9
|
+
*/
|
|
2
10
|
const analyzeFunction = function (fn) {
|
|
3
|
-
const
|
|
4
|
-
|
|
11
|
+
const all = typeof fn === 'function' ? fn.toString() : fn;
|
|
12
|
+
if (typeof all !== 'string') {
|
|
13
|
+
throw Error('Unexpected type ' + typeof fn + ' while parsing function');
|
|
14
|
+
}
|
|
5
15
|
let exp = '';
|
|
6
16
|
let isArrow = false;
|
|
7
17
|
let isAsync = false;
|
|
@@ -16,12 +26,33 @@ const analyzeFunction = function (fn) {
|
|
|
16
26
|
let escapable = ['"', "'", '`'];
|
|
17
27
|
let isEscaped = false;
|
|
18
28
|
let settingDefault = false;
|
|
29
|
+
let isComment = false;
|
|
30
|
+
let isCommentLine = false;
|
|
19
31
|
for (let i = 0; i < all.length; i++) {
|
|
20
|
-
|
|
32
|
+
// Handle string literals
|
|
33
|
+
if (!isComment && all[i] === '/' && all[i + 1] === '*') {
|
|
34
|
+
isComment = true;
|
|
35
|
+
exp = '';
|
|
36
|
+
}
|
|
37
|
+
else if (all[i] === '*' && all[i + 1] === '/') {
|
|
38
|
+
isComment = false;
|
|
39
|
+
}
|
|
40
|
+
else if (!isCommentLine && all[i] === '/' && all[i + 1] === '/') {
|
|
41
|
+
isCommentLine = true;
|
|
42
|
+
exp = '';
|
|
43
|
+
}
|
|
44
|
+
else if (all[i] === '\n') {
|
|
45
|
+
isCommentLine = false;
|
|
46
|
+
}
|
|
47
|
+
else if (isComment || isCommentLine) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
else if (all[i] === currentQuote && !isEscaped && currentQuote) {
|
|
21
51
|
currentQuote = '';
|
|
22
52
|
exp += all[i];
|
|
23
53
|
}
|
|
24
54
|
else if (currentQuote) {
|
|
55
|
+
isEscaped = all[i] === '\\' && !isEscaped;
|
|
25
56
|
exp += all[i];
|
|
26
57
|
}
|
|
27
58
|
else if (escapable.includes(all[i]) && !isEscaped) {
|
|
@@ -43,13 +74,13 @@ const analyzeFunction = function (fn) {
|
|
|
43
74
|
else if (all[i] === ')') {
|
|
44
75
|
if (parOpened === parClosed + 1) {
|
|
45
76
|
if (settingDefault) {
|
|
46
|
-
currentArg
|
|
77
|
+
currentArg['default'] = exp.trim();
|
|
47
78
|
settingDefault = false;
|
|
48
79
|
}
|
|
49
80
|
else if (exp) {
|
|
50
|
-
currentArg
|
|
81
|
+
currentArg['name'] = exp.trim();
|
|
51
82
|
}
|
|
52
|
-
if (currentArg
|
|
83
|
+
if (currentArg['name'] || currentArg['default']) {
|
|
53
84
|
args.push(currentArg);
|
|
54
85
|
currentArg = {};
|
|
55
86
|
}
|
|
@@ -57,37 +88,32 @@ const analyzeFunction = function (fn) {
|
|
|
57
88
|
}
|
|
58
89
|
parClosed++;
|
|
59
90
|
}
|
|
60
|
-
else if (all[i] === '=') {
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
currentArg = {};
|
|
66
|
-
exp = '';
|
|
67
|
-
}
|
|
68
|
-
isArrow = true;
|
|
69
|
-
i++;
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
else if (parOpened > parClosed && !settingDefault) {
|
|
73
|
-
currentArg.name = exp.trim();
|
|
91
|
+
else if (all[i] === '=' && all[i + 1] === '>') {
|
|
92
|
+
if (exp.trim() !== '' && parOpened === parClosed) {
|
|
93
|
+
currentArg['name'] = exp.trim();
|
|
94
|
+
args.push(currentArg);
|
|
95
|
+
currentArg = {};
|
|
74
96
|
exp = '';
|
|
75
|
-
settingDefault = true;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
exp += all[i];
|
|
79
97
|
}
|
|
98
|
+
isArrow = true;
|
|
99
|
+
i++;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
else if (all[i] === '=' && parOpened > parClosed && !settingDefault) {
|
|
103
|
+
currentArg['name'] = exp.trim();
|
|
104
|
+
exp = '';
|
|
105
|
+
settingDefault = true;
|
|
80
106
|
}
|
|
81
107
|
else if (all[i] === ',') {
|
|
82
108
|
if (parOpened > parClosed) {
|
|
83
109
|
if (settingDefault) {
|
|
84
|
-
currentArg
|
|
110
|
+
currentArg['default'] = exp.trim();
|
|
85
111
|
settingDefault = false;
|
|
86
112
|
}
|
|
87
113
|
else if (exp) {
|
|
88
|
-
currentArg
|
|
114
|
+
currentArg['name'] = exp.trim();
|
|
89
115
|
}
|
|
90
|
-
if (currentArg
|
|
116
|
+
if (currentArg['name'] || currentArg['default']) {
|
|
91
117
|
args.push(currentArg);
|
|
92
118
|
currentArg = {};
|
|
93
119
|
}
|
|
@@ -98,11 +124,11 @@ const analyzeFunction = function (fn) {
|
|
|
98
124
|
}
|
|
99
125
|
}
|
|
100
126
|
else if (all[i] === '{' || all[i] === '}') {
|
|
101
|
-
body =
|
|
127
|
+
body = all.substring(i).trim();
|
|
102
128
|
break;
|
|
103
129
|
}
|
|
104
130
|
else if (isArrow) {
|
|
105
|
-
body =
|
|
131
|
+
body = all.substring(all.indexOf('=>') + 2).trim();
|
|
106
132
|
break;
|
|
107
133
|
}
|
|
108
134
|
else if (all[i] === ' ') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bbn/bbn",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.88",
|
|
4
4
|
"description": "Javascript toolkit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"author": "Thomas Nabet <thomas.nabet@gmail.com>",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"devDependencies": {
|
|
21
|
+
"mocha": "^10.2.0",
|
|
21
22
|
"typescript": "^5.2.2"
|
|
22
23
|
},
|
|
23
24
|
"bugs": {
|
|
@@ -26,7 +27,9 @@
|
|
|
26
27
|
"homepage": "https://github.com/nabab/bbn-js#readme",
|
|
27
28
|
"dependencies": {
|
|
28
29
|
"axios": "^1.5.1",
|
|
30
|
+
"chai": "^4.3.10",
|
|
29
31
|
"dayjs": "^1.11.10",
|
|
32
|
+
"jsdom-global": "^3.0.2",
|
|
30
33
|
"typescript-bundle": "^1.0.18"
|
|
31
34
|
},
|
|
32
35
|
"directories": {
|