@ts-for-gir/lib 4.0.0-beta.22 → 4.0.0-beta.24

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/lib/utils.d.ts DELETED
@@ -1,267 +0,0 @@
1
- import lodash from 'lodash';
2
- import { FileInfo } from './types/index.js';
3
- import { inspect } from 'util';
4
- export { inspect };
5
- export declare const __filename: string;
6
- export declare const __dirname: string;
7
- /**
8
- * Performs a deep comparison between two values to determine if they are
9
- * equivalent.
10
- *
11
- * **Note:** This method supports comparing arrays, array buffers, booleans,
12
- * date objects, error objects, maps, numbers, `Object` objects, regexes,
13
- * sets, strings, symbols, and typed arrays. `Object` objects are compared
14
- * by their own, not inherited, enumerable properties. Functions and DOM
15
- * nodes are **not** supported.
16
- *
17
- * @category Lang
18
- * @param value The value to compare.
19
- * @param other The other value to compare.
20
- * @returns Returns `true` if the values are equivalent, else `false`.
21
- * @example
22
- *
23
- * var object = { 'user': 'fred' };
24
- * var other = { 'user': 'fred' };
25
- *
26
- * _.isEqual(object, other);
27
- * // => true
28
- *
29
- * object === other;
30
- * // => false
31
- */
32
- export declare const isEqual: (value: any, other: any) => boolean;
33
- /**
34
- * Creates an array of values by running each element in collection through iteratee. The iteratee is
35
- * invoked with three arguments: (value, index|key, collection).
36
- *
37
- * Many lodash methods are guarded to work as iteratees for methods like _.every, _.filter, _.map, _.mapValues,
38
- * _.reject, and _.some.
39
- *
40
- * The guarded methods are:
41
- * ary, callback, chunk, clone, create, curry, curryRight, drop, dropRight, every, fill, flatten, invert, max,
42
- * min, parseInt, slice, sortBy, take, takeRight, template, trim, trimLeft, trimRight, trunc, random, range,
43
- * sample, some, sum, uniq, and words
44
- *
45
- * @param collection The collection to iterate over.
46
- * @param iteratee The function invoked per iteration.
47
- * @return Returns the new mapped array.
48
- */
49
- export declare const map: {
50
- <T, TResult>(collection: T[] | null | undefined, iteratee: lodash.ArrayIterator<T, TResult>): TResult[];
51
- <T, TResult>(collection: lodash.List<T> | null | undefined, iteratee: lodash.ListIterator<T, TResult>): TResult[];
52
- <T>(collection: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined): T[];
53
- <T extends object, TResult>(collection: T | null | undefined, iteratee: lodash.ObjectIterator<T, TResult>): TResult[];
54
- <T, K extends keyof T>(collection: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined, iteratee: K): Array<T[K]>;
55
- <T>(collection: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined, iteratee?: string): any[];
56
- <T>(collection: lodash.Dictionary<T> | lodash.NumericDictionary<T> | null | undefined, iteratee?: object): boolean[];
57
- };
58
- /**
59
- * Iterates over elements of collection, returning the first element predicate returns truthy for.
60
- * The predicate is invoked with three arguments: (value, index|key, collection).
61
- *
62
- * @param collection The collection to search.
63
- * @param predicate The function invoked per iteration.
64
- * @param fromIndex The index to search from.
65
- * @return Returns the matched element, else undefined.
66
- */
67
- export declare const find: {
68
- <T, S extends T>(collection: lodash.List<T> | null | undefined, predicate: lodash.ListIteratorTypeGuard<T, S>, fromIndex?: number): S | undefined;
69
- <T>(collection: lodash.List<T> | null | undefined, predicate?: lodash.ListIterateeCustom<T, boolean>, fromIndex?: number): T | undefined;
70
- <T extends object, S extends T[keyof T]>(collection: T | null | undefined, predicate: lodash.ObjectIteratorTypeGuard<T, S>, fromIndex?: number): S | undefined;
71
- <T extends object>(collection: T | null | undefined, predicate?: lodash.ObjectIterateeCustom<T, boolean>, fromIndex?: number): T[keyof T] | undefined;
72
- };
73
- /**
74
- * Recursively merges own and inherited enumerable properties of source
75
- * objects into the destination object, skipping source properties that resolve
76
- * to `undefined`. Array and plain object properties are merged recursively.
77
- * Other objects and value types are overridden by assignment. Source objects
78
- * are applied from left to right. Subsequent sources overwrite property
79
- * assignments of previous sources.
80
- *
81
- * **Note:** This method mutates `object`.
82
- *
83
- * @category Object
84
- * @param object The destination object.
85
- * @param [sources] The source objects.
86
- * @returns Returns `object`.
87
- * @example
88
- *
89
- * var users = {
90
- * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
91
- * };
92
- *
93
- * var ages = {
94
- * 'data': [{ 'age': 36 }, { 'age': 40 }]
95
- * };
96
- *
97
- * _.merge(users, ages);
98
- * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
99
- */
100
- export declare const merge: {
101
- <TObject, TSource>(object: TObject, source: TSource): TObject & TSource;
102
- <TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2;
103
- <TObject, TSource1, TSource2, TSource3>(object: TObject, source1: TSource1, source2: TSource2, source3: TSource3): TObject & TSource1 & TSource2 & TSource3;
104
- <TObject, TSource1, TSource2, TSource3, TSource4>(object: TObject, source1: TSource1, source2: TSource2, source3: TSource3, source4: TSource4): TObject & TSource1 & TSource2 & TSource3 & TSource4;
105
- (object: any, ...otherArgs: any[]): any;
106
- };
107
- /**
108
- * Creates a shallow clone of value.
109
- *
110
- * Note: This method is loosely based on the structured clone algorithm and supports cloning arrays,
111
- * array buffers, booleans, date objects, maps, numbers, Object objects, regex's, sets, strings, symbols,
112
- * and typed arrays. The own enumerable properties of arguments objects are cloned as plain objects. An empty
113
- * object is returned for not cloneable values such as error objects, functions, DOM nodes, and WeakMaps.
114
- *
115
- * @param value The value to clone.
116
- * @return Returns the cloned value.
117
- */
118
- export declare const clone: <T>(value: T) => T;
119
- /**
120
- * This method is like clone except that it recursively clones value.
121
- *
122
- * @param value The value to recursively clone.
123
- * @return Returns the deep cloned value.
124
- */
125
- export declare const cloneDeep: <T>(value: T) => T;
126
- /**
127
- * Split a package name into namespace and version
128
- */
129
- export declare const splitModuleName: (packageName: string) => {
130
- packageName: string;
131
- namespace: string;
132
- version: string;
133
- };
134
- /** Remove namespace prefix */
135
- export declare const removeNamespace: (type: string, namespace: string) => string;
136
- /** Remove class module name prefix */
137
- export declare const removeClassModule: (type: string, namespace: string) => string;
138
- /**
139
- * Add namespace prefix
140
- */
141
- export declare const addNamespace: (type: string, namespace: string) => string;
142
- /**
143
- * Removes line breaks and consecutive white spaces from a given string
144
- * @param str
145
- * @returns
146
- */
147
- export declare const cleanString: (str: string) => string;
148
- /**
149
- * Checking whether some variable is iterable
150
- * @see https://stackoverflow.com/a/32538867
151
- * @param obj Variable to check for iterable
152
- * @returns Whether the variable is iterable or not
153
- */
154
- export declare const isIterable: (obj: unknown[]) => boolean;
155
- /**
156
- * Checking whether a string is numeric
157
- * @param str The string to check
158
- * @returns Whether the string is numeric or not
159
- */
160
- export declare const isNumeric: (str: string) => boolean;
161
- /**
162
- * Get the first character of a string
163
- * @param str The string to get the first character from
164
- * @returns The first character
165
- */
166
- export declare const getFirstChar: (str: string) => string;
167
- /**
168
- * Get the last character of a string
169
- * @param str The string to get the last character from
170
- * @returns The last character
171
- */
172
- export declare const getLastChar: (str: string) => string;
173
- /**
174
- * Check if the first character of a string is numeric
175
- * @param str The string to check
176
- * @returns Whether the first character is numeric or not
177
- */
178
- export declare const isFirstCharNumeric: (str: string) => boolean;
179
- /**
180
- * Convert a string to camelCase, keeps the first alphabet character as it is.
181
- * @param str The string to convert
182
- * @returns The converted string
183
- */
184
- export declare const camelCase: (str: string) => string;
185
- /**
186
- * Convert a string to `lowerCamelCase`
187
- * @param str The string to convert
188
- * @returns The converted string
189
- */
190
- export declare const lowerCamelCase: (str: string) => string;
191
- /**
192
- * Convert a string to `PascalCase`
193
- * @param str The string to convert
194
- * @returns The converted string
195
- */
196
- export declare const pascalCase: (str: string) => string;
197
- /** Alias for {@link pascalCase} */
198
- export declare const upperCamelCase: (str: string) => string;
199
- /**
200
- * Convert a string to `snake_case`
201
- * @param str The string to convert
202
- * @returns The converted string
203
- */
204
- export declare const snakeCase: (str: string) => string;
205
- /**
206
- * Convert a string to `kebab-case`
207
- * @param str The string to convert
208
- * @returns The converted string
209
- */
210
- export declare const kebabCase: (str: string) => string;
211
- /** Alias for {@link kebabCase} */
212
- export declare const slugCase: (str: string) => string;
213
- export declare const underscores: (str: string) => string;
214
- /**
215
- * Find a file in a list of directories
216
- * @param dirs The directories to search in
217
- * @param filename The filename to search for
218
- * @returns The file info
219
- */
220
- export declare const findFilesInDirs: (dirs: string[], filename: string) => Promise<FileInfo[]>;
221
- /**
222
- * Find a file in a list of directories (sync)
223
- * @param dirs The directories to search in
224
- * @param filename The filename to search for
225
- * @returns The file info
226
- */
227
- export declare const findFilesInDirsSync: (dirs: string[], filename: string) => FileInfo[];
228
- /**
229
- * Read a JSON file
230
- * @param filePath The path to the JSON file
231
- * @returns The parsed JSON
232
- */
233
- export declare const readJsonFile: <T = unknown>(filePath: string) => Promise<T>;
234
- /**
235
- * Union (a ∪ b): create a set that contains the elements of both set a and set b.
236
- * See https://2ality.com/2015/01/es6-set-operations.html#union
237
- * @param target
238
- * @param source
239
- */
240
- export declare const union: <T>(target: Set<T> | T[], source: Set<T> | T[]) => Set<T>;
241
- export declare const stripParamNames: (func: string, ignoreTail?: boolean) => string;
242
- /**
243
- * Check if a line is a comment line
244
- * @param line The line to check
245
- * @returns Whether the line is a comment line or not
246
- */
247
- export declare const isCommentLine: (line: string) => boolean;
248
- /**
249
- * Add indents to a string
250
- * @param indents The number of indents
251
- * @param spaceForIndent The number of spaces for each indent
252
- * @returns The indented string
253
- */
254
- export declare const generateIndent: (indents?: number, spaceForIndent?: number) => string;
255
- /**
256
- * Convert a GirBoolean to a boolean
257
- * @param boolStr The GirBoolean string
258
- * @param defaultVal The default value
259
- * @returns The boolean value
260
- */
261
- export declare const girBool: (boolStr: string | undefined, defaultVal?: boolean) => boolean;
262
- /**
263
- * Returns `true` if the definitions in `d1` and `d2` have equivalent signatures
264
- * @param d1
265
- * @param d2
266
- */
267
- export declare const signaturesMatch: (d1: string, d2: string) => boolean;
package/lib/utils.js DELETED
@@ -1,417 +0,0 @@
1
- /* eslint-disable @typescript-eslint/unbound-method */
2
- import lodash from 'lodash';
3
- import { join, dirname } from 'path';
4
- import { existsSync } from 'fs';
5
- import { readFile } from 'fs/promises';
6
- import { glob, globSync } from 'glob';
7
- import { fileURLToPath } from 'url';
8
- import { inspect } from 'util';
9
- import { Logger } from './logger.js';
10
- import { COMMENT_REG_EXP, PARAM_REG_EXP, OPT_PARAM_REG_EXP } from './constants.js';
11
- export { inspect };
12
- // Get __filename on ESM
13
- export const __filename = fileURLToPath(import.meta.url);
14
- // Get __dirname on ESM
15
- export const __dirname = dirname(__filename);
16
- /**
17
- * Performs a deep comparison between two values to determine if they are
18
- * equivalent.
19
- *
20
- * **Note:** This method supports comparing arrays, array buffers, booleans,
21
- * date objects, error objects, maps, numbers, `Object` objects, regexes,
22
- * sets, strings, symbols, and typed arrays. `Object` objects are compared
23
- * by their own, not inherited, enumerable properties. Functions and DOM
24
- * nodes are **not** supported.
25
- *
26
- * @category Lang
27
- * @param value The value to compare.
28
- * @param other The other value to compare.
29
- * @returns Returns `true` if the values are equivalent, else `false`.
30
- * @example
31
- *
32
- * var object = { 'user': 'fred' };
33
- * var other = { 'user': 'fred' };
34
- *
35
- * _.isEqual(object, other);
36
- * // => true
37
- *
38
- * object === other;
39
- * // => false
40
- */
41
- export const isEqual = lodash.isEqual;
42
- /**
43
- * Creates an array of values by running each element in collection through iteratee. The iteratee is
44
- * invoked with three arguments: (value, index|key, collection).
45
- *
46
- * Many lodash methods are guarded to work as iteratees for methods like _.every, _.filter, _.map, _.mapValues,
47
- * _.reject, and _.some.
48
- *
49
- * The guarded methods are:
50
- * ary, callback, chunk, clone, create, curry, curryRight, drop, dropRight, every, fill, flatten, invert, max,
51
- * min, parseInt, slice, sortBy, take, takeRight, template, trim, trimLeft, trimRight, trunc, random, range,
52
- * sample, some, sum, uniq, and words
53
- *
54
- * @param collection The collection to iterate over.
55
- * @param iteratee The function invoked per iteration.
56
- * @return Returns the new mapped array.
57
- */
58
- export const map = lodash.map;
59
- /**
60
- * Iterates over elements of collection, returning the first element predicate returns truthy for.
61
- * The predicate is invoked with three arguments: (value, index|key, collection).
62
- *
63
- * @param collection The collection to search.
64
- * @param predicate The function invoked per iteration.
65
- * @param fromIndex The index to search from.
66
- * @return Returns the matched element, else undefined.
67
- */
68
- export const find = lodash.find;
69
- /**
70
- * Recursively merges own and inherited enumerable properties of source
71
- * objects into the destination object, skipping source properties that resolve
72
- * to `undefined`. Array and plain object properties are merged recursively.
73
- * Other objects and value types are overridden by assignment. Source objects
74
- * are applied from left to right. Subsequent sources overwrite property
75
- * assignments of previous sources.
76
- *
77
- * **Note:** This method mutates `object`.
78
- *
79
- * @category Object
80
- * @param object The destination object.
81
- * @param [sources] The source objects.
82
- * @returns Returns `object`.
83
- * @example
84
- *
85
- * var users = {
86
- * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
87
- * };
88
- *
89
- * var ages = {
90
- * 'data': [{ 'age': 36 }, { 'age': 40 }]
91
- * };
92
- *
93
- * _.merge(users, ages);
94
- * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
95
- */
96
- export const merge = lodash.merge;
97
- /**
98
- * Creates a shallow clone of value.
99
- *
100
- * Note: This method is loosely based on the structured clone algorithm and supports cloning arrays,
101
- * array buffers, booleans, date objects, maps, numbers, Object objects, regex's, sets, strings, symbols,
102
- * and typed arrays. The own enumerable properties of arguments objects are cloned as plain objects. An empty
103
- * object is returned for not cloneable values such as error objects, functions, DOM nodes, and WeakMaps.
104
- *
105
- * @param value The value to clone.
106
- * @return Returns the cloned value.
107
- */
108
- export const clone = lodash.clone;
109
- /**
110
- * This method is like clone except that it recursively clones value.
111
- *
112
- * @param value The value to recursively clone.
113
- * @return Returns the deep cloned value.
114
- */
115
- export const cloneDeep = lodash.cloneDeep;
116
- /**
117
- * Split a package name into namespace and version
118
- */
119
- export const splitModuleName = (packageName) => {
120
- // Workaround for Vte-4-2.91
121
- if (packageName.startsWith('Vte-4')) {
122
- return {
123
- packageName,
124
- namespace: 'Vte',
125
- version: packageName.replace('Vte-', ''),
126
- };
127
- }
128
- if (!packageName.includes('-')) {
129
- return {
130
- packageName,
131
- namespace: packageName,
132
- version: '',
133
- };
134
- }
135
- // There are modules that use multiple hyphens like 'GUPnP-DLNA-1.0'
136
- const splits = packageName.split('-');
137
- const version = splits.splice(-1, 1)[0];
138
- const namespace = splits.join('');
139
- return {
140
- packageName,
141
- namespace,
142
- version,
143
- };
144
- };
145
- /** Remove namespace prefix */
146
- export const removeNamespace = (type, namespace) => {
147
- if (type.startsWith(namespace + '.')) {
148
- type = type.substring(namespace.length + 1);
149
- }
150
- return type;
151
- };
152
- /** Remove class module name prefix */
153
- export const removeClassModule = removeNamespace;
154
- /**
155
- * Add namespace prefix
156
- */
157
- export const addNamespace = (type, namespace) => {
158
- if (!type.startsWith(namespace + '.')) {
159
- type = namespace + '.' + type;
160
- }
161
- return type;
162
- };
163
- /**
164
- * Removes line breaks and consecutive white spaces from a given string
165
- * @param str
166
- * @returns
167
- */
168
- export const cleanString = (str) => {
169
- str = str.replace(/\r?\n|\r/g, ' ');
170
- str = str.replace(/\s+/g, ' ');
171
- return str.trim();
172
- };
173
- /**
174
- * Checking whether some variable is iterable
175
- * @see https://stackoverflow.com/a/32538867
176
- * @param obj Variable to check for iterable
177
- * @returns Whether the variable is iterable or not
178
- */
179
- export const isIterable = (obj) => {
180
- return obj != null && typeof obj[Symbol.iterator] === 'function';
181
- };
182
- /**
183
- * Checking whether a string is numeric
184
- * @param str The string to check
185
- * @returns Whether the string is numeric or not
186
- */
187
- export const isNumeric = (str) => {
188
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
189
- return !isNaN(str - parseFloat(str));
190
- };
191
- /**
192
- * Get the first character of a string
193
- * @param str The string to get the first character from
194
- * @returns The first character
195
- */
196
- export const getFirstChar = (str) => {
197
- return str.charAt(0);
198
- };
199
- /**
200
- * Get the last character of a string
201
- * @param str The string to get the last character from
202
- * @returns The last character
203
- */
204
- export const getLastChar = (str) => {
205
- return str.charAt(str.length - 1);
206
- };
207
- /**
208
- * Check if the first character of a string is numeric
209
- * @param str The string to check
210
- * @returns Whether the first character is numeric or not
211
- */
212
- export const isFirstCharNumeric = (str) => {
213
- return isNumeric(getFirstChar(str));
214
- };
215
- /**
216
- * Convert a string to camelCase, keeps the first alphabet character as it is.
217
- * @param str The string to convert
218
- * @returns The converted string
219
- */
220
- export const camelCase = (str) => {
221
- return str
222
- .replace(/\s(.)|(\s|-|_|\.)(.)/g, (a) => {
223
- return a.toUpperCase();
224
- })
225
- .replace(/(\s|-|_|\.)/g, '');
226
- };
227
- /**
228
- * Convert a string to `lowerCamelCase`
229
- * @param str The string to convert
230
- * @returns The converted string
231
- */
232
- export const lowerCamelCase = (str) => {
233
- str = camelCase(str);
234
- str = getFirstChar(str).toLowerCase() + str.slice(1);
235
- return str;
236
- };
237
- /**
238
- * Convert a string to `PascalCase`
239
- * @param str The string to convert
240
- * @returns The converted string
241
- */
242
- export const pascalCase = (str) => {
243
- str = camelCase(str);
244
- str = getFirstChar(str).toUpperCase() + str.slice(1);
245
- return str;
246
- };
247
- /** Alias for {@link pascalCase} */
248
- export const upperCamelCase = pascalCase;
249
- /**
250
- * Convert a string to `snake_case`
251
- * @param str The string to convert
252
- * @returns The converted string
253
- */
254
- export const snakeCase = (str) => {
255
- return str
256
- .replace(/([a-z])([A-Z])/g, '$1-$2') // replace camelCase with hyphen-case
257
- .replace(/[^a-zA-Z0-9-]+/g, '_') // replace non-alphanumeric characters with underscore
258
- .replace(/^_+|_+$/g, '') // remove any leading or trailing underscores
259
- .toLowerCase();
260
- };
261
- /**
262
- * Convert a string to `kebab-case`
263
- * @param str The string to convert
264
- * @returns The converted string
265
- */
266
- export const kebabCase = (str) => {
267
- return str
268
- .replace(/([a-z])([A-Z])/g, '$1-$2') // replace camelCase with hyphen-case
269
- .replace(/[^a-zA-Z0-9-]+/g, '-') // replace non-alphanumeric characters with hyphen
270
- .replace(/^-+|-+$/g, '') // remove any leading or trailing hyphens
271
- .toLowerCase();
272
- };
273
- /** Alias for {@link kebabCase} */
274
- export const slugCase = kebabCase;
275
- export const underscores = (str) => {
276
- return str.replace(/-|_/g, '_');
277
- };
278
- /**
279
- * Find a file in a list of directories
280
- * @param dirs The directories to search in
281
- * @param filename The filename to search for
282
- * @returns The file info
283
- */
284
- export const findFilesInDirs = async (dirs, filename) => {
285
- const filesInfo = [];
286
- const pattern = dirs.map((dir) => join(dir, filename));
287
- const _files = await glob(pattern);
288
- // Remove duplicates
289
- const files = [...new Set(_files)];
290
- for (const filePath of files) {
291
- const fileInfo = {
292
- path: null,
293
- filename,
294
- exists: false,
295
- };
296
- fileInfo.exists = existsSync(filePath);
297
- if (fileInfo.exists) {
298
- fileInfo.path = filePath;
299
- filesInfo.push(fileInfo);
300
- }
301
- }
302
- if (filesInfo.length === 0) {
303
- filesInfo.push({
304
- path: null,
305
- filename,
306
- exists: false,
307
- });
308
- }
309
- return filesInfo;
310
- };
311
- /**
312
- * Find a file in a list of directories (sync)
313
- * @param dirs The directories to search in
314
- * @param filename The filename to search for
315
- * @returns The file info
316
- */
317
- export const findFilesInDirsSync = (dirs, filename) => {
318
- const filesInfo = [];
319
- const pattern = dirs.map((dir) => join(dir, filename));
320
- const _files = globSync(pattern);
321
- // Remove duplicates
322
- const files = [...new Set(_files)];
323
- for (const filePath of files) {
324
- const fileInfo = {
325
- path: null,
326
- filename,
327
- exists: false,
328
- };
329
- fileInfo.exists = existsSync(filePath);
330
- if (fileInfo.exists) {
331
- fileInfo.path = filePath;
332
- filesInfo.push(fileInfo);
333
- }
334
- }
335
- if (filesInfo.length === 0) {
336
- filesInfo.push({
337
- path: null,
338
- filename,
339
- exists: false,
340
- });
341
- }
342
- return filesInfo;
343
- };
344
- /**
345
- * Read a JSON file
346
- * @param filePath The path to the JSON file
347
- * @returns The parsed JSON
348
- */
349
- export const readJsonFile = async (filePath) => {
350
- const fileContent = await readFile(filePath, 'utf8');
351
- return JSON.parse(fileContent);
352
- };
353
- /**
354
- * Union (a ∪ b): create a set that contains the elements of both set a and set b.
355
- * See https://2ality.com/2015/01/es6-set-operations.html#union
356
- * @param target
357
- * @param source
358
- */
359
- export const union = (target, source) => {
360
- return (target = new Set([...target, ...source]));
361
- };
362
- export const stripParamNames = (func, ignoreTail = false) => {
363
- const g = func;
364
- func = func.replace(COMMENT_REG_EXP, '');
365
- const lb = func.split('(', 2);
366
- if (lb.length < 2)
367
- Logger.error(`Bad function definition ${g}`);
368
- const rb = lb[1].split(')');
369
- const tail = ignoreTail ? '' : rb[rb.length - 1];
370
- let params = rb.slice(0, rb.length - 1).join(')');
371
- params = params.replace(PARAM_REG_EXP, ':');
372
- params = params.replace(OPT_PARAM_REG_EXP, '?:');
373
- return `${lb[0]}(${params})${tail}`;
374
- };
375
- /**
376
- * Check if a line is a comment line
377
- * @param line The line to check
378
- * @returns Whether the line is a comment line or not
379
- */
380
- export const isCommentLine = (line) => {
381
- const lineTrim = line.trim();
382
- return lineTrim.startsWith('//') || (lineTrim.startsWith('/*') && lineTrim.endsWith('*/'));
383
- };
384
- /**
385
- * Add indents to a string
386
- * @param indents The number of indents
387
- * @param spaceForIndent The number of spaces for each indent
388
- * @returns The indented string
389
- */
390
- export const generateIndent = (indents = 1, spaceForIndent = 4) => {
391
- return ' '.repeat(indents * spaceForIndent);
392
- };
393
- /**
394
- * Convert a GirBoolean to a boolean
395
- * @param boolStr The GirBoolean string
396
- * @param defaultVal The default value
397
- * @returns The boolean value
398
- */
399
- export const girBool = (boolStr, defaultVal = false) => {
400
- if (boolStr) {
401
- if (parseInt(boolStr) === 0)
402
- return false;
403
- return true;
404
- }
405
- return defaultVal;
406
- };
407
- /**
408
- * Returns `true` if the definitions in `d1` and `d2` have equivalent signatures
409
- * @param d1
410
- * @param d2
411
- */
412
- export const signaturesMatch = (d1, d2) => {
413
- if (isCommentLine(d1) || isCommentLine(d2))
414
- return false;
415
- return stripParamNames(d1) == stripParamNames(d2);
416
- };
417
- //# sourceMappingURL=utils.js.map