1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.uniq = exports.isFunction = exports.isClass = exports.last = exports.nameValueToObject = exports.flatten = void 0;
|
4 | const function_tokenizer_1 = require("./function-tokenizer");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function flatten(array) {
|
15 | const result = [];
|
16 | array.forEach((arr) => {
|
17 | arr.forEach((item) => {
|
18 | result.push(item);
|
19 | });
|
20 | });
|
21 | return result;
|
22 | }
|
23 | exports.flatten = flatten;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | function nameValueToObject(name, value) {
|
36 | let obj = name;
|
37 | if (typeof obj === 'string' || typeof obj === 'symbol') {
|
38 | return { [name]: value };
|
39 | }
|
40 | return obj;
|
41 | }
|
42 | exports.nameValueToObject = nameValueToObject;
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | function last(arr) {
|
53 | return arr[arr.length - 1];
|
54 | }
|
55 | exports.last = last;
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | function isClass(fn) {
|
63 |
|
64 | if (typeof fn !== 'function') {
|
65 | return false;
|
66 | }
|
67 |
|
68 | const tokenizer = (0, function_tokenizer_1.createTokenizer)(fn.toString());
|
69 | const first = tokenizer.next();
|
70 | if (first.type === 'class') {
|
71 | return true;
|
72 | }
|
73 | const second = tokenizer.next();
|
74 | if (first.type === 'function' && second.value) {
|
75 | if (second.value[0] === second.value[0].toUpperCase()) {
|
76 | return true;
|
77 | }
|
78 | }
|
79 | return false;
|
80 | }
|
81 | exports.isClass = isClass;
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | function isFunction(val) {
|
92 | return typeof val === 'function';
|
93 | }
|
94 | exports.isFunction = isFunction;
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | function uniq(arr) {
|
105 | return Array.from(new Set(arr));
|
106 | }
|
107 | exports.uniq = uniq;
|
108 |
|
\ | No newline at end of file |