ahegao 1.69.44 → 1.69.46
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/index.js +9 -25
- package/dist/structures/structs.js +45 -46
- package/dist/types/classes.js +122 -121
- package/dist/types/discord_classes.js +106 -140
- package/dist/types/discord_fields.js +24 -28
- package/dist/types/discord_types.js +4 -6
- package/dist/types/fields.js +232 -238
- package/dist/types/types.js +1 -3
- package/dist/utils/discord-util.js +235 -370
- package/dist/utils/util.js +694 -1146
- package/package.json +2 -1
- package/dist/data/downside.json +0 -75
- package/dist/data/hiragana.json +0 -527
- package/dist/data/homoglyphs.json +0 -31790
- package/dist/data/letterArray.json +0 -254
- package/dist/data/superscript.json +0 -96
- package/dist/data/upside.json +0 -78
- package/dist/index.d.ts +0 -9
- package/dist/index.js.map +0 -1
- package/dist/structures/structs.d.ts +0 -77
- package/dist/structures/structs.js.map +0 -1
- package/dist/types/classes.d.ts +0 -214
- package/dist/types/classes.js.map +0 -1
- package/dist/types/discord_classes.d.ts +0 -93
- package/dist/types/discord_classes.js.map +0 -1
- package/dist/types/discord_fields.d.ts +0 -27
- package/dist/types/discord_fields.js.map +0 -1
- package/dist/types/discord_types.d.ts +0 -51
- package/dist/types/discord_types.js.map +0 -1
- package/dist/types/fields.d.ts +0 -163
- package/dist/types/fields.js.map +0 -1
- package/dist/types/types.d.ts +0 -99
- package/dist/types/types.js.map +0 -1
- package/dist/utils/discord-util.d.ts +0 -198
- package/dist/utils/discord-util.js.map +0 -1
- package/dist/utils/util.d.ts +0 -504
- package/dist/utils/util.js.map +0 -1
package/dist/utils/util.js
CHANGED
|
@@ -1,467 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.MUSICAL_NOTES = exports.classifyExt = exports.isImageSequence = exports.isModel = exports.isCode = exports.isDocument = exports.isArchive = exports.isFont = exports.isSubtitle = exports.isAudio = exports.isVideo = exports.isPicture = exports.getZeroBigInt = exports.getZero = exports.ZERO_BIG_INT = exports.sherpa_onnx = exports.geniusClient = exports.chalk = exports.musicMetadata = void 0;
|
|
40
|
-
exports.toExtension = toExtension;
|
|
41
|
-
exports.removeExtension = removeExtension;
|
|
42
|
-
exports.rtl = rtl;
|
|
43
|
-
exports.random = random;
|
|
44
|
-
exports.randomBoolean = randomBoolean;
|
|
45
|
-
exports.randomFromArray = randomFromArray;
|
|
46
|
-
exports.randomFromArrayButNot = randomFromArrayButNot;
|
|
47
|
-
exports.upsideMapDown = upsideMapDown;
|
|
48
|
-
exports.forEachInfo = forEachInfo;
|
|
49
|
-
exports.forEachFilePath = forEachFilePath;
|
|
50
|
-
exports.forEachFileInfo = forEachFileInfo;
|
|
51
|
-
exports.forEachFile = forEachFile;
|
|
52
|
-
exports.forEachDirInfo = forEachDirInfo;
|
|
53
|
-
exports.forEachDir = forEachDir;
|
|
54
|
-
exports.forEachInfoRecursive = forEachInfoRecursive;
|
|
55
|
-
exports.forEachRecursive = forEachRecursive;
|
|
56
|
-
exports.forEachFileInfoRecursive = forEachFileInfoRecursive;
|
|
57
|
-
exports.getEachFileInfoRecursive = getEachFileInfoRecursive;
|
|
58
|
-
exports.getEachFileInfo = getEachFileInfo;
|
|
59
|
-
exports.forEachFileRecursive = forEachFileRecursive;
|
|
60
|
-
exports.forEachDirInfoRecursive = forEachDirInfoRecursive;
|
|
61
|
-
exports.getEachDirInfoRecursive = getEachDirInfoRecursive;
|
|
62
|
-
exports.getEachDirInfo = getEachDirInfo;
|
|
63
|
-
exports.forEachDirRecursive = forEachDirRecursive;
|
|
64
|
-
exports.purgeEmptyDirectoriesRecursive = purgeEmptyDirectoriesRecursive;
|
|
65
|
-
exports.firstUpperLowerRest = firstUpperLowerRest;
|
|
66
|
-
exports.firstUpperLowerRestEachWord = firstUpperLowerRestEachWord;
|
|
67
|
-
exports.countChars = countChars;
|
|
68
|
-
exports.countWords = countWords;
|
|
69
|
-
exports.countEmoji = countEmoji;
|
|
70
|
-
exports.incrementMap = incrementMap;
|
|
71
|
-
exports.incrementObjNumber = incrementObjNumber;
|
|
72
|
-
exports.addObjs = addObjs;
|
|
73
|
-
exports.mergeObjs = mergeObjs;
|
|
74
|
-
exports.sumValues = sumValues;
|
|
75
|
-
exports.getOrDefaultObj = getOrDefaultObj;
|
|
76
|
-
exports.getOrDefaultMap = getOrDefaultMap;
|
|
77
|
-
exports.getOrDefault = getOrDefault;
|
|
78
|
-
exports.runSoft = runSoft;
|
|
79
|
-
exports.blacklistArray = blacklistArray;
|
|
80
|
-
exports.getChars = getChars;
|
|
81
|
-
exports.getDiff = getDiff;
|
|
82
|
-
exports.formatDate = formatDate;
|
|
83
|
-
exports.decide = decide;
|
|
84
|
-
exports.decideAsync = decideAsync;
|
|
85
|
-
exports.make = make;
|
|
86
|
-
exports.makeAsync = makeAsync;
|
|
87
|
-
exports.extractElementsIntoArray = extractElementsIntoArray;
|
|
88
|
-
exports.extractItemsIntoArray = extractItemsIntoArray;
|
|
89
|
-
exports.mapArrayOfObjsByElement = mapArrayOfObjsByElement;
|
|
90
|
-
exports.mapToArray = mapToArray;
|
|
91
|
-
exports.stringify = stringify;
|
|
92
|
-
exports.acronymStringIfTooLong = acronymStringIfTooLong;
|
|
93
|
-
exports.mkdirSoftRecursive = mkdirSoftRecursive;
|
|
94
|
-
exports.mkdirSoft = mkdirSoft;
|
|
95
|
-
exports.goUpDir = goUpDir;
|
|
96
|
-
exports.writeFileIfNotPresent = writeFileIfNotPresent;
|
|
97
|
-
exports.requireSoft = requireSoft;
|
|
98
|
-
exports.clone = clone;
|
|
99
|
-
exports.getBit = getBit;
|
|
100
|
-
exports.isBit = isBit;
|
|
101
|
-
exports.map = map;
|
|
102
|
-
exports.logMap = logMap;
|
|
103
|
-
exports.clamp = clamp;
|
|
104
|
-
exports.clamp0 = clamp0;
|
|
105
|
-
exports.datesDiff = datesDiff;
|
|
106
|
-
exports.datesDiffToStamp = datesDiffToStamp;
|
|
107
|
-
exports.datesGapToStamp = datesGapToStamp;
|
|
108
|
-
exports.dateToStamp = dateToStamp;
|
|
109
|
-
exports.toStamp = toStamp;
|
|
110
|
-
exports.convertNumberBase = convertNumberBase;
|
|
111
|
-
exports.moveSync = moveSync;
|
|
112
|
-
exports.download = download;
|
|
113
|
-
exports.isCharUpperCase = isCharUpperCase;
|
|
114
|
-
exports.isCharLowerCase = isCharLowerCase;
|
|
115
|
-
exports.isStandardLetter = isStandardLetter;
|
|
116
|
-
exports.getOrCreateAppendedLinesFile = getOrCreateAppendedLinesFile;
|
|
117
|
-
exports.rmSoft = rmSoft;
|
|
118
|
-
exports.saveAppendedLinesFile = saveAppendedLinesFile;
|
|
119
|
-
exports.getOrCreateFromKeys = getOrCreateFromKeys;
|
|
120
|
-
exports.getOrCreate = getOrCreate;
|
|
121
|
-
exports.getOrCreateObj = getOrCreateObj;
|
|
122
|
-
exports.appendObjArray = appendObjArray;
|
|
123
|
-
exports.organiseByKey = organiseByKey;
|
|
124
|
-
exports.millisecondsToNanoseconds = millisecondsToNanoseconds;
|
|
125
|
-
exports.secondsToNanoseconds = secondsToNanoseconds;
|
|
126
|
-
exports.minutesToNanoseconds = minutesToNanoseconds;
|
|
127
|
-
exports.hoursToNanoseconds = hoursToNanoseconds;
|
|
128
|
-
exports.daysToNanoseconds = daysToNanoseconds;
|
|
129
|
-
exports.weeksToNanoseconds = weeksToNanoseconds;
|
|
130
|
-
exports.nanosecondsToMilliseconds = nanosecondsToMilliseconds;
|
|
131
|
-
exports.secondsToMilliseconds = secondsToMilliseconds;
|
|
132
|
-
exports.minutesToMilliseconds = minutesToMilliseconds;
|
|
133
|
-
exports.hoursToMilliseconds = hoursToMilliseconds;
|
|
134
|
-
exports.daysToMilliseconds = daysToMilliseconds;
|
|
135
|
-
exports.weeksToMilliseconds = weeksToMilliseconds;
|
|
136
|
-
exports.nanosecondsToSeconds = nanosecondsToSeconds;
|
|
137
|
-
exports.millisecondsToSeconds = millisecondsToSeconds;
|
|
138
|
-
exports.minutesToSeconds = minutesToSeconds;
|
|
139
|
-
exports.hoursToSeconds = hoursToSeconds;
|
|
140
|
-
exports.daysToSeconds = daysToSeconds;
|
|
141
|
-
exports.weeksToSeconds = weeksToSeconds;
|
|
142
|
-
exports.nanosecondsToMinutes = nanosecondsToMinutes;
|
|
143
|
-
exports.millisecondsToMinutes = millisecondsToMinutes;
|
|
144
|
-
exports.secondsToMinutes = secondsToMinutes;
|
|
145
|
-
exports.hoursToMinutes = hoursToMinutes;
|
|
146
|
-
exports.daysToMinutes = daysToMinutes;
|
|
147
|
-
exports.weeksToMinutes = weeksToMinutes;
|
|
148
|
-
exports.nanosecondsToHours = nanosecondsToHours;
|
|
149
|
-
exports.millisecondsToHours = millisecondsToHours;
|
|
150
|
-
exports.secondsToHours = secondsToHours;
|
|
151
|
-
exports.minutesToHours = minutesToHours;
|
|
152
|
-
exports.daysToHours = daysToHours;
|
|
153
|
-
exports.weeksToHours = weeksToHours;
|
|
154
|
-
exports.nanosecondsToDays = nanosecondsToDays;
|
|
155
|
-
exports.millisecondsToDays = millisecondsToDays;
|
|
156
|
-
exports.secondsToDays = secondsToDays;
|
|
157
|
-
exports.minutesToDays = minutesToDays;
|
|
158
|
-
exports.hoursToDays = hoursToDays;
|
|
159
|
-
exports.weeksToDays = weeksToDays;
|
|
160
|
-
exports.nanosecondsToWeeks = nanosecondsToWeeks;
|
|
161
|
-
exports.millisecondsToWeeks = millisecondsToWeeks;
|
|
162
|
-
exports.secondsToWeeks = secondsToWeeks;
|
|
163
|
-
exports.minutesToWeeks = minutesToWeeks;
|
|
164
|
-
exports.hoursToWeeks = hoursToWeeks;
|
|
165
|
-
exports.daysToWeeks = daysToWeeks;
|
|
166
|
-
exports.minutesToHoursMinutes = minutesToHoursMinutes;
|
|
167
|
-
exports.parsedFileInfoNameToIntSort = parsedFileInfoNameToIntSort;
|
|
168
|
-
exports.parsedStringToIntSort = parsedStringToIntSort;
|
|
169
|
-
exports.degreesToRadians = degreesToRadians;
|
|
170
|
-
exports.toRads = toRads;
|
|
171
|
-
exports.radiansToDegrees = radiansToDegrees;
|
|
172
|
-
exports.toDegs = toDegs;
|
|
173
|
-
exports.getDayMonthYearDateString = getDayMonthYearDateString;
|
|
174
|
-
exports.touchSoft = touchSoft;
|
|
175
|
-
exports.increment = increment;
|
|
176
|
-
exports.readFileInt = readFileInt;
|
|
177
|
-
exports.hashCode = hashCode;
|
|
178
|
-
exports.chalkColor = chalkColor;
|
|
179
|
-
exports.chalkRainbowColor = chalkRainbowColor;
|
|
180
|
-
exports.chalkNextRainbowColor = chalkNextRainbowColor;
|
|
181
|
-
exports.seededChalkRainbowColor = seededChalkRainbowColor;
|
|
182
|
-
exports.randomChalkRainbowColor = randomChalkRainbowColor;
|
|
183
|
-
exports.padLeft = padLeft;
|
|
184
|
-
exports.padRight = padRight;
|
|
185
|
-
exports.getCuteAscii = getCuteAscii;
|
|
186
|
-
exports.isEmpty = isEmpty;
|
|
187
|
-
exports.singleSpacesOnly = singleSpacesOnly;
|
|
188
|
-
exports.getWeekDayString = getWeekDayString;
|
|
189
|
-
exports.getFirstRegexGroupMatchElse = getFirstRegexGroupMatchElse;
|
|
190
|
-
exports.getFirstRegexGroupMatchAsIntElse = getFirstRegexGroupMatchAsIntElse;
|
|
191
|
-
exports.getFirstRegexGroupMatchAsFloatElse = getFirstRegexGroupMatchAsFloatElse;
|
|
192
|
-
exports.getFirstRegexGroupMatchElseUndefined = getFirstRegexGroupMatchElseUndefined;
|
|
193
|
-
exports.getFirstRegexGroupMatchAsIntElseUndefined = getFirstRegexGroupMatchAsIntElseUndefined;
|
|
194
|
-
exports.getFirstRegexGroupMatchAsFloatElseUndefined = getFirstRegexGroupMatchAsFloatElseUndefined;
|
|
195
|
-
exports.allRegexesMatched = allRegexesMatched;
|
|
196
|
-
exports.countOccurrences = countOccurrences;
|
|
197
|
-
exports.occursAtleastTimes = occursAtleastTimes;
|
|
198
|
-
exports.removeColorCodes = removeColorCodes;
|
|
199
|
-
exports.replaceAllRegexAsGlobalArray = replaceAllRegexAsGlobalArray;
|
|
200
|
-
exports.replaceAllRegexAsGlobal = replaceAllRegexAsGlobal;
|
|
201
|
-
exports.setToJSON = setToJSON;
|
|
202
|
-
exports.mapToJSON = mapToJSON;
|
|
203
|
-
exports.toJSON = toJSON;
|
|
204
|
-
exports.jsonToSet = jsonToSet;
|
|
205
|
-
exports.jsonToMap = jsonToMap;
|
|
206
|
-
exports.fromJSON = fromJSON;
|
|
207
|
-
exports.htmlAsCheerio = htmlAsCheerio;
|
|
208
|
-
exports.getPageCheerio = getPageCheerio;
|
|
209
|
-
exports.getPageHtml = getPageHtml;
|
|
210
|
-
exports.humanReadableJsonToHumanReadableNextLineBracketsJson = humanReadableJsonToHumanReadableNextLineBracketsJson;
|
|
211
|
-
exports.toJson = toJson;
|
|
212
|
-
exports.charToRegexOrHomoglyphs = charToRegexOrHomoglyphs;
|
|
213
|
-
exports.stringToRegexOrHomoglyphs = stringToRegexOrHomoglyphs;
|
|
214
|
-
exports.toInsanelyAccurateRegex = toInsanelyAccurateRegex;
|
|
215
|
-
exports.noop = noop;
|
|
216
|
-
exports.noop1 = noop1;
|
|
217
|
-
exports.noop2 = noop2;
|
|
218
|
-
exports.noop3 = noop3;
|
|
219
|
-
exports.forEachKeyValue = forEachKeyValue;
|
|
220
|
-
exports.keyValueToOdt = keyValueToOdt;
|
|
221
|
-
exports.orElse = orElse;
|
|
222
|
-
exports.getClosestValue = getClosestValue;
|
|
223
|
-
exports.getClosestNumber = getClosestNumber;
|
|
224
|
-
exports.convertTime = convertTime;
|
|
225
|
-
exports.getNs = getNs;
|
|
226
|
-
exports.startTimer = startTimer;
|
|
227
|
-
exports.getTimer = getTimer;
|
|
228
|
-
exports.getTimerString = getTimerString;
|
|
229
|
-
exports.printTimer = printTimer;
|
|
230
|
-
exports.isString = isString;
|
|
231
|
-
exports.reverseString = reverseString;
|
|
232
|
-
exports.wipeAllLetters = wipeAllLetters;
|
|
233
|
-
exports.keepOnlyAllLetters = keepOnlyAllLetters;
|
|
234
|
-
exports.wipeNumbers = wipeNumbers;
|
|
235
|
-
exports.keepOnlyNumbers = keepOnlyNumbers;
|
|
236
|
-
exports.wipeAllLettersAndNumbers = wipeAllLettersAndNumbers;
|
|
237
|
-
exports.keepOnlyAllLettersAndNumbers = keepOnlyAllLettersAndNumbers;
|
|
238
|
-
exports.fromArrayOrNull = fromArrayOrNull;
|
|
239
|
-
exports.setClipboard = setClipboard;
|
|
240
|
-
exports.readClipboard = readClipboard;
|
|
241
|
-
exports.toDDMMYYYY = toDDMMYYYY;
|
|
242
|
-
exports.toMMDDYYYY = toMMDDYYYY;
|
|
243
|
-
exports.downloadItem = downloadItem;
|
|
244
|
-
exports.getChild = getChild;
|
|
245
|
-
exports.getDynamicContentCheerio = getDynamicContentCheerio;
|
|
246
|
-
exports.getDynamicContent = getDynamicContent;
|
|
247
|
-
exports.randomTimeout = randomTimeout;
|
|
248
|
-
exports.randomTimeoutVerbose = randomTimeoutVerbose;
|
|
249
|
-
exports.getLast = getLast;
|
|
250
|
-
exports.getLastX = getLastX;
|
|
251
|
-
exports.forLastX = forLastX;
|
|
252
|
-
exports.joinToXCounts = joinToXCounts;
|
|
253
|
-
exports.asyncMap = asyncMap;
|
|
254
|
-
exports.emptyIfEmpty = emptyIfEmpty;
|
|
255
|
-
exports.getRandomWeighedItem = getRandomWeighedItem;
|
|
256
|
-
exports.getWeightOfKeys = getWeightOfKeys;
|
|
257
|
-
exports.getWeightOfValues = getWeightOfValues;
|
|
258
|
-
exports.getSum = getSum;
|
|
259
|
-
exports.getCurrentMs = getCurrentMs;
|
|
260
|
-
exports.getCurrentSecond = getCurrentSecond;
|
|
261
|
-
exports.getCurrentMinute = getCurrentMinute;
|
|
262
|
-
exports.getCurrentHour = getCurrentHour;
|
|
263
|
-
exports.getCurrentDay = getCurrentDay;
|
|
264
|
-
exports.reverseMap = reverseMap;
|
|
265
|
-
exports.toArray = toArray;
|
|
266
|
-
exports.sortDateOldestFirst = sortDateOldestFirst;
|
|
267
|
-
exports.sortDateNewestFirst = sortDateNewestFirst;
|
|
268
|
-
exports.dateValuesMapToSortedKeysArray = dateValuesMapToSortedKeysArray;
|
|
269
|
-
exports.getCount = getCount;
|
|
270
|
-
exports.sumStringNumberObj = sumStringNumberObj;
|
|
271
|
-
exports.splitWords = splitWords;
|
|
272
|
-
exports.filterMap = filterMap;
|
|
273
|
-
exports.filterMapCopy = filterMapCopy;
|
|
274
|
-
exports.filterSet = filterSet;
|
|
275
|
-
exports.filterSetCopy = filterSetCopy;
|
|
276
|
-
exports.prismaDeleteIfExists = prismaDeleteIfExists;
|
|
277
|
-
exports.getWeekSince1980 = getWeekSince1980;
|
|
278
|
-
exports.getDaySince1980 = getDaySince1980;
|
|
279
|
-
exports.runCommand = runCommand;
|
|
280
|
-
exports.runCommandRejectAsResolve = runCommandRejectAsResolve;
|
|
281
|
-
exports.sanitizeStringForFFMPEG = sanitizeStringForFFMPEG;
|
|
282
|
-
exports.getArtistsFromFlacMetadata = getArtistsFromFlacMetadata;
|
|
283
|
-
exports.getTitleFromFlacMetadata = getTitleFromFlacMetadata;
|
|
284
|
-
exports.getAlbumFromFlacMetadata = getAlbumFromFlacMetadata;
|
|
285
|
-
exports.getAlbumArtistFromFlacMetadata = getAlbumArtistFromFlacMetadata;
|
|
286
|
-
exports.getLyricsFromFlacVorbisTags = getLyricsFromFlacVorbisTags;
|
|
287
|
-
exports.generateHash = generateHash;
|
|
288
|
-
exports.extensionHasAudio = extensionHasAudio;
|
|
289
|
-
exports.songTitleExtractSide = songTitleExtractSide;
|
|
290
|
-
exports.sanitizeStringForSeed = sanitizeStringForSeed;
|
|
291
|
-
exports.addAllSetToSet = addAllSetToSet;
|
|
292
|
-
exports.addAllArrayToSet = addAllArrayToSet;
|
|
293
|
-
exports.addAllSetToArray = addAllSetToArray;
|
|
294
|
-
exports.addAllArrayToArray = addAllArrayToArray;
|
|
295
|
-
exports.addAllArrayToMap = addAllArrayToMap;
|
|
296
|
-
exports.addSetArrayToMap = addSetArrayToMap;
|
|
297
|
-
exports.replaceAllArray = replaceAllArray;
|
|
298
|
-
exports.librarySplitMultipleArtists = librarySplitMultipleArtists;
|
|
299
|
-
exports.libraryFindFeaturing = libraryFindFeaturing;
|
|
300
|
-
exports.libraryCleanUpStartAndEndOfString = libraryCleanUpStartAndEndOfString;
|
|
301
|
-
exports.generateWeightedItemsGridString = generateWeightedItemsGridString;
|
|
302
|
-
exports.promptYesOrNo = promptYesOrNo;
|
|
303
|
-
exports.musicFileInfoToM3uEntry = musicFileInfoToM3uEntry;
|
|
304
|
-
exports.toM3uEntry = toM3uEntry;
|
|
305
|
-
exports.getStepString = getStepString;
|
|
306
|
-
exports.sliceOffLastSlash = sliceOffLastSlash;
|
|
307
|
-
exports.sliceOffLast = sliceOffLast;
|
|
308
|
-
exports.sliceOffUntil = sliceOffUntil;
|
|
309
|
-
exports.countOccurances = countOccurances;
|
|
310
|
-
exports.countPathDepth = countPathDepth;
|
|
311
|
-
exports.getPathEscapeString = getPathEscapeString;
|
|
312
|
-
exports.getFullPathEscapeString = getFullPathEscapeString;
|
|
313
|
-
exports.jsonLookupToMap = jsonLookupToMap;
|
|
314
|
-
exports.extractElementFromJsonAndRemove = extractElementFromJsonAndRemove;
|
|
315
|
-
exports.extractLookupFromJsonAndRemove = extractLookupFromJsonAndRemove;
|
|
316
|
-
exports.forEachValueAndPathOfObj = forEachValueAndPathOfObj;
|
|
317
|
-
exports.forEachLookUpValueAndPathOfObjRecursive = forEachLookUpValueAndPathOfObjRecursive;
|
|
318
|
-
exports.findGeniusSongs = findGeniusSongs;
|
|
319
|
-
exports.trimToCharNumbersOnly = trimToCharNumbersOnly;
|
|
320
|
-
exports.trimStartToCharNumbersOnly = trimStartToCharNumbersOnly;
|
|
321
|
-
exports.trimEndToCharNumbersOnly = trimEndToCharNumbersOnly;
|
|
322
|
-
exports.trim = trim;
|
|
323
|
-
exports.trimStart = trimStart;
|
|
324
|
-
exports.trimEnd = trimEnd;
|
|
325
|
-
exports.findGeniusLyrics = findGeniusLyrics;
|
|
326
|
-
exports.softSliceFrom = softSliceFrom;
|
|
327
|
-
exports.trimFirstLinesWhileIncludes = trimFirstLinesWhileIncludes;
|
|
328
|
-
exports.getFirstLine = getFirstLine;
|
|
329
|
-
exports.skyify = skyify;
|
|
330
|
-
exports.dateToFilename = dateToFilename;
|
|
331
|
-
exports.makeMap = makeMap;
|
|
332
|
-
exports.makeWeightedMap = makeWeightedMap;
|
|
333
|
-
exports.makeWeightedTextCompMap = makeWeightedTextCompMap;
|
|
334
|
-
exports.generateLinesUntilCharacterLimit = generateLinesUntilCharacterLimit;
|
|
335
|
-
exports.lastIndexOfSeparator = lastIndexOfSeparator;
|
|
336
|
-
exports.timestamp = timestamp;
|
|
337
|
-
exports.timestampWithMs = timestampWithMs;
|
|
338
|
-
exports.isSilent = isSilent;
|
|
339
|
-
exports.waitMs = waitMs;
|
|
340
|
-
exports.waitS = waitS;
|
|
341
|
-
exports.whileFalseAsyncS = whileFalseAsyncS;
|
|
342
|
-
exports.whileFalseAsyncMs = whileFalseAsyncMs;
|
|
343
|
-
exports.repeatForAsyncS = repeatForAsyncS;
|
|
344
|
-
exports.repeatForAsyncMs = repeatForAsyncMs;
|
|
345
|
-
exports.replaceLastTerminalLine = replaceLastTerminalLine;
|
|
346
|
-
exports.setTerminalOutput = setTerminalOutput;
|
|
347
|
-
exports.clearSetTerminalOutput = clearSetTerminalOutput;
|
|
348
|
-
exports.clearTerminalLines = clearTerminalLines;
|
|
349
|
-
exports.sIfNot1 = sIfNot1;
|
|
350
|
-
exports.if1Else = if1Else;
|
|
351
|
-
exports.makePath = makePath;
|
|
352
|
-
exports.makeUnixPath = makeUnixPath;
|
|
353
|
-
exports.makeWindowsPath = makeWindowsPath;
|
|
354
|
-
exports.overflow = overflow;
|
|
355
|
-
exports.overflow0 = overflow0;
|
|
356
|
-
exports.isWithin = isWithin;
|
|
357
|
-
exports.startShiftItemsMenu = startShiftItemsMenu;
|
|
358
|
-
exports.getRelativeOverflow = getRelativeOverflow;
|
|
359
|
-
exports.shiftMenuItemsFunction = shiftMenuItemsFunction;
|
|
360
|
-
exports.startNumbersEditMenu = startNumbersEditMenu;
|
|
361
|
-
exports.startMenu = startMenu;
|
|
362
|
-
exports.navigationKeysToNumber = navigationKeysToNumber;
|
|
363
|
-
exports.editNumberByInput = editNumberByInput;
|
|
364
|
-
exports.toMenuString = toMenuString;
|
|
365
|
-
exports.toPrintString = toPrintString;
|
|
366
|
-
exports.getStackTrace = getStackTrace;
|
|
367
|
-
exports.getStackTraceLine = getStackTraceLine;
|
|
368
|
-
exports.getCallerErrorLine = getCallerErrorLine;
|
|
369
|
-
exports.isCallerTs = isCallerTs;
|
|
370
|
-
exports.printError = printError;
|
|
371
|
-
exports.printWarn = printWarn;
|
|
372
|
-
exports.print = print;
|
|
373
|
-
exports.softToFixed = softToFixed;
|
|
374
|
-
exports.extractEpisodeNumber = extractEpisodeNumber;
|
|
375
|
-
exports.trashSoft = trashSoft;
|
|
376
|
-
exports.isOfType = isOfType;
|
|
377
|
-
exports.subtitlesStreamInfoToString = subtitlesStreamInfoToString;
|
|
378
|
-
exports.extractsubtitlesStreamsInfo = extractsubtitlesStreamsInfo;
|
|
379
|
-
exports.tryExtractSubtitles = tryExtractSubtitles;
|
|
380
|
-
exports.addSubtitles = addSubtitles;
|
|
381
|
-
exports.noteFromMIDI = noteFromMIDI;
|
|
382
|
-
exports.octaveFromMIDI = octaveFromMIDI;
|
|
383
|
-
exports.fullNoteFromMIDI = fullNoteFromMIDI;
|
|
384
|
-
exports.clearTerminal = clearTerminal;
|
|
385
|
-
exports.connectMidiByName = connectMidiByName;
|
|
386
|
-
exports.joinSet = joinSet;
|
|
387
|
-
exports.verboseModText = verboseModText;
|
|
388
|
-
exports.printDifferenceIfDifferent = printDifferenceIfDifferent;
|
|
389
|
-
exports.highlightDifference = highlightDifference;
|
|
390
|
-
exports.toRegexpAsExactString = toRegexpAsExactString;
|
|
391
|
-
exports.greenUnderlineBold = greenUnderlineBold;
|
|
392
|
-
exports.greenUnderline = greenUnderline;
|
|
393
|
-
exports.redUnderlineBold = redUnderlineBold;
|
|
394
|
-
exports.redUnderline = redUnderline;
|
|
395
|
-
exports.yellowUnderline = yellowUnderline;
|
|
396
|
-
exports.underlineBold = underlineBold;
|
|
397
|
-
exports.modAllMatchAndNotMatch = modAllMatchAndNotMatch;
|
|
398
|
-
exports.modMatchAndNotMatch = modMatchAndNotMatch;
|
|
399
|
-
exports.createRunnableScriptFiles = createRunnableScriptFiles;
|
|
400
|
-
exports.createProject = createProject;
|
|
401
|
-
exports.spawnLiveCmd = spawnLiveCmd;
|
|
402
|
-
exports.spawnLivePowershell = spawnLivePowershell;
|
|
403
|
-
exports.spawnLiveSilent = spawnLiveSilent;
|
|
404
|
-
exports.spawnLive = spawnLive;
|
|
405
|
-
exports.isWindows = isWindows;
|
|
406
|
-
exports.isMacOS = isMacOS;
|
|
407
|
-
exports.isLinux = isLinux;
|
|
408
|
-
exports.isUnixLike = isUnixLike;
|
|
409
|
-
exports.makeRunnable = makeRunnable;
|
|
410
|
-
exports.acceptUserInput = acceptUserInput;
|
|
411
|
-
exports.writeFileSyncCheck = writeFileSyncCheck;
|
|
412
|
-
exports.isLibTs = isLibTs;
|
|
413
|
-
exports.removeDuplicateLines = removeDuplicateLines;
|
|
414
|
-
exports.openCDTray = openCDTray;
|
|
415
|
-
exports.closeCDTray = closeCDTray;
|
|
416
|
-
exports.toggleCDTray = toggleCDTray;
|
|
417
|
-
exports.recordAudioUntilX = recordAudioUntilX;
|
|
418
|
-
exports.createSherpaCanaryOfflineSpeechRecognizer = createSherpaCanaryOfflineSpeechRecognizer;
|
|
419
|
-
exports.createSherpaOfflineSpeechRecognizer = createSherpaOfflineSpeechRecognizer;
|
|
420
|
-
exports.isTerminalAvailable = isTerminalAvailable;
|
|
421
|
-
exports.interpretWave = interpretWave;
|
|
422
|
-
exports.getAudioFileDuration = getAudioFileDuration;
|
|
423
|
-
exports.getDebugPaths = getDebugPaths;
|
|
424
|
-
exports.setDebugPaths = setDebugPaths;
|
|
425
|
-
exports.dogPaths = dogPaths;
|
|
426
|
-
exports.getTempPath = getTempPath;
|
|
427
|
-
exports.patchMicLib = patchMicLib;
|
|
428
|
-
exports.softSyncGitRepo = softSyncGitRepo;
|
|
429
|
-
const cheerio = __importStar(require("cheerio"));
|
|
430
|
-
const fs_1 = require("fs");
|
|
431
|
-
const https_1 = require("https");
|
|
432
|
-
const puppeteer_1 = __importDefault(require("puppeteer"));
|
|
433
|
-
const structs_1 = require("../structures/structs");
|
|
434
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
435
|
-
const child_process_1 = require("child_process");
|
|
436
|
-
const crypto_1 = require("crypto");
|
|
437
|
-
const fs_2 = require("fs");
|
|
438
|
-
const path_1 = __importStar(require("path"));
|
|
439
|
-
const classes_1 = require("../types/classes");
|
|
440
|
-
const fields_1 = require("../types/fields");
|
|
441
|
-
const util_1 = require("./util");
|
|
442
|
-
const os_1 = require("os");
|
|
443
|
-
const mic_1 = __importDefault(require("mic"));
|
|
444
|
-
var music_metadata_1 = require("music-metadata");
|
|
445
|
-
Object.defineProperty(exports, "musicMetadata", { enumerable: true, get: function () { return __importDefault(music_metadata_1).default; } });
|
|
1
|
+
import * as cheerio from "cheerio";
|
|
2
|
+
import { chmodSync, copyFileSync, createWriteStream, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmdirSync, rmSync, statSync, unlinkSync, writeFileSync } from "fs";
|
|
3
|
+
import { get } from "https";
|
|
4
|
+
import puppeteer from "puppeteer";
|
|
5
|
+
import { FileInfo, RangedNumber } from "../structures/structs";
|
|
6
|
+
import chalkImport from 'chalk';
|
|
7
|
+
import { exec, execSync, spawn } from "child_process";
|
|
8
|
+
import { createHash } from "crypto";
|
|
9
|
+
import { appendFileSync } from "fs";
|
|
10
|
+
import path, { basename } from "path";
|
|
11
|
+
import { MUSIC_ARTIST_ALIASES, Timer, TitleAndArtists, WeightedMap } from "../types/classes";
|
|
12
|
+
import { ACRONYM_REGEX, ACRONYM_REGEXES, AFTER_SIDES_SANITIZE_REGEXES, AUDIO_CONTAINING_EXTENSION_TYPES, BEFORE_SIDES_SANITIZE_REGEXES, CHALK_RAINBOW_COLORS, COLOR_CODE_REGEX, CONTRIBUTORS_REGEX, CUSTOM_EMOJI_REGEX, CUTE_ASCII, DAYS_IN_WEEK, DEFAULT_HTTPS_CONNECTION_OPTIONS, DEGREES_TO_RADIANS, DISCORD_MESSAGE_LENGTH_LIMIT, DOWNSIDE_MAP, EMOJI_REGEX, EMPTY, EMPTY_ARRAY, EXEC_NO_WINDOWS, FEAT_WITH_PARENTHESIS_REGEX, HOMOGLYPHS_AS_REGEXP_OR, HOURS_IN_DAY, HOURS_IN_WEEK, JSON_NEXT_LINE_BRACKET_FROM_REGEX, JSON_NEXT_LINE_BRACKET_TO, MILLISECONDS_IN_DAY, MILLISECONDS_IN_HOUR, MILLISECONDS_IN_MINUTE, MILLISECONDS_IN_SECOND, MILLISECONDS_IN_WEEK, MINUTES_IN_DAY, MINUTES_IN_HOUR, MINUTES_IN_WEEK, NANOSECONDS_IN_DAY, NANOSECONDS_IN_HOUR, NANOSECONDS_IN_MILLISECOND, NANOSECONDS_IN_MINUTE, NANOSECONDS_IN_SECOND, NANOSECONDS_IN_WEEK, NEW_LINE_REGEX, NIGHT_SKY_ITEMS, NIGHT_SKY_ITEMS_TOTAL_WEIGHT, NON_NUMBER_OR_CHAR_REGEX, NON_NUMBER_REGEX, NOT_UNICODE_LETTERS_REGEX, NUMBER_REGEX, PRESS_ENTER_TO_EXIT_SH, RADIANS_TO_DEGREES, SECONDS_IN_DAY, SECONDS_IN_HOUR, SECONDS_IN_MINUTE, SECONDS_IN_WEEK, SEP, SEPARATOR_REGEX, START_OF_PATH_REGEX, SUBTITLE_METADATA_REGEX, TRIM_REGEX, TSCONFIG_JSON, UNICODE_LETTERS_REGEX, UNSYNCEDLYRICS_FLAC_ID, UPSIDE_MAP, VERBOSE_DATE_TIME_FORMAT_OPTIONS, VSCODE_TS_LAUNCH_JSON, WORDS_REGEX } from "../types/fields";
|
|
13
|
+
import { musicMetadata } from "./util";
|
|
14
|
+
import { platform } from "os";
|
|
15
|
+
import mic from "mic";
|
|
16
|
+
export { default as musicMetadata } from 'music-metadata';
|
|
446
17
|
const ncp = require('node-clipboardy');
|
|
447
|
-
|
|
18
|
+
export const chalk = chalkImport;
|
|
448
19
|
const Genius = require("genius-lyrics");
|
|
449
|
-
|
|
20
|
+
export const geniusClient = new Genius.Client(undefined);
|
|
450
21
|
const readline = require('readline');
|
|
451
|
-
|
|
22
|
+
export const sherpa_onnx = require('sherpa-onnx');
|
|
452
23
|
//region Functions
|
|
453
|
-
function toExtension(input) {
|
|
24
|
+
export function toExtension(input) {
|
|
454
25
|
const indexOfPeriod = input.lastIndexOf(".");
|
|
455
26
|
return indexOfPeriod == -1 ? "" : input.substring(indexOfPeriod + 1);
|
|
456
27
|
}
|
|
457
|
-
function removeExtension(input) {
|
|
28
|
+
export function removeExtension(input) {
|
|
458
29
|
if (input[0] == ".") {
|
|
459
30
|
return input;
|
|
460
31
|
}
|
|
461
32
|
const indexOfPeriod = input.lastIndexOf(".");
|
|
462
33
|
return indexOfPeriod == -1 ? input : input.substring(0, indexOfPeriod);
|
|
463
34
|
}
|
|
464
|
-
function rtl(text, amount, emptyChar = '') {
|
|
35
|
+
export function rtl(text, amount, emptyChar = '') {
|
|
465
36
|
text = text.toString();
|
|
466
37
|
let temp = "";
|
|
467
38
|
for (let i = text.length; i < amount; ++i) {
|
|
@@ -469,7 +40,7 @@ function rtl(text, amount, emptyChar = '') {
|
|
|
469
40
|
}
|
|
470
41
|
return temp + text;
|
|
471
42
|
}
|
|
472
|
-
function random(min, max) {
|
|
43
|
+
export function random(min, max) {
|
|
473
44
|
if (min > max) {
|
|
474
45
|
const temp = min;
|
|
475
46
|
min = max;
|
|
@@ -477,13 +48,13 @@ function random(min, max) {
|
|
|
477
48
|
}
|
|
478
49
|
return (Math.floor(Math.random() * (Math.floor(max) - Math.floor(min) + 1) + Math.floor(min)));
|
|
479
50
|
}
|
|
480
|
-
function randomBoolean(chance = 0.5) {
|
|
51
|
+
export function randomBoolean(chance = 0.5) {
|
|
481
52
|
return Math.random() < chance;
|
|
482
53
|
}
|
|
483
|
-
function randomFromArray(array) {
|
|
54
|
+
export function randomFromArray(array) {
|
|
484
55
|
return array[random(0, array.length - 1)];
|
|
485
56
|
}
|
|
486
|
-
function randomFromArrayButNot(array, not) {
|
|
57
|
+
export function randomFromArrayButNot(array, not) {
|
|
487
58
|
while (true) {
|
|
488
59
|
const item = array[random(0, array.length - 1)];
|
|
489
60
|
if (item != not) {
|
|
@@ -492,25 +63,25 @@ function randomFromArrayButNot(array, not) {
|
|
|
492
63
|
}
|
|
493
64
|
}
|
|
494
65
|
const troublesomeupsideMapdown = ["[", "]", "{", "}", "<", ">", "\\", "/", "3", "Ɛ"];
|
|
495
|
-
function upsideMapDown(text, reverse) {
|
|
66
|
+
export function upsideMapDown(text, reverse) {
|
|
496
67
|
if (!text) {
|
|
497
68
|
return "You forgot the text!";
|
|
498
69
|
}
|
|
499
70
|
let returnText = "";
|
|
500
71
|
for (var i = 0; i < text.length; ++i) {
|
|
501
72
|
if (reverse) {
|
|
502
|
-
if (
|
|
503
|
-
returnText +=
|
|
504
|
-
else if (
|
|
505
|
-
returnText +=
|
|
73
|
+
if (UPSIDE_MAP[text[text.length - i - 1]])
|
|
74
|
+
returnText += UPSIDE_MAP[text[text.length - i - 1]];
|
|
75
|
+
else if (DOWNSIDE_MAP[text[text.length - i - 1]])
|
|
76
|
+
returnText += DOWNSIDE_MAP[text[text.length - i - 1]];
|
|
506
77
|
else
|
|
507
78
|
returnText += text[text.length - i - 1];
|
|
508
79
|
}
|
|
509
80
|
else {
|
|
510
|
-
if (
|
|
511
|
-
returnText +=
|
|
512
|
-
else if (
|
|
513
|
-
returnText +=
|
|
81
|
+
if (UPSIDE_MAP[text[i]] && !troublesomeupsideMapdown.includes(text[i]))
|
|
82
|
+
returnText += UPSIDE_MAP[text[i]];
|
|
83
|
+
else if (DOWNSIDE_MAP[text[i]] && !troublesomeupsideMapdown.includes(text[i]))
|
|
84
|
+
returnText += DOWNSIDE_MAP[text[i]];
|
|
514
85
|
else
|
|
515
86
|
returnText += text[i];
|
|
516
87
|
}
|
|
@@ -518,17 +89,17 @@ function upsideMapDown(text, reverse) {
|
|
|
518
89
|
return returnText;
|
|
519
90
|
}
|
|
520
91
|
//START for each file/directory
|
|
521
|
-
function forEachInfo(basePath, func) {
|
|
522
|
-
forEachFilePath(basePath, filePath => func(new
|
|
92
|
+
export function forEachInfo(basePath, func) {
|
|
93
|
+
forEachFilePath(basePath, filePath => func(new FileInfo(filePath)));
|
|
523
94
|
}
|
|
524
|
-
function forEachFilePath(basePath, func) {
|
|
95
|
+
export function forEachFilePath(basePath, func) {
|
|
525
96
|
//Can only iterate through a directory
|
|
526
|
-
if (!
|
|
97
|
+
if (!statSync(basePath).isDirectory()) {
|
|
527
98
|
return;
|
|
528
99
|
}
|
|
529
|
-
for (const file of
|
|
530
|
-
const filePath = `${basePath}${
|
|
531
|
-
if (!
|
|
100
|
+
for (const file of readdirSync(basePath)) {
|
|
101
|
+
const filePath = `${basePath}${SEP}${file}`;
|
|
102
|
+
if (!existsSync(filePath)) //Nani the fuck?
|
|
532
103
|
{
|
|
533
104
|
continue;
|
|
534
105
|
}
|
|
@@ -537,34 +108,34 @@ function forEachFilePath(basePath, func) {
|
|
|
537
108
|
}
|
|
538
109
|
//END for each file/directory
|
|
539
110
|
//START for each file
|
|
540
|
-
function forEachFileInfo(basePath, func) {
|
|
541
|
-
forEachFile(basePath, filePath => func(new
|
|
111
|
+
export function forEachFileInfo(basePath, func) {
|
|
112
|
+
forEachFile(basePath, filePath => func(new FileInfo(filePath)));
|
|
542
113
|
}
|
|
543
|
-
function forEachFile(basePath, func) {
|
|
114
|
+
export function forEachFile(basePath, func) {
|
|
544
115
|
forEachFilePath(basePath, filePath => {
|
|
545
|
-
if (
|
|
116
|
+
if (statSync(filePath).isDirectory())
|
|
546
117
|
return;
|
|
547
118
|
func(filePath);
|
|
548
119
|
});
|
|
549
120
|
}
|
|
550
121
|
//END for each file
|
|
551
122
|
//START for each directory
|
|
552
|
-
function forEachDirInfo(basePath, func) {
|
|
553
|
-
forEachDir(basePath, filePath => func(new
|
|
123
|
+
export function forEachDirInfo(basePath, func) {
|
|
124
|
+
forEachDir(basePath, filePath => func(new FileInfo(filePath)));
|
|
554
125
|
}
|
|
555
|
-
function forEachDir(basePath, func) {
|
|
126
|
+
export function forEachDir(basePath, func) {
|
|
556
127
|
forEachFilePath(basePath, filePath => {
|
|
557
|
-
if (!
|
|
128
|
+
if (!statSync(filePath).isDirectory())
|
|
558
129
|
return;
|
|
559
130
|
func(filePath);
|
|
560
131
|
});
|
|
561
132
|
}
|
|
562
133
|
//END for each directory
|
|
563
134
|
//START for each file/directory recursive
|
|
564
|
-
function forEachInfoRecursive(basePath, func) {
|
|
565
|
-
forEachRecursive(basePath, filePath => func(new
|
|
135
|
+
export function forEachInfoRecursive(basePath, func) {
|
|
136
|
+
forEachRecursive(basePath, filePath => func(new FileInfo(filePath)));
|
|
566
137
|
}
|
|
567
|
-
function forEachRecursive(basePath, func) {
|
|
138
|
+
export function forEachRecursive(basePath, func) {
|
|
568
139
|
forEachFilePath(basePath, filePath => {
|
|
569
140
|
const result = func(filePath);
|
|
570
141
|
if (result != null && !result)
|
|
@@ -574,31 +145,31 @@ function forEachRecursive(basePath, func) {
|
|
|
574
145
|
}
|
|
575
146
|
//END for each file/directory recursive
|
|
576
147
|
//START for each file recursive
|
|
577
|
-
function forEachFileInfoRecursive(basePath, func) {
|
|
578
|
-
forEachFileRecursive(basePath, filePath => func(new
|
|
148
|
+
export function forEachFileInfoRecursive(basePath, func) {
|
|
149
|
+
forEachFileRecursive(basePath, filePath => func(new FileInfo(filePath)));
|
|
579
150
|
}
|
|
580
|
-
function getEachFileInfoRecursive(basePath) {
|
|
151
|
+
export function getEachFileInfoRecursive(basePath) {
|
|
581
152
|
const fileInfos = [];
|
|
582
153
|
forEachFileInfoRecursive(basePath, fileInfo => fileInfos.push(fileInfo));
|
|
583
154
|
return fileInfos;
|
|
584
155
|
}
|
|
585
|
-
function getEachFileInfo(basePath) {
|
|
156
|
+
export function getEachFileInfo(basePath) {
|
|
586
157
|
const fileInfos = [];
|
|
587
158
|
forEachFileInfo(basePath, fileInfo => fileInfos.push(fileInfo));
|
|
588
159
|
return fileInfos;
|
|
589
160
|
}
|
|
590
|
-
function forEachFileRecursive(basePath, func) {
|
|
161
|
+
export function forEachFileRecursive(basePath, func) {
|
|
591
162
|
forEachRecursive(basePath, filePath => {
|
|
592
|
-
if (!
|
|
163
|
+
if (!statSync(filePath).isDirectory())
|
|
593
164
|
func(filePath);
|
|
594
165
|
});
|
|
595
166
|
}
|
|
596
167
|
//END for each file recursive
|
|
597
168
|
//START for each directory recursive
|
|
598
|
-
function forEachDirInfoRecursive(basePath, func) {
|
|
599
|
-
forEachDirRecursive(basePath, filePath => func(new
|
|
169
|
+
export function forEachDirInfoRecursive(basePath, func) {
|
|
170
|
+
forEachDirRecursive(basePath, filePath => func(new FileInfo(filePath)));
|
|
600
171
|
}
|
|
601
|
-
function getEachDirInfoRecursive(basePath) {
|
|
172
|
+
export function getEachDirInfoRecursive(basePath) {
|
|
602
173
|
const fileInfos = [];
|
|
603
174
|
forEachDirInfoRecursive(basePath, fileInfo => {
|
|
604
175
|
fileInfos.push(fileInfo);
|
|
@@ -606,7 +177,7 @@ function getEachDirInfoRecursive(basePath) {
|
|
|
606
177
|
});
|
|
607
178
|
return fileInfos;
|
|
608
179
|
}
|
|
609
|
-
function getEachDirInfo(basePath) {
|
|
180
|
+
export function getEachDirInfo(basePath) {
|
|
610
181
|
const fileInfos = [];
|
|
611
182
|
forEachDirInfo(basePath, fileInfo => {
|
|
612
183
|
fileInfos.push(fileInfo);
|
|
@@ -614,7 +185,7 @@ function getEachDirInfo(basePath) {
|
|
|
614
185
|
});
|
|
615
186
|
return fileInfos;
|
|
616
187
|
}
|
|
617
|
-
function forEachDirRecursive(basePath, func) {
|
|
188
|
+
export function forEachDirRecursive(basePath, func) {
|
|
618
189
|
forEachDir(basePath, filePath => {
|
|
619
190
|
const result = func(filePath);
|
|
620
191
|
if (result != null && !result)
|
|
@@ -623,56 +194,55 @@ function forEachDirRecursive(basePath, func) {
|
|
|
623
194
|
});
|
|
624
195
|
}
|
|
625
196
|
//END for each directory recursive
|
|
626
|
-
function purgeEmptyDirectoriesRecursive(basePath) {
|
|
197
|
+
export function purgeEmptyDirectoriesRecursive(basePath) {
|
|
627
198
|
let removedDirectoriesCount = 0;
|
|
628
199
|
getEachDirInfoRecursive(basePath).forEach(dirInfo => {
|
|
629
|
-
const stat =
|
|
200
|
+
const stat = statSync(dirInfo.path);
|
|
630
201
|
if (!stat.isDirectory()) {
|
|
631
202
|
return;
|
|
632
203
|
}
|
|
633
|
-
const items =
|
|
204
|
+
const items = readdirSync(dirInfo.path);
|
|
634
205
|
if (items.length > 0) {
|
|
635
206
|
return;
|
|
636
207
|
}
|
|
637
208
|
++removedDirectoriesCount;
|
|
638
|
-
|
|
209
|
+
rmdirSync(dirInfo.path);
|
|
639
210
|
});
|
|
640
211
|
return removedDirectoriesCount;
|
|
641
212
|
}
|
|
642
|
-
function firstUpperLowerRest(input) {
|
|
213
|
+
export function firstUpperLowerRest(input) {
|
|
643
214
|
return input[0].toUpperCase() + input.slice(1).toLowerCase();
|
|
644
215
|
}
|
|
645
|
-
function firstUpperLowerRestEachWord(input) {
|
|
216
|
+
export function firstUpperLowerRestEachWord(input) {
|
|
646
217
|
return input.split(" ")
|
|
647
218
|
.filter(word => word.length > 0)
|
|
648
219
|
.map(word => firstUpperLowerRest(word))
|
|
649
220
|
.join(" ");
|
|
650
221
|
}
|
|
651
|
-
function countChars(input) {
|
|
222
|
+
export function countChars(input) {
|
|
652
223
|
const charCount = {};
|
|
653
224
|
for (const char of input)
|
|
654
225
|
incrementObjNumber(charCount, char);
|
|
655
226
|
return charCount;
|
|
656
227
|
}
|
|
657
|
-
function countWords(input) {
|
|
228
|
+
export function countWords(input) {
|
|
658
229
|
const wordCount = {};
|
|
659
|
-
for (const word of input.matchAll(
|
|
230
|
+
for (const word of input.matchAll(WORDS_REGEX))
|
|
660
231
|
incrementObjNumber(wordCount, word[0]);
|
|
661
232
|
return wordCount;
|
|
662
233
|
}
|
|
663
|
-
function countEmoji(input) {
|
|
234
|
+
export function countEmoji(input) {
|
|
664
235
|
const emojiCount = {};
|
|
665
|
-
for (const match of input.matchAll(
|
|
236
|
+
for (const match of input.matchAll(EMOJI_REGEX)) {
|
|
666
237
|
incrementObjNumber(emojiCount, match[0]);
|
|
667
238
|
}
|
|
668
|
-
for (const match of input.matchAll(
|
|
239
|
+
for (const match of input.matchAll(CUSTOM_EMOJI_REGEX)) {
|
|
669
240
|
incrementObjNumber(emojiCount, match[1]);
|
|
670
241
|
}
|
|
671
242
|
return emojiCount;
|
|
672
243
|
}
|
|
673
|
-
function incrementMap(map, key, incrementBy = 1) {
|
|
674
|
-
|
|
675
|
-
const existingValue = (_a = map.get(key)) !== null && _a !== void 0 ? _a : 0;
|
|
244
|
+
export function incrementMap(map, key, incrementBy = 1) {
|
|
245
|
+
const existingValue = map.get(key) ?? 0;
|
|
676
246
|
if (incrementBy == 0) {
|
|
677
247
|
return existingValue;
|
|
678
248
|
}
|
|
@@ -680,9 +250,8 @@ function incrementMap(map, key, incrementBy = 1) {
|
|
|
680
250
|
map.set(key, newValue);
|
|
681
251
|
return newValue;
|
|
682
252
|
}
|
|
683
|
-
function incrementObjNumber(obj, key, incrementBy = 1) {
|
|
684
|
-
|
|
685
|
-
const existingValue = (_a = obj[key]) !== null && _a !== void 0 ? _a : 0;
|
|
253
|
+
export function incrementObjNumber(obj, key, incrementBy = 1) {
|
|
254
|
+
const existingValue = obj[key] ?? 0;
|
|
686
255
|
if (incrementBy == 0) {
|
|
687
256
|
return existingValue;
|
|
688
257
|
}
|
|
@@ -690,41 +259,41 @@ function incrementObjNumber(obj, key, incrementBy = 1) {
|
|
|
690
259
|
obj[key] = newValue;
|
|
691
260
|
return newValue;
|
|
692
261
|
}
|
|
693
|
-
function addObjs(obj1, obj2) {
|
|
262
|
+
export function addObjs(obj1, obj2) {
|
|
694
263
|
for (const [key, value] of Object.entries(obj2)) {
|
|
695
264
|
incrementObjNumber(obj1, key, value);
|
|
696
265
|
}
|
|
697
266
|
return obj1;
|
|
698
267
|
}
|
|
699
|
-
function mergeObjs(...objs) {
|
|
268
|
+
export function mergeObjs(...objs) {
|
|
700
269
|
const obj = {};
|
|
701
270
|
for (const o of objs) {
|
|
702
271
|
Object.assign(obj, o);
|
|
703
272
|
}
|
|
704
273
|
return obj;
|
|
705
274
|
}
|
|
706
|
-
function sumValues(obj) {
|
|
275
|
+
export function sumValues(obj) {
|
|
707
276
|
let sum = 0;
|
|
708
277
|
for (const key of Object.keys(obj))
|
|
709
278
|
sum += obj[key];
|
|
710
279
|
return sum;
|
|
711
280
|
}
|
|
712
|
-
function getOrDefaultObj(input, key, elseValue) {
|
|
281
|
+
export function getOrDefaultObj(input, key, elseValue) {
|
|
713
282
|
if (input[key])
|
|
714
283
|
return input[key];
|
|
715
284
|
else
|
|
716
285
|
return elseValue;
|
|
717
286
|
}
|
|
718
|
-
function getOrDefaultMap(input, key, elseValue) {
|
|
287
|
+
export function getOrDefaultMap(input, key, elseValue) {
|
|
719
288
|
if (input.has(key))
|
|
720
289
|
return input.get(key);
|
|
721
290
|
else
|
|
722
291
|
return elseValue;
|
|
723
292
|
}
|
|
724
|
-
function getOrDefault(input, ifNull) {
|
|
293
|
+
export function getOrDefault(input, ifNull) {
|
|
725
294
|
return input == undefined ? ifNull : input;
|
|
726
295
|
}
|
|
727
|
-
async function runSoft(func) {
|
|
296
|
+
export async function runSoft(func) {
|
|
728
297
|
try {
|
|
729
298
|
await func.apply(null);
|
|
730
299
|
}
|
|
@@ -732,7 +301,7 @@ async function runSoft(func) {
|
|
|
732
301
|
console.log(e);
|
|
733
302
|
}
|
|
734
303
|
}
|
|
735
|
-
function blacklistArray(elements, blacklist = []) {
|
|
304
|
+
export function blacklistArray(elements, blacklist = []) {
|
|
736
305
|
const output = [];
|
|
737
306
|
for (const element of elements) {
|
|
738
307
|
if (blacklist.includes(element))
|
|
@@ -741,7 +310,7 @@ function blacklistArray(elements, blacklist = []) {
|
|
|
741
310
|
}
|
|
742
311
|
return output;
|
|
743
312
|
}
|
|
744
|
-
function getChars(word) {
|
|
313
|
+
export function getChars(word) {
|
|
745
314
|
word = word.toLowerCase();
|
|
746
315
|
let chars = {};
|
|
747
316
|
for (let i = 0; i < word.length; ++i) {
|
|
@@ -750,7 +319,7 @@ function getChars(word) {
|
|
|
750
319
|
}
|
|
751
320
|
return chars;
|
|
752
321
|
}
|
|
753
|
-
function getDiff(mAChars, mBChars) {
|
|
322
|
+
export function getDiff(mAChars, mBChars) {
|
|
754
323
|
let diff = 0;
|
|
755
324
|
const merged = {};
|
|
756
325
|
const mAKeys = Object.keys(mAChars);
|
|
@@ -778,24 +347,24 @@ function getDiff(mAChars, mBChars) {
|
|
|
778
347
|
});
|
|
779
348
|
return diff;
|
|
780
349
|
}
|
|
781
|
-
function formatDate(date) {
|
|
350
|
+
export function formatDate(date) {
|
|
782
351
|
return date.toISOString().replace(/T/, ' ').replace(/\..+/, '');
|
|
783
352
|
}
|
|
784
|
-
function decide(decision) {
|
|
353
|
+
export function decide(decision) {
|
|
785
354
|
return decision();
|
|
786
355
|
}
|
|
787
|
-
async function decideAsync(decision) {
|
|
356
|
+
export async function decideAsync(decision) {
|
|
788
357
|
return await decision();
|
|
789
358
|
}
|
|
790
|
-
function make(obj, init) {
|
|
359
|
+
export function make(obj, init) {
|
|
791
360
|
init(obj);
|
|
792
361
|
return obj;
|
|
793
362
|
}
|
|
794
|
-
async function makeAsync(obj, init) {
|
|
363
|
+
export async function makeAsync(obj, init) {
|
|
795
364
|
await init(obj);
|
|
796
365
|
return obj;
|
|
797
366
|
}
|
|
798
|
-
function extractElementsIntoArray(obj, elementKey) {
|
|
367
|
+
export function extractElementsIntoArray(obj, elementKey) {
|
|
799
368
|
const elements = [];
|
|
800
369
|
for (const key of Object.keys(obj)) {
|
|
801
370
|
const item = obj[key];
|
|
@@ -805,7 +374,7 @@ function extractElementsIntoArray(obj, elementKey) {
|
|
|
805
374
|
}
|
|
806
375
|
return elements;
|
|
807
376
|
}
|
|
808
|
-
function extractItemsIntoArray(obj, predicate) {
|
|
377
|
+
export function extractItemsIntoArray(obj, predicate) {
|
|
809
378
|
const items = [];
|
|
810
379
|
for (const key of Object.keys(obj)) {
|
|
811
380
|
const item = obj[key];
|
|
@@ -814,7 +383,7 @@ function extractItemsIntoArray(obj, predicate) {
|
|
|
814
383
|
}
|
|
815
384
|
return items;
|
|
816
385
|
}
|
|
817
|
-
function mapArrayOfObjsByElement(obj, elementKey) {
|
|
386
|
+
export function mapArrayOfObjsByElement(obj, elementKey) {
|
|
818
387
|
const map = new Map;
|
|
819
388
|
for (const key of Object.keys(obj)) {
|
|
820
389
|
const item = obj[key];
|
|
@@ -823,13 +392,13 @@ function mapArrayOfObjsByElement(obj, elementKey) {
|
|
|
823
392
|
}
|
|
824
393
|
return map;
|
|
825
394
|
}
|
|
826
|
-
function mapToArray(items, mapFunction) {
|
|
395
|
+
export function mapToArray(items, mapFunction) {
|
|
827
396
|
return make([], (array) => {
|
|
828
397
|
for (const item of items)
|
|
829
398
|
array.push(mapFunction(item));
|
|
830
399
|
});
|
|
831
400
|
}
|
|
832
|
-
function stringify(obj, ignoreEmpty = false) {
|
|
401
|
+
export function stringify(obj, ignoreEmpty = false) {
|
|
833
402
|
for (const key of Object.keys(obj)) {
|
|
834
403
|
const value = obj[key];
|
|
835
404
|
const isBigInt = typeof value == "bigint";
|
|
@@ -842,17 +411,17 @@ function stringify(obj, ignoreEmpty = false) {
|
|
|
842
411
|
}
|
|
843
412
|
return JSON.stringify(obj, null, "\t").replace(/: ([{\[])\n([\t]*)\t/g, ":\n$2$1\n$2\t");
|
|
844
413
|
}
|
|
845
|
-
function acronymStringIfTooLong(input, limit = 10, includeFillers = true) {
|
|
414
|
+
export function acronymStringIfTooLong(input, limit = 10, includeFillers = true) {
|
|
846
415
|
let processedInput = input.replaceAll(/['"]/g, "").replaceAll(/[^\p{L}0-9]/giu, " ").trim();
|
|
847
416
|
if (!includeFillers) {
|
|
848
|
-
processedInput = processedInput.replaceAll(
|
|
417
|
+
processedInput = processedInput.replaceAll(ACRONYM_REGEXES, "");
|
|
849
418
|
}
|
|
850
419
|
if (processedInput.length <= 0) {
|
|
851
420
|
return processedInput;
|
|
852
421
|
}
|
|
853
422
|
if (processedInput.length >= limit) {
|
|
854
423
|
let output = "";
|
|
855
|
-
for (const result of processedInput.matchAll(
|
|
424
|
+
for (const result of processedInput.matchAll(ACRONYM_REGEX)) {
|
|
856
425
|
const match = result[0];
|
|
857
426
|
output += match.charAt(match.length - 1);
|
|
858
427
|
}
|
|
@@ -860,47 +429,46 @@ function acronymStringIfTooLong(input, limit = 10, includeFillers = true) {
|
|
|
860
429
|
}
|
|
861
430
|
return input;
|
|
862
431
|
}
|
|
863
|
-
function mkdirSoftRecursive(fullPath) {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
let path = (_b = (_a = fullPath.match(fields_1.START_OF_PATH_REGEX)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : "";
|
|
432
|
+
export function mkdirSoftRecursive(fullPath) {
|
|
433
|
+
fullPath = fullPath.replaceAll(SEPARATOR_REGEX, SEP);
|
|
434
|
+
let path = fullPath.match(START_OF_PATH_REGEX)?.[0] ?? "";
|
|
867
435
|
const parts = fullPath.slice(path.length).split(/[\\\/]/);
|
|
868
436
|
for (const part of parts) {
|
|
869
|
-
path += part +
|
|
437
|
+
path += part + SEP;
|
|
870
438
|
mkdirSoft(`${path}`);
|
|
871
439
|
}
|
|
872
440
|
}
|
|
873
|
-
function mkdirSoft(path) {
|
|
874
|
-
if (!
|
|
875
|
-
|
|
441
|
+
export function mkdirSoft(path) {
|
|
442
|
+
if (!existsSync(path)) {
|
|
443
|
+
mkdirSync(path);
|
|
876
444
|
}
|
|
877
445
|
}
|
|
878
|
-
function goUpDir(dir, times = 1) {
|
|
446
|
+
export function goUpDir(dir, times = 1) {
|
|
879
447
|
for (let i = 0; i < times; ++i)
|
|
880
448
|
dir = dir.slice(0, lastIndexOfSeparator(dir));
|
|
881
449
|
return dir;
|
|
882
450
|
}
|
|
883
|
-
function writeFileIfNotPresent(path, data, options) {
|
|
884
|
-
if (!
|
|
885
|
-
|
|
451
|
+
export function writeFileIfNotPresent(path, data, options) {
|
|
452
|
+
if (!existsSync(path))
|
|
453
|
+
writeFileSync(path, data);
|
|
886
454
|
}
|
|
887
|
-
function requireSoft(path, data, options) {
|
|
455
|
+
export function requireSoft(path, data, options) {
|
|
888
456
|
writeFileIfNotPresent(path, data);
|
|
889
457
|
return require(path);
|
|
890
458
|
}
|
|
891
|
-
function clone(obj) {
|
|
459
|
+
export function clone(obj) {
|
|
892
460
|
return Object.assign({}, obj);
|
|
893
461
|
}
|
|
894
|
-
function getBit(number, bit) {
|
|
462
|
+
export function getBit(number, bit) {
|
|
895
463
|
return (number >> bit) & 1;
|
|
896
464
|
}
|
|
897
|
-
function isBit(number, bit) {
|
|
465
|
+
export function isBit(number, bit) {
|
|
898
466
|
return getBit(number, bit) == 1;
|
|
899
467
|
}
|
|
900
|
-
function map(input, min1, max1, min2, max2) {
|
|
468
|
+
export function map(input, min1, max1, min2, max2) {
|
|
901
469
|
return ((input - min1) / (max1 - min1)) * (max2 - min2) + min2;
|
|
902
470
|
}
|
|
903
|
-
function logMap(input, inputStart, inputEnd, outputStart, outputEnd, curveIntensity) {
|
|
471
|
+
export function logMap(input, inputStart, inputEnd, outputStart, outputEnd, curveIntensity) {
|
|
904
472
|
// Validate and clamp curve intensity
|
|
905
473
|
// curveIntensity = Math.max(-1, Math.min(1, curveIntensity || 0))
|
|
906
474
|
// Handle linear case (curveIntensity = 0)
|
|
@@ -925,29 +493,29 @@ function logMap(input, inputStart, inputEnd, outputStart, outputEnd, curveIntens
|
|
|
925
493
|
// Map to output range
|
|
926
494
|
return outputStart + mappedValue * (outputEnd - outputStart);
|
|
927
495
|
}
|
|
928
|
-
function clamp(input, min, max) {
|
|
496
|
+
export function clamp(input, min, max) {
|
|
929
497
|
return Math.max(min, Math.min(max, input));
|
|
930
498
|
}
|
|
931
|
-
function clamp0(input, max) {
|
|
499
|
+
export function clamp0(input, max) {
|
|
932
500
|
return clamp(input, 0, max);
|
|
933
501
|
}
|
|
934
502
|
/**
|
|
935
503
|
* @param startDate in ms
|
|
936
504
|
* @param endDate in ms
|
|
937
505
|
*/
|
|
938
|
-
function datesDiff(dates) {
|
|
506
|
+
export function datesDiff(dates) {
|
|
939
507
|
return dates.endDate.valueOf() - (dates.startDate ? dates.startDate : new Date()).valueOf();
|
|
940
508
|
}
|
|
941
|
-
function datesDiffToStamp(dates) {
|
|
509
|
+
export function datesDiffToStamp(dates) {
|
|
942
510
|
return toStamp(datesDiff(dates) / 1000);
|
|
943
511
|
}
|
|
944
|
-
function datesGapToStamp(startDate, endDate) {
|
|
512
|
+
export function datesGapToStamp(startDate, endDate) {
|
|
945
513
|
return toStamp((endDate.valueOf() - startDate.valueOf()) / 1000);
|
|
946
514
|
}
|
|
947
|
-
function dateToStamp(date) {
|
|
515
|
+
export function dateToStamp(date) {
|
|
948
516
|
return toStamp(date.valueOf() / 1000);
|
|
949
517
|
}
|
|
950
|
-
function toStamp(toStamp) {
|
|
518
|
+
export function toStamp(toStamp) {
|
|
951
519
|
if (isNaN(toStamp) || toStamp == Infinity || toStamp == -Infinity) {
|
|
952
520
|
toStamp = 0;
|
|
953
521
|
}
|
|
@@ -975,7 +543,7 @@ function toStamp(toStamp) {
|
|
|
975
543
|
else
|
|
976
544
|
return stamped;
|
|
977
545
|
}
|
|
978
|
-
function convertNumberBase(num, fromBase, toBase) {
|
|
546
|
+
export function convertNumberBase(num, fromBase, toBase) {
|
|
979
547
|
const decimalValue = parseInt(num, fromBase);
|
|
980
548
|
let convertedValue = '';
|
|
981
549
|
let quotient = decimalValue;
|
|
@@ -986,45 +554,45 @@ function convertNumberBase(num, fromBase, toBase) {
|
|
|
986
554
|
}
|
|
987
555
|
return convertedValue;
|
|
988
556
|
}
|
|
989
|
-
function moveSync(oldPath, newPath) {
|
|
557
|
+
export function moveSync(oldPath, newPath) {
|
|
990
558
|
try {
|
|
991
|
-
|
|
559
|
+
renameSync(oldPath, newPath);
|
|
992
560
|
}
|
|
993
561
|
catch (err) {
|
|
994
562
|
if (err.code == "EXDEV") {
|
|
995
|
-
|
|
996
|
-
|
|
563
|
+
copyFileSync(oldPath, newPath);
|
|
564
|
+
unlinkSync(oldPath);
|
|
997
565
|
}
|
|
998
566
|
}
|
|
999
567
|
}
|
|
1000
|
-
async function download(url, dir) {
|
|
568
|
+
export async function download(url, dir) {
|
|
1001
569
|
return new Promise((resolve, reject) => {
|
|
1002
|
-
const file =
|
|
1003
|
-
const request =
|
|
570
|
+
const file = createWriteStream(dir);
|
|
571
|
+
const request = get(url, function (response) {
|
|
1004
572
|
response.pipe(file);
|
|
1005
573
|
resolve(`success\nurl:${url}\ndir:${dir}`);
|
|
1006
574
|
}).on("error", reject);
|
|
1007
575
|
});
|
|
1008
576
|
}
|
|
1009
|
-
function isCharUpperCase(char) {
|
|
577
|
+
export function isCharUpperCase(char) {
|
|
1010
578
|
return char.charCodeAt(0) >= 65 && char.charCodeAt(0) <= 90;
|
|
1011
579
|
}
|
|
1012
|
-
function isCharLowerCase(char) {
|
|
580
|
+
export function isCharLowerCase(char) {
|
|
1013
581
|
return char.charCodeAt(0) >= 97 && char.charCodeAt(0) <= 122;
|
|
1014
582
|
}
|
|
1015
|
-
function isStandardLetter(char) {
|
|
583
|
+
export function isStandardLetter(char) {
|
|
1016
584
|
return isCharLowerCase(char) || isCharUpperCase(char);
|
|
1017
585
|
}
|
|
1018
|
-
function getOrCreateAppendedLinesFile(path) {
|
|
586
|
+
export function getOrCreateAppendedLinesFile(path) {
|
|
1019
587
|
writeFileIfNotPresent(path, "");
|
|
1020
|
-
return new Set(
|
|
588
|
+
return new Set(readFileSync(path, "utf8").split(/[\r\n]/));
|
|
1021
589
|
}
|
|
1022
|
-
function rmSoft(path) {
|
|
1023
|
-
if (
|
|
1024
|
-
|
|
590
|
+
export function rmSoft(path) {
|
|
591
|
+
if (existsSync(path)) {
|
|
592
|
+
rmSync(path);
|
|
1025
593
|
}
|
|
1026
594
|
}
|
|
1027
|
-
function saveAppendedLinesFile(path, lines, excludeEmpty = true, trim = true) {
|
|
595
|
+
export function saveAppendedLinesFile(path, lines, excludeEmpty = true, trim = true) {
|
|
1028
596
|
rmSoft(path);
|
|
1029
597
|
const slashIndex = lastIndexOfSeparator(path);
|
|
1030
598
|
if (slashIndex != -1) {
|
|
@@ -1035,28 +603,28 @@ function saveAppendedLinesFile(path, lines, excludeEmpty = true, trim = true) {
|
|
|
1035
603
|
if (excludeEmpty && line.length <= 0) {
|
|
1036
604
|
continue;
|
|
1037
605
|
}
|
|
1038
|
-
|
|
606
|
+
appendFileSync(path, `${trim ? line.trim() : line}\n`);
|
|
1039
607
|
}
|
|
1040
608
|
}
|
|
1041
|
-
function getOrCreateFromKeys(map, keys, maker) {
|
|
609
|
+
export function getOrCreateFromKeys(map, keys, maker) {
|
|
1042
610
|
for (const key of keys) {
|
|
1043
611
|
getOrCreate(map, key, maker);
|
|
1044
612
|
}
|
|
1045
613
|
return map;
|
|
1046
614
|
}
|
|
1047
|
-
function getOrCreate(map, key, maker) {
|
|
615
|
+
export function getOrCreate(map, key, maker) {
|
|
1048
616
|
if (!map.has(key)) {
|
|
1049
617
|
map.set(key, maker());
|
|
1050
618
|
}
|
|
1051
619
|
return map.get(key);
|
|
1052
620
|
}
|
|
1053
|
-
function getOrCreateObj(obj, key, ifNullMaker) {
|
|
621
|
+
export function getOrCreateObj(obj, key, ifNullMaker) {
|
|
1054
622
|
if (obj[key] == null) {
|
|
1055
623
|
obj[key] = ifNullMaker();
|
|
1056
624
|
}
|
|
1057
625
|
return obj[key];
|
|
1058
626
|
}
|
|
1059
|
-
function appendObjArray(obj, key, item) {
|
|
627
|
+
export function appendObjArray(obj, key, item) {
|
|
1060
628
|
let array = obj[key];
|
|
1061
629
|
if (array == null) {
|
|
1062
630
|
array = [];
|
|
@@ -1065,7 +633,7 @@ function appendObjArray(obj, key, item) {
|
|
|
1065
633
|
array.push(item);
|
|
1066
634
|
return obj[key];
|
|
1067
635
|
}
|
|
1068
|
-
function organiseByKey(items, keyRetriever) {
|
|
636
|
+
export function organiseByKey(items, keyRetriever) {
|
|
1069
637
|
const obj = {};
|
|
1070
638
|
for (const item of items) {
|
|
1071
639
|
appendObjArray(obj, keyRetriever(item), item);
|
|
@@ -1073,196 +641,196 @@ function organiseByKey(items, keyRetriever) {
|
|
|
1073
641
|
return obj;
|
|
1074
642
|
}
|
|
1075
643
|
//To Nanoseconds
|
|
1076
|
-
function millisecondsToNanoseconds(milliseconds) {
|
|
1077
|
-
return milliseconds *
|
|
644
|
+
export function millisecondsToNanoseconds(milliseconds) {
|
|
645
|
+
return milliseconds * NANOSECONDS_IN_MILLISECOND;
|
|
1078
646
|
}
|
|
1079
|
-
function secondsToNanoseconds(nanoseconds) {
|
|
1080
|
-
return nanoseconds *
|
|
647
|
+
export function secondsToNanoseconds(nanoseconds) {
|
|
648
|
+
return nanoseconds * NANOSECONDS_IN_SECOND;
|
|
1081
649
|
}
|
|
1082
|
-
function minutesToNanoseconds(minutes) {
|
|
1083
|
-
return minutes *
|
|
650
|
+
export function minutesToNanoseconds(minutes) {
|
|
651
|
+
return minutes * NANOSECONDS_IN_MINUTE;
|
|
1084
652
|
}
|
|
1085
|
-
function hoursToNanoseconds(hours) {
|
|
1086
|
-
return hours *
|
|
653
|
+
export function hoursToNanoseconds(hours) {
|
|
654
|
+
return hours * NANOSECONDS_IN_HOUR;
|
|
1087
655
|
}
|
|
1088
|
-
function daysToNanoseconds(days) {
|
|
1089
|
-
return days *
|
|
656
|
+
export function daysToNanoseconds(days) {
|
|
657
|
+
return days * NANOSECONDS_IN_DAY;
|
|
1090
658
|
}
|
|
1091
|
-
function weeksToNanoseconds(weeks) {
|
|
1092
|
-
return weeks *
|
|
659
|
+
export function weeksToNanoseconds(weeks) {
|
|
660
|
+
return weeks * NANOSECONDS_IN_WEEK;
|
|
1093
661
|
}
|
|
1094
662
|
//!To Nanoseconds
|
|
1095
663
|
//To Milliseconds
|
|
1096
|
-
function nanosecondsToMilliseconds(nanoseconds) {
|
|
1097
|
-
return nanoseconds /
|
|
664
|
+
export function nanosecondsToMilliseconds(nanoseconds) {
|
|
665
|
+
return nanoseconds / NANOSECONDS_IN_MILLISECOND;
|
|
1098
666
|
}
|
|
1099
|
-
function secondsToMilliseconds(milliseconds) {
|
|
1100
|
-
return milliseconds *
|
|
667
|
+
export function secondsToMilliseconds(milliseconds) {
|
|
668
|
+
return milliseconds * MILLISECONDS_IN_SECOND;
|
|
1101
669
|
}
|
|
1102
|
-
function minutesToMilliseconds(minutes) {
|
|
1103
|
-
return minutes *
|
|
670
|
+
export function minutesToMilliseconds(minutes) {
|
|
671
|
+
return minutes * MILLISECONDS_IN_MINUTE;
|
|
1104
672
|
}
|
|
1105
|
-
function hoursToMilliseconds(hours) {
|
|
1106
|
-
return hours *
|
|
673
|
+
export function hoursToMilliseconds(hours) {
|
|
674
|
+
return hours * MILLISECONDS_IN_HOUR;
|
|
1107
675
|
}
|
|
1108
|
-
function daysToMilliseconds(days) {
|
|
1109
|
-
return days *
|
|
676
|
+
export function daysToMilliseconds(days) {
|
|
677
|
+
return days * MILLISECONDS_IN_DAY;
|
|
1110
678
|
}
|
|
1111
|
-
function weeksToMilliseconds(weeks) {
|
|
1112
|
-
return weeks *
|
|
679
|
+
export function weeksToMilliseconds(weeks) {
|
|
680
|
+
return weeks * MILLISECONDS_IN_WEEK;
|
|
1113
681
|
}
|
|
1114
682
|
//!To Milliseconds
|
|
1115
683
|
//To Seconds
|
|
1116
|
-
function nanosecondsToSeconds(nanoseconds) {
|
|
1117
|
-
return nanoseconds /
|
|
684
|
+
export function nanosecondsToSeconds(nanoseconds) {
|
|
685
|
+
return nanoseconds / NANOSECONDS_IN_SECOND;
|
|
1118
686
|
}
|
|
1119
|
-
function millisecondsToSeconds(milliseconds) {
|
|
1120
|
-
return milliseconds /
|
|
687
|
+
export function millisecondsToSeconds(milliseconds) {
|
|
688
|
+
return milliseconds / MILLISECONDS_IN_SECOND;
|
|
1121
689
|
}
|
|
1122
|
-
function minutesToSeconds(minutes) {
|
|
1123
|
-
return minutes *
|
|
690
|
+
export function minutesToSeconds(minutes) {
|
|
691
|
+
return minutes * SECONDS_IN_MINUTE;
|
|
1124
692
|
}
|
|
1125
|
-
function hoursToSeconds(hours) {
|
|
1126
|
-
return hours *
|
|
693
|
+
export function hoursToSeconds(hours) {
|
|
694
|
+
return hours * SECONDS_IN_HOUR;
|
|
1127
695
|
}
|
|
1128
|
-
function daysToSeconds(days) {
|
|
1129
|
-
return days *
|
|
696
|
+
export function daysToSeconds(days) {
|
|
697
|
+
return days * SECONDS_IN_DAY;
|
|
1130
698
|
}
|
|
1131
|
-
function weeksToSeconds(weeks) {
|
|
1132
|
-
return weeks *
|
|
699
|
+
export function weeksToSeconds(weeks) {
|
|
700
|
+
return weeks * SECONDS_IN_WEEK;
|
|
1133
701
|
}
|
|
1134
702
|
//!To Seconds
|
|
1135
703
|
//To Minutes
|
|
1136
|
-
function nanosecondsToMinutes(nanoseconds) {
|
|
1137
|
-
return nanoseconds /
|
|
704
|
+
export function nanosecondsToMinutes(nanoseconds) {
|
|
705
|
+
return nanoseconds / NANOSECONDS_IN_MINUTE;
|
|
1138
706
|
}
|
|
1139
|
-
function millisecondsToMinutes(milliseconds) {
|
|
1140
|
-
return milliseconds /
|
|
707
|
+
export function millisecondsToMinutes(milliseconds) {
|
|
708
|
+
return milliseconds / MILLISECONDS_IN_MINUTE;
|
|
1141
709
|
}
|
|
1142
|
-
function secondsToMinutes(minutes) {
|
|
1143
|
-
return minutes /
|
|
710
|
+
export function secondsToMinutes(minutes) {
|
|
711
|
+
return minutes / SECONDS_IN_MINUTE;
|
|
1144
712
|
}
|
|
1145
|
-
function hoursToMinutes(hours) {
|
|
1146
|
-
return hours *
|
|
713
|
+
export function hoursToMinutes(hours) {
|
|
714
|
+
return hours * MINUTES_IN_HOUR;
|
|
1147
715
|
}
|
|
1148
|
-
function daysToMinutes(days) {
|
|
1149
|
-
return days *
|
|
716
|
+
export function daysToMinutes(days) {
|
|
717
|
+
return days * MINUTES_IN_DAY;
|
|
1150
718
|
}
|
|
1151
|
-
function weeksToMinutes(weeks) {
|
|
1152
|
-
return weeks *
|
|
719
|
+
export function weeksToMinutes(weeks) {
|
|
720
|
+
return weeks * MINUTES_IN_WEEK;
|
|
1153
721
|
}
|
|
1154
722
|
//!To Minutes
|
|
1155
723
|
//To Hours
|
|
1156
|
-
function nanosecondsToHours(nanoseconds) {
|
|
1157
|
-
return nanoseconds /
|
|
724
|
+
export function nanosecondsToHours(nanoseconds) {
|
|
725
|
+
return nanoseconds / NANOSECONDS_IN_HOUR;
|
|
1158
726
|
}
|
|
1159
|
-
function millisecondsToHours(milliseconds) {
|
|
1160
|
-
return milliseconds /
|
|
727
|
+
export function millisecondsToHours(milliseconds) {
|
|
728
|
+
return milliseconds / MILLISECONDS_IN_HOUR;
|
|
1161
729
|
}
|
|
1162
|
-
function secondsToHours(seconds) {
|
|
1163
|
-
return seconds /
|
|
730
|
+
export function secondsToHours(seconds) {
|
|
731
|
+
return seconds / SECONDS_IN_HOUR;
|
|
1164
732
|
}
|
|
1165
|
-
function minutesToHours(minutes) {
|
|
1166
|
-
return minutes /
|
|
733
|
+
export function minutesToHours(minutes) {
|
|
734
|
+
return minutes / MINUTES_IN_HOUR;
|
|
1167
735
|
}
|
|
1168
|
-
function daysToHours(days) {
|
|
1169
|
-
return days *
|
|
736
|
+
export function daysToHours(days) {
|
|
737
|
+
return days * HOURS_IN_DAY;
|
|
1170
738
|
}
|
|
1171
|
-
function weeksToHours(weeks) {
|
|
1172
|
-
return weeks *
|
|
739
|
+
export function weeksToHours(weeks) {
|
|
740
|
+
return weeks * HOURS_IN_WEEK;
|
|
1173
741
|
}
|
|
1174
742
|
//!To Hours
|
|
1175
743
|
//To Days
|
|
1176
|
-
function nanosecondsToDays(nanoseconds) {
|
|
1177
|
-
return nanoseconds /
|
|
744
|
+
export function nanosecondsToDays(nanoseconds) {
|
|
745
|
+
return nanoseconds / NANOSECONDS_IN_DAY;
|
|
1178
746
|
}
|
|
1179
|
-
function millisecondsToDays(milliseconds) {
|
|
1180
|
-
return milliseconds /
|
|
747
|
+
export function millisecondsToDays(milliseconds) {
|
|
748
|
+
return milliseconds / MILLISECONDS_IN_DAY;
|
|
1181
749
|
}
|
|
1182
|
-
function secondsToDays(seconds) {
|
|
1183
|
-
return seconds /
|
|
750
|
+
export function secondsToDays(seconds) {
|
|
751
|
+
return seconds / SECONDS_IN_DAY;
|
|
1184
752
|
}
|
|
1185
|
-
function minutesToDays(minutes) {
|
|
1186
|
-
return minutes /
|
|
753
|
+
export function minutesToDays(minutes) {
|
|
754
|
+
return minutes / MINUTES_IN_DAY;
|
|
1187
755
|
}
|
|
1188
|
-
function hoursToDays(hours) {
|
|
1189
|
-
return hours /
|
|
756
|
+
export function hoursToDays(hours) {
|
|
757
|
+
return hours / HOURS_IN_DAY;
|
|
1190
758
|
}
|
|
1191
|
-
function weeksToDays(weeks) {
|
|
1192
|
-
return weeks *
|
|
759
|
+
export function weeksToDays(weeks) {
|
|
760
|
+
return weeks * DAYS_IN_WEEK;
|
|
1193
761
|
}
|
|
1194
762
|
//!To Days
|
|
1195
763
|
//To Weeks
|
|
1196
|
-
function nanosecondsToWeeks(nanoseconds) {
|
|
1197
|
-
return nanoseconds /
|
|
764
|
+
export function nanosecondsToWeeks(nanoseconds) {
|
|
765
|
+
return nanoseconds / NANOSECONDS_IN_WEEK;
|
|
1198
766
|
}
|
|
1199
|
-
function millisecondsToWeeks(milliseconds) {
|
|
1200
|
-
return milliseconds /
|
|
767
|
+
export function millisecondsToWeeks(milliseconds) {
|
|
768
|
+
return milliseconds / MILLISECONDS_IN_WEEK;
|
|
1201
769
|
}
|
|
1202
|
-
function secondsToWeeks(seconds) {
|
|
1203
|
-
return seconds /
|
|
770
|
+
export function secondsToWeeks(seconds) {
|
|
771
|
+
return seconds / SECONDS_IN_WEEK;
|
|
1204
772
|
}
|
|
1205
|
-
function minutesToWeeks(minutes) {
|
|
1206
|
-
return minutes /
|
|
773
|
+
export function minutesToWeeks(minutes) {
|
|
774
|
+
return minutes / MINUTES_IN_WEEK;
|
|
1207
775
|
}
|
|
1208
|
-
function hoursToWeeks(hours) {
|
|
1209
|
-
return hours /
|
|
776
|
+
export function hoursToWeeks(hours) {
|
|
777
|
+
return hours / HOURS_IN_WEEK;
|
|
1210
778
|
}
|
|
1211
|
-
function daysToWeeks(days) {
|
|
1212
|
-
return days /
|
|
779
|
+
export function daysToWeeks(days) {
|
|
780
|
+
return days / DAYS_IN_WEEK;
|
|
1213
781
|
}
|
|
1214
782
|
//!To Weeks
|
|
1215
|
-
function minutesToHoursMinutes(totalMinutes) {
|
|
783
|
+
export function minutesToHoursMinutes(totalMinutes) {
|
|
1216
784
|
let minutes = Math.floor(totalMinutes % 60);
|
|
1217
785
|
return padLeft("" + Math.floor(totalMinutes / 60), 2, "0") + ":" + padLeft("" + minutes, 2, "0");
|
|
1218
786
|
}
|
|
1219
|
-
function parsedFileInfoNameToIntSort(a, b, ascending = true) {
|
|
787
|
+
export function parsedFileInfoNameToIntSort(a, b, ascending = true) {
|
|
1220
788
|
return parsedStringToIntSort(a.name, b.name, ascending);
|
|
1221
789
|
}
|
|
1222
|
-
function parsedStringToIntSort(a, b, ascending = true) {
|
|
1223
|
-
const valueA = parseInt(a.replaceAll(
|
|
1224
|
-
const valueB = parseInt(b.replaceAll(
|
|
790
|
+
export function parsedStringToIntSort(a, b, ascending = true) {
|
|
791
|
+
const valueA = parseInt(a.replaceAll(NON_NUMBER_REGEX, ""));
|
|
792
|
+
const valueB = parseInt(b.replaceAll(NON_NUMBER_REGEX, ""));
|
|
1225
793
|
return ascending ? valueA - valueB : valueB - valueA;
|
|
1226
794
|
}
|
|
1227
|
-
function degreesToRadians(degrees) {
|
|
1228
|
-
return degrees *
|
|
795
|
+
export function degreesToRadians(degrees) {
|
|
796
|
+
return degrees * DEGREES_TO_RADIANS;
|
|
1229
797
|
}
|
|
1230
|
-
function toRads(degrees) {
|
|
1231
|
-
return degrees *
|
|
798
|
+
export function toRads(degrees) {
|
|
799
|
+
return degrees * DEGREES_TO_RADIANS;
|
|
1232
800
|
}
|
|
1233
|
-
function radiansToDegrees(radians) {
|
|
1234
|
-
return radians *
|
|
801
|
+
export function radiansToDegrees(radians) {
|
|
802
|
+
return radians * RADIANS_TO_DEGREES;
|
|
1235
803
|
}
|
|
1236
|
-
function toDegs(radians) {
|
|
1237
|
-
return radians *
|
|
804
|
+
export function toDegs(radians) {
|
|
805
|
+
return radians * RADIANS_TO_DEGREES;
|
|
1238
806
|
}
|
|
1239
|
-
function getDayMonthYearDateString() {
|
|
807
|
+
export function getDayMonthYearDateString() {
|
|
1240
808
|
const nowDate = new Date();
|
|
1241
809
|
const dateStr = `${nowDate.getDate()}-${nowDate.getMonth() + 1}-${nowDate.getFullYear()}`;
|
|
1242
810
|
return dateStr;
|
|
1243
811
|
}
|
|
1244
|
-
function touchSoft(path, defaultContent = "") {
|
|
1245
|
-
if (!
|
|
1246
|
-
|
|
812
|
+
export function touchSoft(path, defaultContent = "") {
|
|
813
|
+
if (!existsSync(path)) {
|
|
814
|
+
writeFileSync(path, defaultContent);
|
|
1247
815
|
}
|
|
1248
816
|
}
|
|
1249
|
-
function increment(path, amount = 1, float = false) {
|
|
1250
|
-
if (!
|
|
1251
|
-
|
|
817
|
+
export function increment(path, amount = 1, float = false) {
|
|
818
|
+
if (!existsSync(path)) {
|
|
819
|
+
writeFileSync(path, "" + amount);
|
|
1252
820
|
return amount;
|
|
1253
821
|
}
|
|
1254
|
-
const parsedNumber = float ? parseFloat(
|
|
822
|
+
const parsedNumber = float ? parseFloat(readFileSync(path, "utf8")) : parseInt(readFileSync(path, "utf8"));
|
|
1255
823
|
const newValue = (isNaN(parsedNumber) ? 0 : parsedNumber) + amount;
|
|
1256
|
-
|
|
824
|
+
writeFileSync(path, "" + newValue);
|
|
1257
825
|
return newValue;
|
|
1258
826
|
}
|
|
1259
|
-
function readFileInt(path) {
|
|
1260
|
-
if (
|
|
1261
|
-
return parseInt(
|
|
827
|
+
export function readFileInt(path) {
|
|
828
|
+
if (existsSync(path)) {
|
|
829
|
+
return parseInt(readFileSync(path, "utf8"));
|
|
1262
830
|
}
|
|
1263
831
|
return -1;
|
|
1264
832
|
}
|
|
1265
|
-
function hashCode(str) {
|
|
833
|
+
export function hashCode(str) {
|
|
1266
834
|
let hash = 0;
|
|
1267
835
|
if (str.length === 0) {
|
|
1268
836
|
return hash;
|
|
@@ -1274,97 +842,97 @@ function hashCode(str) {
|
|
|
1274
842
|
}
|
|
1275
843
|
return hash;
|
|
1276
844
|
}
|
|
1277
|
-
function chalkColor(input, color) {
|
|
1278
|
-
return
|
|
845
|
+
export function chalkColor(input, color) {
|
|
846
|
+
return chalk.keyword(color)(input);
|
|
1279
847
|
}
|
|
1280
|
-
function chalkRainbowColor(input, color) {
|
|
1281
|
-
return
|
|
848
|
+
export function chalkRainbowColor(input, color) {
|
|
849
|
+
return chalk.keyword(CHALK_RAINBOW_COLORS[Math.abs(color) % CHALK_RAINBOW_COLORS.length])(input);
|
|
1282
850
|
}
|
|
1283
|
-
function chalkNextRainbowColor(input) {
|
|
851
|
+
export function chalkNextRainbowColor(input) {
|
|
1284
852
|
return chalkRainbowColor(input, rainbowIndex++);
|
|
1285
853
|
}
|
|
1286
|
-
function seededChalkRainbowColor(input) {
|
|
1287
|
-
return
|
|
854
|
+
export function seededChalkRainbowColor(input) {
|
|
855
|
+
return chalk.keyword(randomFromArray(CHALK_RAINBOW_COLORS))(input);
|
|
1288
856
|
}
|
|
1289
|
-
function randomChalkRainbowColor(input) {
|
|
857
|
+
export function randomChalkRainbowColor(input) {
|
|
1290
858
|
return chalkRainbowColor(input, hashCode(input));
|
|
1291
859
|
}
|
|
1292
|
-
function padLeft(input, leftPad, padCharacter = " ") {
|
|
860
|
+
export function padLeft(input, leftPad, padCharacter = " ") {
|
|
1293
861
|
const padAmount = leftPad - input.length;
|
|
1294
862
|
for (let i = 0; i < padAmount; ++i) {
|
|
1295
863
|
input = padCharacter + input;
|
|
1296
864
|
}
|
|
1297
865
|
return input;
|
|
1298
866
|
}
|
|
1299
|
-
function padRight(input, rightPad, padCharacter = " ") {
|
|
867
|
+
export function padRight(input, rightPad, padCharacter = " ") {
|
|
1300
868
|
const padAmount = rightPad - input.length;
|
|
1301
869
|
for (let i = 0; i < padAmount; ++i) {
|
|
1302
870
|
input += padCharacter;
|
|
1303
871
|
}
|
|
1304
872
|
return input;
|
|
1305
873
|
}
|
|
1306
|
-
function getCuteAscii() {
|
|
1307
|
-
return randomFromArray(
|
|
874
|
+
export function getCuteAscii() {
|
|
875
|
+
return randomFromArray(CUTE_ASCII);
|
|
1308
876
|
}
|
|
1309
|
-
function isEmpty(char) {
|
|
877
|
+
export function isEmpty(char) {
|
|
1310
878
|
if (char === " ") {
|
|
1311
879
|
return true;
|
|
1312
880
|
}
|
|
1313
881
|
return false;
|
|
1314
882
|
}
|
|
1315
|
-
function singleSpacesOnly(input, trim = true) {
|
|
883
|
+
export function singleSpacesOnly(input, trim = true) {
|
|
1316
884
|
input = input.replaceAll(/[ ]{2,}/g, " ");
|
|
1317
885
|
if (trim) {
|
|
1318
886
|
input = input.trim();
|
|
1319
887
|
}
|
|
1320
888
|
return input;
|
|
1321
889
|
}
|
|
1322
|
-
function getWeekDayString(date, lang = "en-US") {
|
|
1323
|
-
return date.toLocaleDateString(lang,
|
|
890
|
+
export function getWeekDayString(date, lang = "en-US") {
|
|
891
|
+
return date.toLocaleDateString(lang, VERBOSE_DATE_TIME_FORMAT_OPTIONS);
|
|
1324
892
|
}
|
|
1325
|
-
function getFirstRegexGroupMatchElse(input, regex, defaultValue) {
|
|
893
|
+
export function getFirstRegexGroupMatchElse(input, regex, defaultValue) {
|
|
1326
894
|
const match = input.match(regex);
|
|
1327
895
|
if (match == undefined || match[1] == undefined) {
|
|
1328
896
|
return defaultValue;
|
|
1329
897
|
}
|
|
1330
898
|
return match[1];
|
|
1331
899
|
}
|
|
1332
|
-
function getFirstRegexGroupMatchAsIntElse(input, regex, defaultValue) {
|
|
900
|
+
export function getFirstRegexGroupMatchAsIntElse(input, regex, defaultValue) {
|
|
1333
901
|
const match = input.match(regex);
|
|
1334
902
|
if (match == undefined || match[1] == undefined) {
|
|
1335
903
|
return defaultValue;
|
|
1336
904
|
}
|
|
1337
905
|
return parseInt(match[1]);
|
|
1338
906
|
}
|
|
1339
|
-
function getFirstRegexGroupMatchAsFloatElse(input, regex, defaultValue) {
|
|
907
|
+
export function getFirstRegexGroupMatchAsFloatElse(input, regex, defaultValue) {
|
|
1340
908
|
const match = input.match(regex);
|
|
1341
909
|
if (match == undefined || match[1] == undefined) {
|
|
1342
910
|
return defaultValue;
|
|
1343
911
|
}
|
|
1344
912
|
return parseFloat(match[1]);
|
|
1345
913
|
}
|
|
1346
|
-
function getFirstRegexGroupMatchElseUndefined(input, regex) {
|
|
914
|
+
export function getFirstRegexGroupMatchElseUndefined(input, regex) {
|
|
1347
915
|
const match = input.match(regex);
|
|
1348
916
|
if (match == undefined || match[1] == undefined) {
|
|
1349
917
|
return undefined;
|
|
1350
918
|
}
|
|
1351
919
|
return match[1];
|
|
1352
920
|
}
|
|
1353
|
-
function getFirstRegexGroupMatchAsIntElseUndefined(input, regex) {
|
|
921
|
+
export function getFirstRegexGroupMatchAsIntElseUndefined(input, regex) {
|
|
1354
922
|
const match = input.match(regex);
|
|
1355
923
|
if (match == undefined || match[1] == undefined) {
|
|
1356
924
|
return undefined;
|
|
1357
925
|
}
|
|
1358
926
|
return parseInt(match[1]);
|
|
1359
927
|
}
|
|
1360
|
-
function getFirstRegexGroupMatchAsFloatElseUndefined(input, regex) {
|
|
928
|
+
export function getFirstRegexGroupMatchAsFloatElseUndefined(input, regex) {
|
|
1361
929
|
const match = input.match(regex);
|
|
1362
930
|
if (match == undefined || match[1] == undefined) {
|
|
1363
931
|
return undefined;
|
|
1364
932
|
}
|
|
1365
933
|
return parseFloat(match[1]);
|
|
1366
934
|
}
|
|
1367
|
-
function allRegexesMatched(regexes, toMatchOn) {
|
|
935
|
+
export function allRegexesMatched(regexes, toMatchOn) {
|
|
1368
936
|
for (const regex of regexes) {
|
|
1369
937
|
if (toMatchOn.match(regex) == undefined) {
|
|
1370
938
|
return false;
|
|
@@ -1372,7 +940,7 @@ function allRegexesMatched(regexes, toMatchOn) {
|
|
|
1372
940
|
}
|
|
1373
941
|
return true;
|
|
1374
942
|
}
|
|
1375
|
-
function countOccurrences(stringToCountFrom, stringToCountOccurenceOf) {
|
|
943
|
+
export function countOccurrences(stringToCountFrom, stringToCountOccurenceOf) {
|
|
1376
944
|
let count = 0;
|
|
1377
945
|
let lastIndex = -1;
|
|
1378
946
|
while ((lastIndex = stringToCountFrom.indexOf(stringToCountOccurenceOf, lastIndex + 1)) !== -1) {
|
|
@@ -1380,7 +948,7 @@ function countOccurrences(stringToCountFrom, stringToCountOccurenceOf) {
|
|
|
1380
948
|
}
|
|
1381
949
|
return count;
|
|
1382
950
|
}
|
|
1383
|
-
function occursAtleastTimes(stringToCountFrom, stringToCountOccurenceOf, requiredOccuranceCount) {
|
|
951
|
+
export function occursAtleastTimes(stringToCountFrom, stringToCountOccurenceOf, requiredOccuranceCount) {
|
|
1384
952
|
let count = 0;
|
|
1385
953
|
let lastIndex = -1;
|
|
1386
954
|
while ((lastIndex = stringToCountFrom.indexOf(stringToCountOccurenceOf, lastIndex + 1)) !== -1) {
|
|
@@ -1391,19 +959,19 @@ function occursAtleastTimes(stringToCountFrom, stringToCountOccurenceOf, require
|
|
|
1391
959
|
}
|
|
1392
960
|
return false;
|
|
1393
961
|
}
|
|
1394
|
-
function removeColorCodes(input) {
|
|
1395
|
-
return input.replace(
|
|
962
|
+
export function removeColorCodes(input) {
|
|
963
|
+
return input.replace(COLOR_CODE_REGEX, '');
|
|
1396
964
|
}
|
|
1397
|
-
function replaceAllRegexAsGlobalArray(input, regexes, replaceWith) {
|
|
965
|
+
export function replaceAllRegexAsGlobalArray(input, regexes, replaceWith) {
|
|
1398
966
|
for (const regex of regexes) {
|
|
1399
967
|
input = replaceAllRegexAsGlobal(input, regex, "**$&**");
|
|
1400
968
|
}
|
|
1401
969
|
return input;
|
|
1402
970
|
}
|
|
1403
|
-
function replaceAllRegexAsGlobal(input, regex, replaceWith) {
|
|
971
|
+
export function replaceAllRegexAsGlobal(input, regex, replaceWith) {
|
|
1404
972
|
return input.replaceAll(new RegExp(regex.source, "g"), replaceWith);
|
|
1405
973
|
}
|
|
1406
|
-
function setToJSON(set) {
|
|
974
|
+
export function setToJSON(set) {
|
|
1407
975
|
const array = [];
|
|
1408
976
|
set.forEach((value) => {
|
|
1409
977
|
if (value instanceof Set) {
|
|
@@ -1418,7 +986,7 @@ function setToJSON(set) {
|
|
|
1418
986
|
});
|
|
1419
987
|
return array;
|
|
1420
988
|
}
|
|
1421
|
-
function mapToJSON(map) {
|
|
989
|
+
export function mapToJSON(map) {
|
|
1422
990
|
const obj = {};
|
|
1423
991
|
map.forEach((value, key) => {
|
|
1424
992
|
if (value instanceof Set) {
|
|
@@ -1433,7 +1001,7 @@ function mapToJSON(map) {
|
|
|
1433
1001
|
});
|
|
1434
1002
|
return obj;
|
|
1435
1003
|
}
|
|
1436
|
-
function toJSON(input) {
|
|
1004
|
+
export function toJSON(input) {
|
|
1437
1005
|
if (input instanceof Set) {
|
|
1438
1006
|
return setToJSON(input);
|
|
1439
1007
|
}
|
|
@@ -1444,7 +1012,7 @@ function toJSON(input) {
|
|
|
1444
1012
|
throw new Error('Input must be a Set or Map');
|
|
1445
1013
|
}
|
|
1446
1014
|
}
|
|
1447
|
-
function jsonToSet(jsonArray) {
|
|
1015
|
+
export function jsonToSet(jsonArray) {
|
|
1448
1016
|
const set = new Set();
|
|
1449
1017
|
jsonArray.forEach((item) => {
|
|
1450
1018
|
if (Array.isArray(item)) {
|
|
@@ -1459,7 +1027,7 @@ function jsonToSet(jsonArray) {
|
|
|
1459
1027
|
});
|
|
1460
1028
|
return set;
|
|
1461
1029
|
}
|
|
1462
|
-
function jsonToMap(jsonObject) {
|
|
1030
|
+
export function jsonToMap(jsonObject) {
|
|
1463
1031
|
const map = new Map();
|
|
1464
1032
|
Object.keys(jsonObject).forEach((key) => {
|
|
1465
1033
|
const value = jsonObject[key];
|
|
@@ -1475,7 +1043,7 @@ function jsonToMap(jsonObject) {
|
|
|
1475
1043
|
});
|
|
1476
1044
|
return map;
|
|
1477
1045
|
}
|
|
1478
|
-
function fromJSON(json) {
|
|
1046
|
+
export function fromJSON(json) {
|
|
1479
1047
|
if (Array.isArray(json)) {
|
|
1480
1048
|
return jsonToSet(json);
|
|
1481
1049
|
}
|
|
@@ -1486,15 +1054,15 @@ function fromJSON(json) {
|
|
|
1486
1054
|
throw new Error('JSON must be an array or object');
|
|
1487
1055
|
}
|
|
1488
1056
|
}
|
|
1489
|
-
function htmlAsCheerio(html) {
|
|
1057
|
+
export function htmlAsCheerio(html) {
|
|
1490
1058
|
return cheerio.load(html);
|
|
1491
1059
|
}
|
|
1492
|
-
async function getPageCheerio(url, options =
|
|
1060
|
+
export async function getPageCheerio(url, options = DEFAULT_HTTPS_CONNECTION_OPTIONS) {
|
|
1493
1061
|
return htmlAsCheerio(await getPageHtml(url, options));
|
|
1494
1062
|
}
|
|
1495
|
-
async function getPageHtml(url, options =
|
|
1063
|
+
export async function getPageHtml(url, options = DEFAULT_HTTPS_CONNECTION_OPTIONS) {
|
|
1496
1064
|
return new Promise((resolve, reject) => {
|
|
1497
|
-
|
|
1065
|
+
get(url, options, (response) => {
|
|
1498
1066
|
let data = '';
|
|
1499
1067
|
response.on('data', (chunk) => {
|
|
1500
1068
|
data += chunk;
|
|
@@ -1508,17 +1076,17 @@ async function getPageHtml(url, options = fields_1.DEFAULT_HTTPS_CONNECTION_OPTI
|
|
|
1508
1076
|
});
|
|
1509
1077
|
});
|
|
1510
1078
|
}
|
|
1511
|
-
function humanReadableJsonToHumanReadableNextLineBracketsJson(json) {
|
|
1512
|
-
return json.replaceAll(
|
|
1079
|
+
export function humanReadableJsonToHumanReadableNextLineBracketsJson(json) {
|
|
1080
|
+
return json.replaceAll(JSON_NEXT_LINE_BRACKET_FROM_REGEX, JSON_NEXT_LINE_BRACKET_TO);
|
|
1513
1081
|
}
|
|
1514
1082
|
/**
|
|
1515
1083
|
* @returns Stringified JSON version of the object in Human Readable, Next Line Bracket string.
|
|
1516
1084
|
*/
|
|
1517
|
-
function toJson(obj) {
|
|
1085
|
+
export function toJson(obj) {
|
|
1518
1086
|
return humanReadableJsonToHumanReadableNextLineBracketsJson(JSON.stringify(obj, null, "\t"));
|
|
1519
1087
|
}
|
|
1520
|
-
function charToRegexOrHomoglyphs(char) {
|
|
1521
|
-
const homoglyphRegexpOr =
|
|
1088
|
+
export function charToRegexOrHomoglyphs(char) {
|
|
1089
|
+
const homoglyphRegexpOr = HOMOGLYPHS_AS_REGEXP_OR[char];
|
|
1522
1090
|
if (homoglyphRegexpOr == undefined) {
|
|
1523
1091
|
return char;
|
|
1524
1092
|
}
|
|
@@ -1526,7 +1094,7 @@ function charToRegexOrHomoglyphs(char) {
|
|
|
1526
1094
|
return homoglyphRegexpOr;
|
|
1527
1095
|
}
|
|
1528
1096
|
}
|
|
1529
|
-
function stringToRegexOrHomoglyphs(text, suffix = "+") {
|
|
1097
|
+
export function stringToRegexOrHomoglyphs(text, suffix = "+") {
|
|
1530
1098
|
let output = "";
|
|
1531
1099
|
let lastChar = "";
|
|
1532
1100
|
const groupChars = suffix == "+" || suffix == "*";
|
|
@@ -1552,36 +1120,36 @@ function stringToRegexOrHomoglyphs(text, suffix = "+") {
|
|
|
1552
1120
|
}
|
|
1553
1121
|
return output;
|
|
1554
1122
|
}
|
|
1555
|
-
function toInsanelyAccurateRegex(regex, flags = "i") {
|
|
1123
|
+
export function toInsanelyAccurateRegex(regex, flags = "i") {
|
|
1556
1124
|
return new RegExp(stringToRegexOrHomoglyphs(regex, "+"));
|
|
1557
1125
|
}
|
|
1558
|
-
function noop() { }
|
|
1559
|
-
function noop1(arg1) { }
|
|
1560
|
-
function noop2(arg1, arg2) { }
|
|
1561
|
-
function noop3(arg1, arg2, arg3) { }
|
|
1562
|
-
function forEachKeyValue(obj, consumer) {
|
|
1126
|
+
export function noop() { }
|
|
1127
|
+
export function noop1(arg1) { }
|
|
1128
|
+
export function noop2(arg1, arg2) { }
|
|
1129
|
+
export function noop3(arg1, arg2, arg3) { }
|
|
1130
|
+
export function forEachKeyValue(obj, consumer) {
|
|
1563
1131
|
for (const key of Object.keys(obj)) {
|
|
1564
1132
|
consumer(obj[key], key);
|
|
1565
1133
|
}
|
|
1566
1134
|
}
|
|
1567
|
-
function keyValueToOdt(obj) {
|
|
1135
|
+
export function keyValueToOdt(obj) {
|
|
1568
1136
|
let output = "";
|
|
1569
1137
|
forEachKeyValue(obj, (value, key) => {
|
|
1570
1138
|
output += `${key}\t${value}\n`;
|
|
1571
1139
|
});
|
|
1572
1140
|
return output;
|
|
1573
1141
|
}
|
|
1574
|
-
function orElse(item, orElse) {
|
|
1142
|
+
export function orElse(item, orElse) {
|
|
1575
1143
|
if (item == null) {
|
|
1576
1144
|
return orElse();
|
|
1577
1145
|
}
|
|
1578
1146
|
return item;
|
|
1579
1147
|
}
|
|
1580
|
-
function getClosestValue(map, input) {
|
|
1148
|
+
export function getClosestValue(map, input) {
|
|
1581
1149
|
const closestKey = getClosestNumber(input, Array.from(map.keys()).sort());
|
|
1582
1150
|
return map.get(closestKey);
|
|
1583
1151
|
}
|
|
1584
|
-
function getClosestNumber(input, options) {
|
|
1152
|
+
export function getClosestNumber(input, options) {
|
|
1585
1153
|
if (options.length <= 0) {
|
|
1586
1154
|
return input;
|
|
1587
1155
|
}
|
|
@@ -1762,7 +1330,7 @@ const TO_WEEK_CONVERSION_TYPES = [
|
|
|
1762
1330
|
"w_to_w",
|
|
1763
1331
|
];
|
|
1764
1332
|
//!~~~~~To~~~~~
|
|
1765
|
-
function convertTime(input, type) {
|
|
1333
|
+
export function convertTime(input, type) {
|
|
1766
1334
|
switch (type) {
|
|
1767
1335
|
case "ns_to_s":
|
|
1768
1336
|
return nanosecondsToSeconds(input);
|
|
@@ -1850,64 +1418,62 @@ function convertTime(input, type) {
|
|
|
1850
1418
|
return weeksToDays(input);
|
|
1851
1419
|
}
|
|
1852
1420
|
}
|
|
1853
|
-
|
|
1854
|
-
const getZero = () => 0;
|
|
1855
|
-
|
|
1856
|
-
const getZeroBigInt = () => exports.ZERO_BIG_INT;
|
|
1857
|
-
exports.getZeroBigInt = getZeroBigInt;
|
|
1421
|
+
export const ZERO_BIG_INT = BigInt(0);
|
|
1422
|
+
export const getZero = () => 0;
|
|
1423
|
+
export const getZeroBigInt = () => ZERO_BIG_INT;
|
|
1858
1424
|
const timeTrackers = new Map();
|
|
1859
|
-
function getNs() {
|
|
1425
|
+
export function getNs() {
|
|
1860
1426
|
return process.hrtime.bigint();
|
|
1861
1427
|
}
|
|
1862
|
-
function startTimer(key) {
|
|
1428
|
+
export function startTimer(key) {
|
|
1863
1429
|
timeTrackers.set(key, getNs());
|
|
1864
1430
|
}
|
|
1865
|
-
function getTimer(key) {
|
|
1866
|
-
return orElse(timeTrackers.get(key),
|
|
1431
|
+
export function getTimer(key) {
|
|
1432
|
+
return orElse(timeTrackers.get(key), getZeroBigInt);
|
|
1867
1433
|
}
|
|
1868
|
-
function getTimerString(key, format = "ns_to_s") {
|
|
1434
|
+
export function getTimerString(key, format = "ns_to_s") {
|
|
1869
1435
|
return `${key}: ${convertTime(Number(getTimer(key)), format)}`;
|
|
1870
1436
|
}
|
|
1871
|
-
function printTimer(key, format = "ns_to_s") {
|
|
1437
|
+
export function printTimer(key, format = "ns_to_s") {
|
|
1872
1438
|
console.log(getTimerString(key, format));
|
|
1873
1439
|
}
|
|
1874
|
-
function isString(input) {
|
|
1440
|
+
export function isString(input) {
|
|
1875
1441
|
return typeof input === 'string' || input instanceof String;
|
|
1876
1442
|
}
|
|
1877
|
-
function reverseString(str) {
|
|
1443
|
+
export function reverseString(str) {
|
|
1878
1444
|
return str.split('').reverse().join('');
|
|
1879
1445
|
}
|
|
1880
|
-
function wipeAllLetters(input) {
|
|
1881
|
-
return input.replaceAll(
|
|
1446
|
+
export function wipeAllLetters(input) {
|
|
1447
|
+
return input.replaceAll(UNICODE_LETTERS_REGEX, "");
|
|
1882
1448
|
}
|
|
1883
|
-
function keepOnlyAllLetters(input) {
|
|
1884
|
-
return input.replaceAll(
|
|
1449
|
+
export function keepOnlyAllLetters(input) {
|
|
1450
|
+
return input.replaceAll(NOT_UNICODE_LETTERS_REGEX, "");
|
|
1885
1451
|
}
|
|
1886
|
-
function wipeNumbers(input) {
|
|
1887
|
-
return input.replaceAll(
|
|
1452
|
+
export function wipeNumbers(input) {
|
|
1453
|
+
return input.replaceAll(NUMBER_REGEX, "");
|
|
1888
1454
|
}
|
|
1889
|
-
function keepOnlyNumbers(input) {
|
|
1890
|
-
return input.replaceAll(
|
|
1455
|
+
export function keepOnlyNumbers(input) {
|
|
1456
|
+
return input.replaceAll(NON_NUMBER_REGEX, "");
|
|
1891
1457
|
}
|
|
1892
|
-
function wipeAllLettersAndNumbers(input) {
|
|
1458
|
+
export function wipeAllLettersAndNumbers(input) {
|
|
1893
1459
|
return wipeAllLetters(wipeNumbers(input));
|
|
1894
1460
|
}
|
|
1895
|
-
function keepOnlyAllLettersAndNumbers(input) {
|
|
1461
|
+
export function keepOnlyAllLettersAndNumbers(input) {
|
|
1896
1462
|
return keepOnlyAllLetters(keepOnlyNumbers(input));
|
|
1897
1463
|
}
|
|
1898
|
-
function fromArrayOrNull(array, index) {
|
|
1464
|
+
export function fromArrayOrNull(array, index) {
|
|
1899
1465
|
if (index >= 0 && index < array.length) {
|
|
1900
1466
|
return array[index];
|
|
1901
1467
|
}
|
|
1902
1468
|
return null;
|
|
1903
1469
|
}
|
|
1904
|
-
function setClipboard(text) {
|
|
1470
|
+
export function setClipboard(text) {
|
|
1905
1471
|
ncp.writeSync(text);
|
|
1906
1472
|
}
|
|
1907
|
-
function readClipboard() {
|
|
1473
|
+
export function readClipboard() {
|
|
1908
1474
|
return ncp.readSync();
|
|
1909
1475
|
}
|
|
1910
|
-
function toDDMMYYYY(date = null) {
|
|
1476
|
+
export function toDDMMYYYY(date = null) {
|
|
1911
1477
|
if (date == null) {
|
|
1912
1478
|
date = new Date();
|
|
1913
1479
|
}
|
|
@@ -1916,7 +1482,7 @@ function toDDMMYYYY(date = null) {
|
|
|
1916
1482
|
const year = date.getFullYear().toString();
|
|
1917
1483
|
return `${day}-${month}-${year}`;
|
|
1918
1484
|
}
|
|
1919
|
-
function toMMDDYYYY(date = null) {
|
|
1485
|
+
export function toMMDDYYYY(date = null) {
|
|
1920
1486
|
if (date == null) {
|
|
1921
1487
|
date = new Date();
|
|
1922
1488
|
}
|
|
@@ -1925,23 +1491,23 @@ function toMMDDYYYY(date = null) {
|
|
|
1925
1491
|
const year = date.getFullYear().toString();
|
|
1926
1492
|
return `${month}-${day}-${year}`;
|
|
1927
1493
|
}
|
|
1928
|
-
async function downloadItem(url, destination) {
|
|
1494
|
+
export async function downloadItem(url, destination) {
|
|
1929
1495
|
const tempDestination = `${destination}_TEMP`;
|
|
1930
|
-
if (
|
|
1931
|
-
|
|
1496
|
+
if (existsSync(tempDestination)) {
|
|
1497
|
+
unlinkSync(tempDestination);
|
|
1932
1498
|
}
|
|
1933
1499
|
return new Promise(resolve => {
|
|
1934
|
-
const file =
|
|
1935
|
-
|
|
1500
|
+
const file = createWriteStream(tempDestination);
|
|
1501
|
+
get(url, (response) => {
|
|
1936
1502
|
response.pipe(file);
|
|
1937
1503
|
file.on('finish', () => {
|
|
1938
1504
|
file.close();
|
|
1939
|
-
if (
|
|
1940
|
-
|
|
1505
|
+
if (existsSync(destination)) {
|
|
1506
|
+
unlinkSync(destination);
|
|
1941
1507
|
}
|
|
1942
|
-
if (
|
|
1943
|
-
|
|
1944
|
-
const stat =
|
|
1508
|
+
if (existsSync(tempDestination)) {
|
|
1509
|
+
renameSync(tempDestination, destination);
|
|
1510
|
+
const stat = statSync(destination);
|
|
1945
1511
|
if (stat.size <= 0) {
|
|
1946
1512
|
console.log(`low size: ${stat.size}`);
|
|
1947
1513
|
resolve(false);
|
|
@@ -1955,25 +1521,25 @@ async function downloadItem(url, destination) {
|
|
|
1955
1521
|
});
|
|
1956
1522
|
}).on('error', (err) => {
|
|
1957
1523
|
console.log(`Failed download ${destination}`);
|
|
1958
|
-
if (
|
|
1959
|
-
|
|
1524
|
+
if (existsSync(tempDestination)) {
|
|
1525
|
+
unlinkSync(tempDestination);
|
|
1960
1526
|
}
|
|
1961
1527
|
resolve(false);
|
|
1962
1528
|
});
|
|
1963
1529
|
});
|
|
1964
1530
|
}
|
|
1965
|
-
function getChild(element, childIndex = 0) {
|
|
1531
|
+
export function getChild(element, childIndex = 0) {
|
|
1966
1532
|
if (element.children.length <= childIndex) {
|
|
1967
1533
|
return element.children[element.children.length - 1];
|
|
1968
1534
|
}
|
|
1969
1535
|
return element.children[childIndex];
|
|
1970
1536
|
}
|
|
1971
|
-
async function getDynamicContentCheerio(url, options) {
|
|
1537
|
+
export async function getDynamicContentCheerio(url, options) {
|
|
1972
1538
|
const html = await getDynamicContent(url, options);
|
|
1973
1539
|
return cheerio.load(html);
|
|
1974
1540
|
}
|
|
1975
|
-
async function getDynamicContent(url, options) {
|
|
1976
|
-
const browser = await
|
|
1541
|
+
export async function getDynamicContent(url, options) {
|
|
1542
|
+
const browser = await puppeteer.launch();
|
|
1977
1543
|
const page = await browser.newPage();
|
|
1978
1544
|
try {
|
|
1979
1545
|
await page.goto(url, options);
|
|
@@ -1988,39 +1554,39 @@ async function getDynamicContent(url, options) {
|
|
|
1988
1554
|
await browser.close();
|
|
1989
1555
|
}
|
|
1990
1556
|
}
|
|
1991
|
-
async function randomTimeout(minMs = 1523, maxMs = 3251) {
|
|
1557
|
+
export async function randomTimeout(minMs = 1523, maxMs = 3251) {
|
|
1992
1558
|
return await new Promise(resolve => setTimeout(resolve, random(minMs, maxMs)));
|
|
1993
1559
|
}
|
|
1994
|
-
async function randomTimeoutVerbose(minMs, maxMs, timeoutGapMs = 1523) {
|
|
1560
|
+
export async function randomTimeoutVerbose(minMs, maxMs, timeoutGapMs = 1523) {
|
|
1995
1561
|
const waitingForMs = random(minMs, maxMs);
|
|
1996
1562
|
let waitedFor = 0;
|
|
1997
1563
|
let waitFor = clamp(waitingForMs - waitedFor, 0, timeoutGapMs);
|
|
1998
1564
|
while (waitedFor < waitingForMs) {
|
|
1999
|
-
console.log(`Waiting for ${
|
|
1565
|
+
console.log(`Waiting for ${chalk.magentaBright(waitingForMs - waitedFor) + "ms"}...`);
|
|
2000
1566
|
await new Promise(resolve => setTimeout(resolve, waitFor));
|
|
2001
1567
|
waitedFor += timeoutGapMs;
|
|
2002
1568
|
waitFor = clamp(waitingForMs - waitedFor, 0, timeoutGapMs);
|
|
2003
1569
|
}
|
|
2004
1570
|
return await new Promise(resolve => setTimeout(resolve, waitFor));
|
|
2005
1571
|
}
|
|
2006
|
-
function getLast(items) {
|
|
1572
|
+
export function getLast(items) {
|
|
2007
1573
|
if (items.length <= 0) {
|
|
2008
1574
|
return undefined;
|
|
2009
1575
|
}
|
|
2010
1576
|
return items[items.length - 1];
|
|
2011
1577
|
}
|
|
2012
|
-
function getLastX(items, lastCount) {
|
|
1578
|
+
export function getLastX(items, lastCount) {
|
|
2013
1579
|
const startIndex = Math.max(0, items.length - lastCount);
|
|
2014
1580
|
return items.slice(startIndex);
|
|
2015
1581
|
}
|
|
2016
|
-
function forLastX(items, lastCount, consumer) {
|
|
1582
|
+
export function forLastX(items, lastCount, consumer) {
|
|
2017
1583
|
const itemsLength = items.length;
|
|
2018
1584
|
const startIndex = Math.max(0, itemsLength - lastCount);
|
|
2019
1585
|
for (let i = startIndex; i < itemsLength; ++i) {
|
|
2020
1586
|
consumer(items[i]);
|
|
2021
1587
|
}
|
|
2022
1588
|
}
|
|
2023
|
-
function joinToXCounts(items, maxCount, joinWith = "\n") {
|
|
1589
|
+
export function joinToXCounts(items, maxCount, joinWith = "\n") {
|
|
2024
1590
|
const output = [];
|
|
2025
1591
|
let msg = "";
|
|
2026
1592
|
let count = 0;
|
|
@@ -2037,17 +1603,17 @@ function joinToXCounts(items, maxCount, joinWith = "\n") {
|
|
|
2037
1603
|
}
|
|
2038
1604
|
return output;
|
|
2039
1605
|
}
|
|
2040
|
-
async function asyncMap(items, mapper) {
|
|
1606
|
+
export async function asyncMap(items, mapper) {
|
|
2041
1607
|
const output = [];
|
|
2042
1608
|
for (const item of items) {
|
|
2043
1609
|
output.push(await mapper(item));
|
|
2044
1610
|
}
|
|
2045
1611
|
return output;
|
|
2046
1612
|
}
|
|
2047
|
-
function emptyIfEmpty(text) {
|
|
2048
|
-
return text.trim().length == 0 ?
|
|
1613
|
+
export function emptyIfEmpty(text) {
|
|
1614
|
+
return text.trim().length == 0 ? EMPTY : text.trim();
|
|
2049
1615
|
}
|
|
2050
|
-
function getRandomWeighedItem(map, total = getWeightOfValues(map)) {
|
|
1616
|
+
export function getRandomWeighedItem(map, total = getWeightOfValues(map)) {
|
|
2051
1617
|
let rand = Math.random() * total;
|
|
2052
1618
|
let item = null;
|
|
2053
1619
|
for (const [key, value] of map.entries()) {
|
|
@@ -2059,42 +1625,42 @@ function getRandomWeighedItem(map, total = getWeightOfValues(map)) {
|
|
|
2059
1625
|
}
|
|
2060
1626
|
return item;
|
|
2061
1627
|
}
|
|
2062
|
-
function getWeightOfKeys(map) {
|
|
1628
|
+
export function getWeightOfKeys(map) {
|
|
2063
1629
|
return getSum(map.keys());
|
|
2064
1630
|
}
|
|
2065
|
-
function getWeightOfValues(map) {
|
|
1631
|
+
export function getWeightOfValues(map) {
|
|
2066
1632
|
return getSum(map.values());
|
|
2067
1633
|
}
|
|
2068
|
-
function getSum(numbers) {
|
|
1634
|
+
export function getSum(numbers) {
|
|
2069
1635
|
let sum = 0;
|
|
2070
1636
|
for (const number of numbers) {
|
|
2071
1637
|
sum += number;
|
|
2072
1638
|
}
|
|
2073
1639
|
return sum;
|
|
2074
1640
|
}
|
|
2075
|
-
function getCurrentMs() {
|
|
1641
|
+
export function getCurrentMs() {
|
|
2076
1642
|
return Date.now();
|
|
2077
1643
|
}
|
|
2078
|
-
function getCurrentSecond() {
|
|
1644
|
+
export function getCurrentSecond() {
|
|
2079
1645
|
return millisecondsToSeconds(getCurrentMs());
|
|
2080
1646
|
}
|
|
2081
|
-
function getCurrentMinute() {
|
|
1647
|
+
export function getCurrentMinute() {
|
|
2082
1648
|
return millisecondsToMinutes(getCurrentMs());
|
|
2083
1649
|
}
|
|
2084
|
-
function getCurrentHour() {
|
|
1650
|
+
export function getCurrentHour() {
|
|
2085
1651
|
return millisecondsToHours(getCurrentMs());
|
|
2086
1652
|
}
|
|
2087
|
-
function getCurrentDay() {
|
|
1653
|
+
export function getCurrentDay() {
|
|
2088
1654
|
return millisecondsToDays(getCurrentMs());
|
|
2089
1655
|
}
|
|
2090
|
-
function reverseMap(map) {
|
|
1656
|
+
export function reverseMap(map) {
|
|
2091
1657
|
const reversedMap = new Map();
|
|
2092
1658
|
for (const [key, value] of map.entries()) {
|
|
2093
1659
|
reversedMap.set(value, key);
|
|
2094
1660
|
}
|
|
2095
1661
|
return reversedMap;
|
|
2096
1662
|
}
|
|
2097
|
-
function toArray(iterator) {
|
|
1663
|
+
export function toArray(iterator) {
|
|
2098
1664
|
const array = [];
|
|
2099
1665
|
let result = iterator.next();
|
|
2100
1666
|
while (!result.done) {
|
|
@@ -2103,13 +1669,13 @@ function toArray(iterator) {
|
|
|
2103
1669
|
}
|
|
2104
1670
|
return array;
|
|
2105
1671
|
}
|
|
2106
|
-
function sortDateOldestFirst(a, b) {
|
|
1672
|
+
export function sortDateOldestFirst(a, b) {
|
|
2107
1673
|
return a.getTime() - b.getTime();
|
|
2108
1674
|
}
|
|
2109
|
-
function sortDateNewestFirst(a, b) {
|
|
1675
|
+
export function sortDateNewestFirst(a, b) {
|
|
2110
1676
|
return b.getTime() - a.getTime();
|
|
2111
1677
|
}
|
|
2112
|
-
function dateValuesMapToSortedKeysArray(map, newestFirst) {
|
|
1678
|
+
export function dateValuesMapToSortedKeysArray(map, newestFirst) {
|
|
2113
1679
|
const sortedKeys = [];
|
|
2114
1680
|
const reversedMap = reverseMap(map);
|
|
2115
1681
|
const sortedDates = toArray(map.values());
|
|
@@ -2119,31 +1685,31 @@ function dateValuesMapToSortedKeysArray(map, newestFirst) {
|
|
|
2119
1685
|
}
|
|
2120
1686
|
return sortedKeys;
|
|
2121
1687
|
}
|
|
2122
|
-
function getCount(iterable) {
|
|
1688
|
+
export function getCount(iterable) {
|
|
2123
1689
|
let count = 0;
|
|
2124
1690
|
for (const item of iterable) {
|
|
2125
1691
|
++count;
|
|
2126
1692
|
}
|
|
2127
1693
|
return count;
|
|
2128
1694
|
}
|
|
2129
|
-
function sumStringNumberObj(obj) {
|
|
1695
|
+
export function sumStringNumberObj(obj) {
|
|
2130
1696
|
let sum = 0;
|
|
2131
1697
|
for (const [key, value] of Object.entries(obj)) {
|
|
2132
1698
|
sum += value;
|
|
2133
1699
|
}
|
|
2134
1700
|
return sum;
|
|
2135
1701
|
}
|
|
2136
|
-
function splitWords(input) {
|
|
1702
|
+
export function splitWords(input) {
|
|
2137
1703
|
return input.split(/[ \r\n]/).filter(word => word.length > 0);
|
|
2138
1704
|
}
|
|
2139
|
-
function filterMap(map, filter) {
|
|
1705
|
+
export function filterMap(map, filter) {
|
|
2140
1706
|
for (const [key, value] of map.entries()) {
|
|
2141
1707
|
if (!filter(key, value)) {
|
|
2142
1708
|
map.delete(key);
|
|
2143
1709
|
}
|
|
2144
1710
|
}
|
|
2145
1711
|
}
|
|
2146
|
-
function filterMapCopy(map, filter) {
|
|
1712
|
+
export function filterMapCopy(map, filter) {
|
|
2147
1713
|
const newMap = new Map();
|
|
2148
1714
|
for (const [key, value] of map.entries()) {
|
|
2149
1715
|
if (filter(key, value)) {
|
|
@@ -2152,14 +1718,14 @@ function filterMapCopy(map, filter) {
|
|
|
2152
1718
|
}
|
|
2153
1719
|
return newMap;
|
|
2154
1720
|
}
|
|
2155
|
-
function filterSet(set, filter) {
|
|
1721
|
+
export function filterSet(set, filter) {
|
|
2156
1722
|
for (const item of set) {
|
|
2157
1723
|
if (!filter(item)) {
|
|
2158
1724
|
set.delete(item);
|
|
2159
1725
|
}
|
|
2160
1726
|
}
|
|
2161
1727
|
}
|
|
2162
|
-
function filterSetCopy(set, filter) {
|
|
1728
|
+
export function filterSetCopy(set, filter) {
|
|
2163
1729
|
const newSet = new Set();
|
|
2164
1730
|
for (const item of set) {
|
|
2165
1731
|
if (!filter(item)) {
|
|
@@ -2168,7 +1734,7 @@ function filterSetCopy(set, filter) {
|
|
|
2168
1734
|
}
|
|
2169
1735
|
return newSet;
|
|
2170
1736
|
}
|
|
2171
|
-
async function prismaDeleteIfExists(db, where) {
|
|
1737
|
+
export async function prismaDeleteIfExists(db, where) {
|
|
2172
1738
|
const item = await db.findFirst({ where });
|
|
2173
1739
|
if (item == null) {
|
|
2174
1740
|
return false;
|
|
@@ -2176,18 +1742,18 @@ async function prismaDeleteIfExists(db, where) {
|
|
|
2176
1742
|
await db.delete({ where });
|
|
2177
1743
|
return true;
|
|
2178
1744
|
}
|
|
2179
|
-
function getWeekSince1980() {
|
|
1745
|
+
export function getWeekSince1980() {
|
|
2180
1746
|
return Math.floor(millisecondsToWeeks(Date.now()));
|
|
2181
1747
|
}
|
|
2182
|
-
function getDaySince1980() {
|
|
1748
|
+
export function getDaySince1980() {
|
|
2183
1749
|
return Math.floor(millisecondsToDays(Date.now()));
|
|
2184
1750
|
}
|
|
2185
|
-
async function runCommand(command, as_user, options) {
|
|
1751
|
+
export async function runCommand(command, as_user, options) {
|
|
2186
1752
|
return new Promise((resolve, reject) => {
|
|
2187
1753
|
if (as_user != null) {
|
|
2188
1754
|
command = `sudo -u ${as_user} sh -c '${command}'`;
|
|
2189
1755
|
}
|
|
2190
|
-
|
|
1756
|
+
exec(command, options, (error, stdout, stderr) => {
|
|
2191
1757
|
if (error) {
|
|
2192
1758
|
reject(stderr || error.message || error);
|
|
2193
1759
|
}
|
|
@@ -2197,7 +1763,7 @@ async function runCommand(command, as_user, options) {
|
|
|
2197
1763
|
});
|
|
2198
1764
|
});
|
|
2199
1765
|
}
|
|
2200
|
-
async function runCommandRejectAsResolve(command, as_user, options) {
|
|
1766
|
+
export async function runCommandRejectAsResolve(command, as_user, options) {
|
|
2201
1767
|
try {
|
|
2202
1768
|
return await runCommand(command, as_user, options);
|
|
2203
1769
|
}
|
|
@@ -2205,10 +1771,10 @@ async function runCommandRejectAsResolve(command, as_user, options) {
|
|
|
2205
1771
|
return String(error);
|
|
2206
1772
|
}
|
|
2207
1773
|
}
|
|
2208
|
-
function sanitizeStringForFFMPEG(input) {
|
|
1774
|
+
export function sanitizeStringForFFMPEG(input) {
|
|
2209
1775
|
return input.replaceAll(/([$!"`])/g, "\\$1");
|
|
2210
1776
|
}
|
|
2211
|
-
function getArtistsFromFlacMetadata(tags, aliases =
|
|
1777
|
+
export function getArtistsFromFlacMetadata(tags, aliases = MUSIC_ARTIST_ALIASES) {
|
|
2212
1778
|
const artists = new Set;
|
|
2213
1779
|
if (tags.common != null) {
|
|
2214
1780
|
if (tags.common.artists != null) {
|
|
@@ -2236,34 +1802,31 @@ function getArtistsFromFlacMetadata(tags, aliases = classes_1.MUSIC_ARTIST_ALIAS
|
|
|
2236
1802
|
}
|
|
2237
1803
|
return artists;
|
|
2238
1804
|
}
|
|
2239
|
-
function getTitleFromFlacMetadata(tags) {
|
|
2240
|
-
|
|
2241
|
-
return (_a = tags.common.title) !== null && _a !== void 0 ? _a : "";
|
|
1805
|
+
export function getTitleFromFlacMetadata(tags) {
|
|
1806
|
+
return tags.common.title ?? "";
|
|
2242
1807
|
}
|
|
2243
|
-
function getAlbumFromFlacMetadata(tags) {
|
|
2244
|
-
|
|
2245
|
-
return (_a = tags.common.album) !== null && _a !== void 0 ? _a : "";
|
|
1808
|
+
export function getAlbumFromFlacMetadata(tags) {
|
|
1809
|
+
return tags.common.album ?? "";
|
|
2246
1810
|
}
|
|
2247
|
-
function getAlbumArtistFromFlacMetadata(tags) {
|
|
2248
|
-
|
|
2249
|
-
return (_a = tags.common.albumartist) !== null && _a !== void 0 ? _a : "";
|
|
1811
|
+
export function getAlbumArtistFromFlacMetadata(tags) {
|
|
1812
|
+
return tags.common.albumartist ?? "";
|
|
2250
1813
|
}
|
|
2251
|
-
function getLyricsFromFlacVorbisTags(vorbisTags) {
|
|
2252
|
-
let lyrics = vorbisTags[
|
|
1814
|
+
export function getLyricsFromFlacVorbisTags(vorbisTags) {
|
|
1815
|
+
let lyrics = vorbisTags[UNSYNCEDLYRICS_FLAC_ID];
|
|
2253
1816
|
if (lyrics == null) {
|
|
2254
1817
|
return "";
|
|
2255
1818
|
}
|
|
2256
1819
|
return lyrics.trim();
|
|
2257
1820
|
}
|
|
2258
|
-
function generateHash(seed) {
|
|
2259
|
-
const hash =
|
|
1821
|
+
export function generateHash(seed) {
|
|
1822
|
+
const hash = createHash('sha256');
|
|
2260
1823
|
hash.update(seed);
|
|
2261
1824
|
return hash.digest('hex');
|
|
2262
1825
|
}
|
|
2263
|
-
function extensionHasAudio(extension) {
|
|
2264
|
-
return
|
|
1826
|
+
export function extensionHasAudio(extension) {
|
|
1827
|
+
return AUDIO_CONTAINING_EXTENSION_TYPES.has(extension);
|
|
2265
1828
|
}
|
|
2266
|
-
function songTitleExtractSide(input, doSides, side) {
|
|
1829
|
+
export function songTitleExtractSide(input, doSides, side) {
|
|
2267
1830
|
let output = input;
|
|
2268
1831
|
if (doSides) {
|
|
2269
1832
|
const indexOfDash = output.lastIndexOf(" - ");
|
|
@@ -2282,12 +1845,12 @@ function songTitleExtractSide(input, doSides, side) {
|
|
|
2282
1845
|
output = output.trim();
|
|
2283
1846
|
return output;
|
|
2284
1847
|
}
|
|
2285
|
-
function sanitizeStringForSeed(input) {
|
|
1848
|
+
export function sanitizeStringForSeed(input) {
|
|
2286
1849
|
let output = input.toLowerCase();
|
|
2287
|
-
for (const [name, regex] of
|
|
1850
|
+
for (const [name, regex] of BEFORE_SIDES_SANITIZE_REGEXES) {
|
|
2288
1851
|
output = output.replaceAll(regex, "");
|
|
2289
1852
|
}
|
|
2290
|
-
for (const [name, regex] of
|
|
1853
|
+
for (const [name, regex] of AFTER_SIDES_SANITIZE_REGEXES) {
|
|
2291
1854
|
output = output.replaceAll(regex, "");
|
|
2292
1855
|
}
|
|
2293
1856
|
while (output.includes(" ")) {
|
|
@@ -2296,52 +1859,52 @@ function sanitizeStringForSeed(input) {
|
|
|
2296
1859
|
output = output.trim();
|
|
2297
1860
|
return output;
|
|
2298
1861
|
}
|
|
2299
|
-
function addAllSetToSet(input, outputSet) {
|
|
1862
|
+
export function addAllSetToSet(input, outputSet) {
|
|
2300
1863
|
for (const item of input) {
|
|
2301
1864
|
outputSet.add(item);
|
|
2302
1865
|
}
|
|
2303
1866
|
return outputSet;
|
|
2304
1867
|
}
|
|
2305
|
-
function addAllArrayToSet(input, outputSet) {
|
|
1868
|
+
export function addAllArrayToSet(input, outputSet) {
|
|
2306
1869
|
for (const item of input) {
|
|
2307
1870
|
outputSet.add(item);
|
|
2308
1871
|
}
|
|
2309
1872
|
return outputSet;
|
|
2310
1873
|
}
|
|
2311
|
-
function addAllSetToArray(input, outputArray) {
|
|
1874
|
+
export function addAllSetToArray(input, outputArray) {
|
|
2312
1875
|
for (const item of input) {
|
|
2313
1876
|
outputArray.push(item);
|
|
2314
1877
|
}
|
|
2315
1878
|
return outputArray;
|
|
2316
1879
|
}
|
|
2317
|
-
function addAllArrayToArray(input, outputArray) {
|
|
1880
|
+
export function addAllArrayToArray(input, outputArray) {
|
|
2318
1881
|
for (const item of input) {
|
|
2319
1882
|
outputArray.push(item);
|
|
2320
1883
|
}
|
|
2321
1884
|
return outputArray;
|
|
2322
1885
|
}
|
|
2323
|
-
function addAllArrayToMap(items, map, keyGetter) {
|
|
1886
|
+
export function addAllArrayToMap(items, map, keyGetter) {
|
|
2324
1887
|
for (const item of items) {
|
|
2325
1888
|
map.set(keyGetter(item), item);
|
|
2326
1889
|
}
|
|
2327
1890
|
}
|
|
2328
|
-
function addSetArrayToMap(items, map, keyGetter) {
|
|
1891
|
+
export function addSetArrayToMap(items, map, keyGetter) {
|
|
2329
1892
|
for (const item of items) {
|
|
2330
1893
|
map.set(keyGetter(item), item);
|
|
2331
1894
|
}
|
|
2332
1895
|
}
|
|
2333
|
-
function replaceAllArray(input, replaceInputs, replaceWith) {
|
|
1896
|
+
export function replaceAllArray(input, replaceInputs, replaceWith) {
|
|
2334
1897
|
let output = input;
|
|
2335
1898
|
for (const replaceInput of replaceInputs) {
|
|
2336
1899
|
output = output.replaceAll(replaceInput, replaceWith);
|
|
2337
1900
|
}
|
|
2338
1901
|
return output;
|
|
2339
1902
|
}
|
|
2340
|
-
function librarySplitMultipleArtists(input, aliases =
|
|
1903
|
+
export function librarySplitMultipleArtists(input, aliases = MUSIC_ARTIST_ALIASES) {
|
|
2341
1904
|
const inputs = input.split(/(?:[,+;]|\W(?:[&x]|and|with|fixes|befriends|vs\.?)\W|\/)/gi);
|
|
2342
1905
|
return inputs.map(artist => {
|
|
2343
1906
|
artist = aliases.get(singleSpacesOnly(artist.replaceAll("", " ").replaceAll(" - Topic", ""))).trim();
|
|
2344
|
-
const parenthesisFeatMatch = artist.match(
|
|
1907
|
+
const parenthesisFeatMatch = artist.match(FEAT_WITH_PARENTHESIS_REGEX);
|
|
2345
1908
|
if (parenthesisFeatMatch != null) {
|
|
2346
1909
|
artist = artist.slice(0, parenthesisFeatMatch.index).trim();
|
|
2347
1910
|
}
|
|
@@ -2354,9 +1917,9 @@ function librarySplitMultipleArtists(input, aliases = classes_1.MUSIC_ARTIST_ALI
|
|
|
2354
1917
|
return singleSpacesOnly(artist);
|
|
2355
1918
|
}).filter(artist => artist.length > 0);
|
|
2356
1919
|
}
|
|
2357
|
-
function libraryFindFeaturing(originalInput, aliases =
|
|
1920
|
+
export function libraryFindFeaturing(originalInput, aliases = MUSIC_ARTIST_ALIASES) {
|
|
2358
1921
|
let input = originalInput;
|
|
2359
|
-
const featMatch = input.match(
|
|
1922
|
+
const featMatch = input.match(FEAT_WITH_PARENTHESIS_REGEX);
|
|
2360
1923
|
if (featMatch == null) {
|
|
2361
1924
|
return { newName: input, artists: [] };
|
|
2362
1925
|
}
|
|
@@ -2380,7 +1943,7 @@ function libraryFindFeaturing(originalInput, aliases = classes_1.MUSIC_ARTIST_AL
|
|
|
2380
1943
|
artists: featuring
|
|
2381
1944
|
};
|
|
2382
1945
|
}
|
|
2383
|
-
function libraryCleanUpStartAndEndOfString(input) {
|
|
1946
|
+
export function libraryCleanUpStartAndEndOfString(input) {
|
|
2384
1947
|
input = input.trim();
|
|
2385
1948
|
if (input.length == 0) {
|
|
2386
1949
|
return input;
|
|
@@ -2403,7 +1966,7 @@ function libraryCleanUpStartAndEndOfString(input) {
|
|
|
2403
1966
|
}
|
|
2404
1967
|
return singleSpacesOnly(input).trim();
|
|
2405
1968
|
}
|
|
2406
|
-
function generateWeightedItemsGridString(width, height, symbols, totalWeight) {
|
|
1969
|
+
export function generateWeightedItemsGridString(width, height, symbols, totalWeight) {
|
|
2407
1970
|
let grid = '';
|
|
2408
1971
|
let lastItem = '';
|
|
2409
1972
|
for (let y = 0; y < height; ++y) {
|
|
@@ -2425,7 +1988,7 @@ function generateWeightedItemsGridString(width, height, symbols, totalWeight) {
|
|
|
2425
1988
|
}
|
|
2426
1989
|
return grid;
|
|
2427
1990
|
}
|
|
2428
|
-
async function promptYesOrNo(actionName = "Proceed?") {
|
|
1991
|
+
export async function promptYesOrNo(actionName = "Proceed?") {
|
|
2429
1992
|
return new Promise(resolve => {
|
|
2430
1993
|
process.stdout.write(`${actionName} [y/n]: `);
|
|
2431
1994
|
process.stdin.setRawMode(true);
|
|
@@ -2449,28 +2012,27 @@ async function promptYesOrNo(actionName = "Proceed?") {
|
|
|
2449
2012
|
process.stdin.on('data', onKeyPress);
|
|
2450
2013
|
});
|
|
2451
2014
|
}
|
|
2452
|
-
async function musicFileInfoToM3uEntry(fileInfo) {
|
|
2453
|
-
|
|
2454
|
-
const
|
|
2455
|
-
const tags = await util_1.musicMetadata.parseFile(fileInfo.path, { skipCovers: true });
|
|
2015
|
+
export async function musicFileInfoToM3uEntry(fileInfo) {
|
|
2016
|
+
const titleAndArtists = await TitleAndArtists.fromFileInfo(fileInfo);
|
|
2017
|
+
const tags = await musicMetadata.parseFile(fileInfo.path, { skipCovers: true });
|
|
2456
2018
|
const formatTags = tags.format;
|
|
2457
|
-
const durationS =
|
|
2019
|
+
const durationS = formatTags.duration ?? -1;
|
|
2458
2020
|
return toM3uEntry(fileInfo.path, titleAndArtists.artistsDashTitle, durationS);
|
|
2459
2021
|
}
|
|
2460
|
-
function toM3uEntry(path, title = "", durationS = -1) {
|
|
2461
|
-
const safeTitle = title.trim().length == 0 ?
|
|
2022
|
+
export function toM3uEntry(path, title = "", durationS = -1) {
|
|
2023
|
+
const safeTitle = title.trim().length == 0 ? basename(path) : title;
|
|
2462
2024
|
return `#EXTINF:${Math.floor(durationS)},${safeTitle}\n${path}`;
|
|
2463
2025
|
}
|
|
2464
|
-
function getStepString(step, totalSteps = -1) {
|
|
2026
|
+
export function getStepString(step, totalSteps = -1) {
|
|
2465
2027
|
if (totalSteps > 0) {
|
|
2466
2028
|
return `Step ${step}/${totalSteps}:`;
|
|
2467
2029
|
}
|
|
2468
2030
|
return `Step ${step}:`;
|
|
2469
2031
|
}
|
|
2470
|
-
function sliceOffLastSlash(path, times = 1) {
|
|
2471
|
-
return sliceOffLast(path,
|
|
2032
|
+
export function sliceOffLastSlash(path, times = 1) {
|
|
2033
|
+
return sliceOffLast(path, SEP, times);
|
|
2472
2034
|
}
|
|
2473
|
-
function sliceOffLast(path, lastMatch, times = 1) {
|
|
2035
|
+
export function sliceOffLast(path, lastMatch, times = 1) {
|
|
2474
2036
|
do {
|
|
2475
2037
|
const lastSlashIndex = path.lastIndexOf(lastMatch);
|
|
2476
2038
|
if (lastSlashIndex == -1) {
|
|
@@ -2480,7 +2042,7 @@ function sliceOffLast(path, lastMatch, times = 1) {
|
|
|
2480
2042
|
} while (--times > 0);
|
|
2481
2043
|
return path;
|
|
2482
2044
|
}
|
|
2483
|
-
function sliceOffUntil(text, lastMatch) {
|
|
2045
|
+
export function sliceOffUntil(text, lastMatch) {
|
|
2484
2046
|
const lastSlashIndex = text.lastIndexOf(lastMatch);
|
|
2485
2047
|
if (lastSlashIndex == -1) {
|
|
2486
2048
|
return text;
|
|
@@ -2500,7 +2062,7 @@ function sliceOffNonProject(path) {
|
|
|
2500
2062
|
}
|
|
2501
2063
|
return path.substring(lastSlashIndex + 1);
|
|
2502
2064
|
}
|
|
2503
|
-
function countOccurances(path, match) {
|
|
2065
|
+
export function countOccurances(path, match) {
|
|
2504
2066
|
let count = 0;
|
|
2505
2067
|
let index = path.indexOf(match);
|
|
2506
2068
|
while (index != -1) {
|
|
@@ -2509,21 +2071,21 @@ function countOccurances(path, match) {
|
|
|
2509
2071
|
}
|
|
2510
2072
|
return count;
|
|
2511
2073
|
}
|
|
2512
|
-
function countPathDepth(path) {
|
|
2074
|
+
export function countPathDepth(path) {
|
|
2513
2075
|
return countOccurances(path, "/");
|
|
2514
2076
|
}
|
|
2515
|
-
function getPathEscapeString(depth) {
|
|
2077
|
+
export function getPathEscapeString(depth) {
|
|
2516
2078
|
let pathEscapeString = "";
|
|
2517
2079
|
for (let i = 0; i < depth; ++i) {
|
|
2518
2080
|
pathEscapeString += "../";
|
|
2519
2081
|
}
|
|
2520
2082
|
return pathEscapeString;
|
|
2521
2083
|
}
|
|
2522
|
-
function getFullPathEscapeString(path) {
|
|
2084
|
+
export function getFullPathEscapeString(path) {
|
|
2523
2085
|
const depth = countPathDepth(path);
|
|
2524
2086
|
return getPathEscapeString(depth);
|
|
2525
2087
|
}
|
|
2526
|
-
function jsonLookupToMap(json) {
|
|
2088
|
+
export function jsonLookupToMap(json) {
|
|
2527
2089
|
const map = new Map();
|
|
2528
2090
|
for (const [key, value] of Object.entries(json)) {
|
|
2529
2091
|
const numberKey = parseInt(key);
|
|
@@ -2535,19 +2097,19 @@ function jsonLookupToMap(json) {
|
|
|
2535
2097
|
}
|
|
2536
2098
|
return map;
|
|
2537
2099
|
}
|
|
2538
|
-
function extractElementFromJsonAndRemove(obj, key) {
|
|
2100
|
+
export function extractElementFromJsonAndRemove(obj, key) {
|
|
2539
2101
|
const element = obj[key];
|
|
2540
2102
|
delete obj[key];
|
|
2541
2103
|
return element;
|
|
2542
2104
|
}
|
|
2543
|
-
function extractLookupFromJsonAndRemove(obj) {
|
|
2105
|
+
export function extractLookupFromJsonAndRemove(obj) {
|
|
2544
2106
|
const keys = jsonLookupToMap(extractElementFromJsonAndRemove(obj, "lookup"));
|
|
2545
2107
|
return keys;
|
|
2546
2108
|
}
|
|
2547
|
-
function forEachValueAndPathOfObj(obj, callback, lookup = new Map) {
|
|
2109
|
+
export function forEachValueAndPathOfObj(obj, callback, lookup = new Map) {
|
|
2548
2110
|
return forEachLookUpValueAndPathOfObjRecursive(lookup, obj, callback);
|
|
2549
2111
|
}
|
|
2550
|
-
function forEachLookUpValueAndPathOfObjRecursive(lookup, obj, callback, inputPath = "") {
|
|
2112
|
+
export function forEachLookUpValueAndPathOfObjRecursive(lookup, obj, callback, inputPath = "") {
|
|
2551
2113
|
for (const [key, value] of Object.entries(obj)) {
|
|
2552
2114
|
const path = inputPath.length == 0 ? key : `${inputPath}/${key}`;
|
|
2553
2115
|
if (Array.isArray(value)) {
|
|
@@ -2563,48 +2125,48 @@ function forEachLookUpValueAndPathOfObjRecursive(lookup, obj, callback, inputPat
|
|
|
2563
2125
|
}
|
|
2564
2126
|
}
|
|
2565
2127
|
}
|
|
2566
|
-
async function findGeniusSongs(search) {
|
|
2567
|
-
const songs = await
|
|
2128
|
+
export async function findGeniusSongs(search) {
|
|
2129
|
+
const songs = await geniusClient.songs.search(search);
|
|
2568
2130
|
return songs;
|
|
2569
2131
|
}
|
|
2570
|
-
function trimToCharNumbersOnly(input) {
|
|
2571
|
-
return trim(input,
|
|
2132
|
+
export function trimToCharNumbersOnly(input) {
|
|
2133
|
+
return trim(input, NON_NUMBER_OR_CHAR_REGEX);
|
|
2572
2134
|
}
|
|
2573
|
-
function trimStartToCharNumbersOnly(input) {
|
|
2574
|
-
return trimStart(input,
|
|
2135
|
+
export function trimStartToCharNumbersOnly(input) {
|
|
2136
|
+
return trimStart(input, NON_NUMBER_OR_CHAR_REGEX);
|
|
2575
2137
|
}
|
|
2576
|
-
function trimEndToCharNumbersOnly(input) {
|
|
2577
|
-
return trimEnd(input,
|
|
2138
|
+
export function trimEndToCharNumbersOnly(input) {
|
|
2139
|
+
return trimEnd(input, NON_NUMBER_OR_CHAR_REGEX);
|
|
2578
2140
|
}
|
|
2579
|
-
function trim(input, regex =
|
|
2141
|
+
export function trim(input, regex = TRIM_REGEX) {
|
|
2580
2142
|
return trimStart(trimEnd(input, regex), regex);
|
|
2581
2143
|
}
|
|
2582
|
-
function trimStart(input, regex) {
|
|
2144
|
+
export function trimStart(input, regex) {
|
|
2583
2145
|
let startIndex = 0;
|
|
2584
2146
|
while (startIndex < input.length && regex.test(input[startIndex])) {
|
|
2585
2147
|
++startIndex;
|
|
2586
2148
|
}
|
|
2587
2149
|
return input.slice(startIndex, input.length);
|
|
2588
2150
|
}
|
|
2589
|
-
function trimEnd(input, regex) {
|
|
2151
|
+
export function trimEnd(input, regex) {
|
|
2590
2152
|
let endIndex = input.length - 1;
|
|
2591
2153
|
while (endIndex >= 0 && regex.test(input[endIndex])) {
|
|
2592
2154
|
--endIndex;
|
|
2593
2155
|
}
|
|
2594
2156
|
return input.slice(0, endIndex + 1);
|
|
2595
2157
|
}
|
|
2596
|
-
async function findGeniusLyrics(query, artistsToMatch = []) {
|
|
2158
|
+
export async function findGeniusLyrics(query, artistsToMatch = []) {
|
|
2597
2159
|
const geniusSongs = await findGeniusSongs(query);
|
|
2598
2160
|
for (const geniusSong of geniusSongs) {
|
|
2599
2161
|
const geniusArtistsDashTitle = `${geniusSong.artist.name} - ${geniusSong.title}`;
|
|
2600
|
-
const geniusSongArtist =
|
|
2162
|
+
const geniusSongArtist = MUSIC_ARTIST_ALIASES.get(geniusSong.artist.name);
|
|
2601
2163
|
let correctArtist = false;
|
|
2602
2164
|
if (artistsToMatch.length == 0) {
|
|
2603
2165
|
correctArtist = true;
|
|
2604
2166
|
}
|
|
2605
2167
|
else {
|
|
2606
2168
|
for (const artist of artistsToMatch) {
|
|
2607
|
-
if (geniusSongArtist ===
|
|
2169
|
+
if (geniusSongArtist === MUSIC_ARTIST_ALIASES.get(artist)) {
|
|
2608
2170
|
correctArtist = true;
|
|
2609
2171
|
break;
|
|
2610
2172
|
}
|
|
@@ -2612,16 +2174,16 @@ async function findGeniusLyrics(query, artistsToMatch = []) {
|
|
|
2612
2174
|
}
|
|
2613
2175
|
if (correctArtist) {
|
|
2614
2176
|
try {
|
|
2615
|
-
const geniusLyrics = (await geniusSong.lyrics()).replaceAll(
|
|
2177
|
+
const geniusLyrics = (await geniusSong.lyrics()).replaceAll(CONTRIBUTORS_REGEX, "");
|
|
2616
2178
|
return geniusLyrics;
|
|
2617
2179
|
}
|
|
2618
2180
|
catch (err) {
|
|
2619
|
-
console.log(
|
|
2181
|
+
console.log(chalk.redBright(`Error getting Genius lyrics for ${geniusArtistsDashTitle}:\n${err}`));
|
|
2620
2182
|
}
|
|
2621
2183
|
}
|
|
2622
2184
|
}
|
|
2623
2185
|
}
|
|
2624
|
-
function softSliceFrom(input, sliceFrom, anyCase = true, fromElseTo = true) {
|
|
2186
|
+
export function softSliceFrom(input, sliceFrom, anyCase = true, fromElseTo = true) {
|
|
2625
2187
|
const regex = new RegExp(`(${sliceFrom})`, `${anyCase ? "i" : ""}`);
|
|
2626
2188
|
const match = input.match(regex);
|
|
2627
2189
|
if (match != null) {
|
|
@@ -2635,10 +2197,10 @@ function softSliceFrom(input, sliceFrom, anyCase = true, fromElseTo = true) {
|
|
|
2635
2197
|
}
|
|
2636
2198
|
return input.trim();
|
|
2637
2199
|
}
|
|
2638
|
-
function trimFirstLinesWhileIncludes(input, blacklistLineTerm) {
|
|
2200
|
+
export function trimFirstLinesWhileIncludes(input, blacklistLineTerm) {
|
|
2639
2201
|
input = input.trim();
|
|
2640
2202
|
do {
|
|
2641
|
-
const nextLineMatch = input.match(
|
|
2203
|
+
const nextLineMatch = input.match(NEW_LINE_REGEX);
|
|
2642
2204
|
if (nextLineMatch == null) {
|
|
2643
2205
|
break;
|
|
2644
2206
|
}
|
|
@@ -2653,8 +2215,8 @@ function trimFirstLinesWhileIncludes(input, blacklistLineTerm) {
|
|
|
2653
2215
|
} while (true);
|
|
2654
2216
|
return input;
|
|
2655
2217
|
}
|
|
2656
|
-
function getFirstLine(input) {
|
|
2657
|
-
const nextLineMatch = input.match(
|
|
2218
|
+
export function getFirstLine(input) {
|
|
2219
|
+
const nextLineMatch = input.match(NEW_LINE_REGEX);
|
|
2658
2220
|
if (nextLineMatch == null) {
|
|
2659
2221
|
return undefined;
|
|
2660
2222
|
}
|
|
@@ -2662,19 +2224,19 @@ function getFirstLine(input) {
|
|
|
2662
2224
|
const firstLine = input.slice(0, nextLineIndex);
|
|
2663
2225
|
return firstLine;
|
|
2664
2226
|
}
|
|
2665
|
-
function skyify(input) {
|
|
2666
|
-
return input.replaceAll(/[^\n\r ]/g, (_) => getRandomWeighedItem(
|
|
2227
|
+
export function skyify(input) {
|
|
2228
|
+
return input.replaceAll(/[^\n\r ]/g, (_) => getRandomWeighedItem(NIGHT_SKY_ITEMS, NIGHT_SKY_ITEMS_TOTAL_WEIGHT)).slice(0, DISCORD_MESSAGE_LENGTH_LIMIT);
|
|
2667
2229
|
}
|
|
2668
|
-
function dateToFilename(date) {
|
|
2230
|
+
export function dateToFilename(date) {
|
|
2669
2231
|
const year = date.getFullYear();
|
|
2670
2232
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
2671
2233
|
const day = String(date.getDate()).padStart(2, '0');
|
|
2672
2234
|
return `${year}-${month}-${day}_${date.getHours()}-${date.getMinutes()}-${date.getSeconds()}`;
|
|
2673
2235
|
}
|
|
2674
|
-
function makeMap(preparer) {
|
|
2236
|
+
export function makeMap(preparer) {
|
|
2675
2237
|
return make(new Map, preparer);
|
|
2676
2238
|
}
|
|
2677
|
-
function makeWeightedMap(input) {
|
|
2239
|
+
export function makeWeightedMap(input) {
|
|
2678
2240
|
if (input instanceof Array) {
|
|
2679
2241
|
return makeWeightedMap(map => {
|
|
2680
2242
|
for (const item of input) {
|
|
@@ -2682,9 +2244,9 @@ function makeWeightedMap(input) {
|
|
|
2682
2244
|
}
|
|
2683
2245
|
});
|
|
2684
2246
|
}
|
|
2685
|
-
return make(new
|
|
2247
|
+
return make(new WeightedMap, input);
|
|
2686
2248
|
}
|
|
2687
|
-
function makeWeightedTextCompMap(input) {
|
|
2249
|
+
export function makeWeightedTextCompMap(input) {
|
|
2688
2250
|
if (input instanceof Array) {
|
|
2689
2251
|
return makeWeightedTextCompMap(map => {
|
|
2690
2252
|
for (const item of input) {
|
|
@@ -2692,9 +2254,9 @@ function makeWeightedTextCompMap(input) {
|
|
|
2692
2254
|
}
|
|
2693
2255
|
});
|
|
2694
2256
|
}
|
|
2695
|
-
return make(new
|
|
2257
|
+
return make(new WeightedMap, input);
|
|
2696
2258
|
}
|
|
2697
|
-
function generateLinesUntilCharacterLimit(generator, amount = 1, limit =
|
|
2259
|
+
export function generateLinesUntilCharacterLimit(generator, amount = 1, limit = DISCORD_MESSAGE_LENGTH_LIMIT) {
|
|
2698
2260
|
let output = "";
|
|
2699
2261
|
for (let i = 0; i < amount; ++i) {
|
|
2700
2262
|
const nextLine = generator();
|
|
@@ -2705,18 +2267,18 @@ function generateLinesUntilCharacterLimit(generator, amount = 1, limit = fields_
|
|
|
2705
2267
|
}
|
|
2706
2268
|
return output;
|
|
2707
2269
|
}
|
|
2708
|
-
function lastIndexOfSeparator(path) {
|
|
2270
|
+
export function lastIndexOfSeparator(path) {
|
|
2709
2271
|
return Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
2710
2272
|
}
|
|
2711
|
-
function timestamp() {
|
|
2273
|
+
export function timestamp() {
|
|
2712
2274
|
const now = new Date();
|
|
2713
2275
|
return `[${padLeft(now.getHours().toString(), 2, "0")}:${padLeft(now.getMinutes().toString(), 2, "0")}:${padLeft(now.getSeconds().toString(), 2, "0")}]`;
|
|
2714
2276
|
}
|
|
2715
|
-
function timestampWithMs() {
|
|
2277
|
+
export function timestampWithMs() {
|
|
2716
2278
|
const now = new Date();
|
|
2717
2279
|
return `${timestamp().slice(0, -1)}.${padLeft(now.getMilliseconds().toString(), 3, "0")}]`;
|
|
2718
2280
|
}
|
|
2719
|
-
function isSilent(buffer) {
|
|
2281
|
+
export function isSilent(buffer) {
|
|
2720
2282
|
var speechSample;
|
|
2721
2283
|
for (var i = 0; i < buffer.length; i = i + 2) {
|
|
2722
2284
|
if (buffer[i + 1] > 128) {
|
|
@@ -2732,16 +2294,16 @@ function isSilent(buffer) {
|
|
|
2732
2294
|
}
|
|
2733
2295
|
return true;
|
|
2734
2296
|
}
|
|
2735
|
-
async function waitMs(ms) {
|
|
2297
|
+
export async function waitMs(ms) {
|
|
2736
2298
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
2737
2299
|
}
|
|
2738
|
-
async function waitS(s) {
|
|
2300
|
+
export async function waitS(s) {
|
|
2739
2301
|
return new Promise(resolve => setTimeout(resolve, s * 1000));
|
|
2740
2302
|
}
|
|
2741
|
-
async function whileFalseAsyncS(intervalS, stopIfTrue) {
|
|
2303
|
+
export async function whileFalseAsyncS(intervalS, stopIfTrue) {
|
|
2742
2304
|
return whileFalseAsyncMs(intervalS * 1000, stopIfTrue);
|
|
2743
2305
|
}
|
|
2744
|
-
async function whileFalseAsyncMs(intervalMs, stopIfTrue) {
|
|
2306
|
+
export async function whileFalseAsyncMs(intervalMs, stopIfTrue) {
|
|
2745
2307
|
return new Promise(async (resolve, reject) => {
|
|
2746
2308
|
let task = null;
|
|
2747
2309
|
task = setInterval(() => {
|
|
@@ -2752,10 +2314,10 @@ async function whileFalseAsyncMs(intervalMs, stopIfTrue) {
|
|
|
2752
2314
|
}, intervalMs);
|
|
2753
2315
|
});
|
|
2754
2316
|
}
|
|
2755
|
-
async function repeatForAsyncS(durationS, intervalS, stopIfTrue) {
|
|
2317
|
+
export async function repeatForAsyncS(durationS, intervalS, stopIfTrue) {
|
|
2756
2318
|
return repeatForAsyncMs(durationS * 1000, intervalS * 1000, stopIfTrue);
|
|
2757
2319
|
}
|
|
2758
|
-
async function repeatForAsyncMs(durationMs, intervalMs, stopIfTrue) {
|
|
2320
|
+
export async function repeatForAsyncMs(durationMs, intervalMs, stopIfTrue) {
|
|
2759
2321
|
const endTime = Date.now() + durationMs;
|
|
2760
2322
|
return whileFalseAsyncMs(intervalMs, () => {
|
|
2761
2323
|
if (Date.now() <= endTime || stopIfTrue()) {
|
|
@@ -2776,7 +2338,7 @@ async function repeatForAsyncMs(durationMs, intervalMs, stopIfTrue) {
|
|
|
2776
2338
|
// }
|
|
2777
2339
|
// }
|
|
2778
2340
|
let lastSetTerminalLine = "";
|
|
2779
|
-
function replaceLastTerminalLine(text) {
|
|
2341
|
+
export function replaceLastTerminalLine(text) {
|
|
2780
2342
|
try {
|
|
2781
2343
|
process.stdout.clearLine(0);
|
|
2782
2344
|
process.stdout.cursorTo(0);
|
|
@@ -2790,7 +2352,7 @@ function replaceLastTerminalLine(text) {
|
|
|
2790
2352
|
}
|
|
2791
2353
|
}
|
|
2792
2354
|
let lastTerminalOutputLines = 0;
|
|
2793
|
-
function setTerminalOutput(text, newSession = false) {
|
|
2355
|
+
export function setTerminalOutput(text, newSession = false) {
|
|
2794
2356
|
try {
|
|
2795
2357
|
clearTerminalLines(lastTerminalOutputLines);
|
|
2796
2358
|
if (newSession) {
|
|
@@ -2804,11 +2366,11 @@ function setTerminalOutput(text, newSession = false) {
|
|
|
2804
2366
|
print(`Tried to set terminal output, but failed.\n${getStackTrace()}\n${e}`);
|
|
2805
2367
|
}
|
|
2806
2368
|
}
|
|
2807
|
-
function clearSetTerminalOutput() {
|
|
2369
|
+
export function clearSetTerminalOutput() {
|
|
2808
2370
|
clearTerminalLines(lastTerminalOutputLines);
|
|
2809
2371
|
lastTerminalOutputLines = 0;
|
|
2810
2372
|
}
|
|
2811
|
-
function clearTerminalLines(amount) {
|
|
2373
|
+
export function clearTerminalLines(amount) {
|
|
2812
2374
|
try {
|
|
2813
2375
|
process.stdout.write('\x1b[0G'); // Move to start of line
|
|
2814
2376
|
for (let i = 0; i < amount + 1; i++) {
|
|
@@ -2822,22 +2384,22 @@ function clearTerminalLines(amount) {
|
|
|
2822
2384
|
print(`Tried to clear terminal lines, but failed.\n${getStackTrace()}\n${e}`);
|
|
2823
2385
|
}
|
|
2824
2386
|
}
|
|
2825
|
-
function sIfNot1(count) {
|
|
2387
|
+
export function sIfNot1(count) {
|
|
2826
2388
|
return count == 1 ? "" : "s";
|
|
2827
2389
|
}
|
|
2828
|
-
function if1Else(count, if1, or) {
|
|
2390
|
+
export function if1Else(count, if1, or) {
|
|
2829
2391
|
return count == 1 ? if1 : or;
|
|
2830
2392
|
}
|
|
2831
|
-
function makePath(...paths) {
|
|
2832
|
-
return paths.join(
|
|
2393
|
+
export function makePath(...paths) {
|
|
2394
|
+
return paths.join(path.sep).replaceAll(/[/\\]/g, path.sep);
|
|
2833
2395
|
}
|
|
2834
|
-
function makeUnixPath(...paths) {
|
|
2396
|
+
export function makeUnixPath(...paths) {
|
|
2835
2397
|
return paths.join("/").replaceAll("\\", "/");
|
|
2836
2398
|
}
|
|
2837
|
-
function makeWindowsPath(...paths) {
|
|
2399
|
+
export function makeWindowsPath(...paths) {
|
|
2838
2400
|
return paths.join("\\").replaceAll("/", "\\");
|
|
2839
2401
|
}
|
|
2840
|
-
function overflow(value, min, max) {
|
|
2402
|
+
export function overflow(value, min, max) {
|
|
2841
2403
|
if (value < min) {
|
|
2842
2404
|
const gap = max - min + 1;
|
|
2843
2405
|
const minGap = min - value - 1;
|
|
@@ -2850,14 +2412,14 @@ function overflow(value, min, max) {
|
|
|
2850
2412
|
}
|
|
2851
2413
|
return value;
|
|
2852
2414
|
}
|
|
2853
|
-
function overflow0(value, max) {
|
|
2415
|
+
export function overflow0(value, max) {
|
|
2854
2416
|
return overflow(value, 0, max);
|
|
2855
2417
|
}
|
|
2856
|
-
function isWithin(value, min, max) {
|
|
2418
|
+
export function isWithin(value, min, max) {
|
|
2857
2419
|
return min <= value && value <= max;
|
|
2858
2420
|
}
|
|
2859
2421
|
//region Menu
|
|
2860
|
-
async function startShiftItemsMenu(items, itemValueMap, values, selectedIndex = 0, rainbow = true, itemToString = objectToString, valueToString = objectToString) {
|
|
2422
|
+
export async function startShiftItemsMenu(items, itemValueMap, values, selectedIndex = 0, rainbow = true, itemToString = objectToString, valueToString = objectToString) {
|
|
2861
2423
|
if (values.length === 0) {
|
|
2862
2424
|
throw new Error("startShiftItemsMenu: No values to select from!");
|
|
2863
2425
|
}
|
|
@@ -2880,10 +2442,10 @@ async function startShiftItemsMenu(items, itemValueMap, values, selectedIndex =
|
|
|
2880
2442
|
update();
|
|
2881
2443
|
}, rainbow, itemToString, valueToString);
|
|
2882
2444
|
}
|
|
2883
|
-
function getRelativeOverflow(startIndex, values, moveBy) {
|
|
2445
|
+
export function getRelativeOverflow(startIndex, values, moveBy) {
|
|
2884
2446
|
return values[overflow0(startIndex + moveBy, values.length - 1)];
|
|
2885
2447
|
}
|
|
2886
|
-
function shiftMenuItemsFunction(valueIndex, values, value, info) {
|
|
2448
|
+
export function shiftMenuItemsFunction(valueIndex, values, value, info) {
|
|
2887
2449
|
if (valueIndex === -1) {
|
|
2888
2450
|
valueIndex = clamp0(values.indexOf(value), values.length - 1);
|
|
2889
2451
|
}
|
|
@@ -2894,7 +2456,7 @@ function shiftMenuItemsFunction(valueIndex, values, value, info) {
|
|
|
2894
2456
|
index: valueIndex
|
|
2895
2457
|
};
|
|
2896
2458
|
}
|
|
2897
|
-
async function startNumbersEditMenu(items, itemValueMap, selectedIndex = 0, rainbow = true, itemToString = objectToString, valueToString = objectToString) {
|
|
2459
|
+
export async function startNumbersEditMenu(items, itemValueMap, selectedIndex = 0, rainbow = true, itemToString = objectToString, valueToString = objectToString) {
|
|
2898
2460
|
getOrCreateFromKeys(itemValueMap, items, () => 0);
|
|
2899
2461
|
return startMenu(items, itemValueMap, selectedIndex, (selectedIndex, info, update, setSelectedIndex) => {
|
|
2900
2462
|
switch (info.name) {
|
|
@@ -2922,14 +2484,14 @@ async function startNumbersEditMenu(items, itemValueMap, selectedIndex = 0, rain
|
|
|
2922
2484
|
}
|
|
2923
2485
|
}, rainbow, itemToString, valueToString);
|
|
2924
2486
|
}
|
|
2925
|
-
async function startMenu(items, itemValueMap, selectedIndex = 0, onKeyPress, rainbow = true, itemToString = objectToString, valueToString = objectToString) {
|
|
2487
|
+
export async function startMenu(items, itemValueMap, selectedIndex = 0, onKeyPress, rainbow = true, itemToString = objectToString, valueToString = objectToString) {
|
|
2926
2488
|
selectedIndex = clamp0(selectedIndex, items.length - 1);
|
|
2927
2489
|
return new Promise((resolve, reject) => {
|
|
2928
2490
|
if (items.length === 0) {
|
|
2929
2491
|
reject('startMenu: No items to select from!');
|
|
2930
2492
|
return;
|
|
2931
2493
|
}
|
|
2932
|
-
const itemsRange =
|
|
2494
|
+
const itemsRange = RangedNumber.range(0, items.length - 1);
|
|
2933
2495
|
let item;
|
|
2934
2496
|
const update = () => {
|
|
2935
2497
|
item = items[selectedIndex];
|
|
@@ -2972,7 +2534,7 @@ async function startMenu(items, itemValueMap, selectedIndex = 0, onKeyPress, rai
|
|
|
2972
2534
|
});
|
|
2973
2535
|
});
|
|
2974
2536
|
}
|
|
2975
|
-
function navigationKeysToNumber(info) {
|
|
2537
|
+
export function navigationKeysToNumber(info) {
|
|
2976
2538
|
const key = info.name.toLowerCase();
|
|
2977
2539
|
switch (key) {
|
|
2978
2540
|
case 'up':
|
|
@@ -2996,7 +2558,7 @@ function navigationKeysToNumber(info) {
|
|
|
2996
2558
|
}
|
|
2997
2559
|
return 0;
|
|
2998
2560
|
}
|
|
2999
|
-
function editNumberByInput(value, key, overflowLimits, control = false, shift = false, meta = false) {
|
|
2561
|
+
export function editNumberByInput(value, key, overflowLimits, control = false, shift = false, meta = false) {
|
|
3000
2562
|
switch (key.toLowerCase()) {
|
|
3001
2563
|
case 'up':
|
|
3002
2564
|
case 'down':
|
|
@@ -3031,7 +2593,7 @@ function editNumberByInput(value, key, overflowLimits, control = false, shift =
|
|
|
3031
2593
|
return value;
|
|
3032
2594
|
}
|
|
3033
2595
|
const objectToString = (obj) => obj.toString();
|
|
3034
|
-
function toMenuString(items, itemValueMap, selectedIndex = 0, rainbow = true, itemToString = objectToString, valueToString = objectToString) {
|
|
2596
|
+
export function toMenuString(items, itemValueMap, selectedIndex = 0, rainbow = true, itemToString = objectToString, valueToString = objectToString) {
|
|
3035
2597
|
let output = '';
|
|
3036
2598
|
let longest = 0;
|
|
3037
2599
|
for (const [item, value] of itemValueMap) {
|
|
@@ -3043,11 +2605,11 @@ function toMenuString(items, itemValueMap, selectedIndex = 0, rainbow = true, it
|
|
|
3043
2605
|
let itemIndex = 0;
|
|
3044
2606
|
for (const [item, value] of itemValueMap) {
|
|
3045
2607
|
const selected = itemIndex === selectedIndex;
|
|
3046
|
-
const prefix = selected ? '>' :
|
|
2608
|
+
const prefix = selected ? '>' : EMPTY;
|
|
3047
2609
|
const valueText = valueToString(value);
|
|
3048
|
-
let itemText = `${prefix}${`[${padRight(valueText, longest,
|
|
2610
|
+
let itemText = `${prefix}${`[${padRight(valueText, longest, EMPTY)}]`} | ${itemToString(item)}`;
|
|
3049
2611
|
if (selected) {
|
|
3050
|
-
itemText =
|
|
2612
|
+
itemText = chalk.bold(itemText);
|
|
3051
2613
|
}
|
|
3052
2614
|
if (rainbow) {
|
|
3053
2615
|
itemText = chalkRainbowColor(itemText, itemIndex);
|
|
@@ -3058,31 +2620,29 @@ function toMenuString(items, itemValueMap, selectedIndex = 0, rainbow = true, it
|
|
|
3058
2620
|
return output.trim();
|
|
3059
2621
|
}
|
|
3060
2622
|
//endregion Menu
|
|
3061
|
-
function toPrintString(fileName, functionName, lineNumber) {
|
|
3062
|
-
return `${timestamp()} ${
|
|
2623
|
+
export function toPrintString(fileName, functionName, lineNumber) {
|
|
2624
|
+
return `${timestamp()} ${chalk.cyanBright(sliceOffNonProject(fileName))}:${chalk.greenBright(lineNumber)}${functionName ? ` | ${chalk.magentaBright(functionName)}` : ""}`;
|
|
3063
2625
|
}
|
|
3064
2626
|
let rainbowIndex = 0;
|
|
3065
|
-
function getStackTrace() {
|
|
2627
|
+
export function getStackTrace() {
|
|
3066
2628
|
return new Error().stack;
|
|
3067
2629
|
}
|
|
3068
|
-
function getStackTraceLine(depth) {
|
|
3069
|
-
|
|
3070
|
-
return (_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split('\n')[depth]) === null || _b === void 0 ? void 0 : _b.trim();
|
|
2630
|
+
export function getStackTraceLine(depth) {
|
|
2631
|
+
return new Error().stack?.split('\n')[depth]?.trim();
|
|
3071
2632
|
}
|
|
3072
|
-
function getCallerErrorLine() {
|
|
2633
|
+
export function getCallerErrorLine() {
|
|
3073
2634
|
return getStackTraceLine(4);
|
|
3074
2635
|
}
|
|
3075
|
-
function isCallerTs() {
|
|
3076
|
-
|
|
3077
|
-
return (_b = (_a = getCallerErrorLine()) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(".ts:")) !== null && _b !== void 0 ? _b : false;
|
|
2636
|
+
export function isCallerTs() {
|
|
2637
|
+
return getCallerErrorLine()?.toLowerCase().includes(".ts:") ?? false;
|
|
3078
2638
|
}
|
|
3079
|
-
function printError(message) {
|
|
3080
|
-
print(
|
|
2639
|
+
export function printError(message) {
|
|
2640
|
+
print(chalk.redBright(`ERROR${message ? `: ${message}` : undefined}`), false);
|
|
3081
2641
|
}
|
|
3082
|
-
function printWarn(message) {
|
|
3083
|
-
print(
|
|
2642
|
+
export function printWarn(message) {
|
|
2643
|
+
print(chalk.yellowBright(`WARN${message ? `: ${message}` : undefined}`), false);
|
|
3084
2644
|
}
|
|
3085
|
-
function print(message, rainbow = false) {
|
|
2645
|
+
export function print(message, rainbow = false) {
|
|
3086
2646
|
message = message ? `: ${message}` : "";
|
|
3087
2647
|
const stack = new Error().stack;
|
|
3088
2648
|
if (stack) {
|
|
@@ -3112,7 +2672,7 @@ function print(message, rainbow = false) {
|
|
|
3112
2672
|
}
|
|
3113
2673
|
}
|
|
3114
2674
|
}
|
|
3115
|
-
function softToFixed(num, maxDecimals = 2) {
|
|
2675
|
+
export function softToFixed(num, maxDecimals = 2) {
|
|
3116
2676
|
if (!isFinite(num)) {
|
|
3117
2677
|
return String(num);
|
|
3118
2678
|
}
|
|
@@ -3120,41 +2680,41 @@ function softToFixed(num, maxDecimals = 2) {
|
|
|
3120
2680
|
const rounded = Math.round(num * factor) / factor;
|
|
3121
2681
|
return rounded.toString();
|
|
3122
2682
|
}
|
|
3123
|
-
function extractEpisodeNumber(filename) {
|
|
2683
|
+
export function extractEpisodeNumber(filename) {
|
|
3124
2684
|
const match = filename.match(/(?:e\s*)?(\d{1,3})(?!\d)/i);
|
|
3125
2685
|
return match ? parseInt(match[1], 10) : -1;
|
|
3126
2686
|
}
|
|
3127
|
-
function trashSoft(filePath) {
|
|
3128
|
-
if (!
|
|
2687
|
+
export function trashSoft(filePath) {
|
|
2688
|
+
if (!existsSync(filePath)) {
|
|
3129
2689
|
return false;
|
|
3130
2690
|
}
|
|
3131
|
-
const plat =
|
|
2691
|
+
const plat = platform();
|
|
3132
2692
|
try {
|
|
3133
2693
|
switch (plat) {
|
|
3134
2694
|
case "win32":
|
|
3135
2695
|
{
|
|
3136
|
-
|
|
2696
|
+
execSync(`powershell -Command "Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile('${filePath.replace(/'/g, "''")}', 'OnlyErrorDialogs', 'SendToRecycleBin')"`);
|
|
3137
2697
|
}
|
|
3138
2698
|
break;
|
|
3139
2699
|
case "darwin":
|
|
3140
2700
|
{
|
|
3141
|
-
|
|
2701
|
+
execSync(`osascript -e 'tell app "Finder" to delete POSIX file "${filePath.replace(/"/g, '\\"')}"'`);
|
|
3142
2702
|
}
|
|
3143
2703
|
break;
|
|
3144
2704
|
default:
|
|
3145
2705
|
{
|
|
3146
2706
|
try {
|
|
3147
|
-
|
|
2707
|
+
execSync(`gio trash "${filePath.replace(/"/g, '\\"')}"`);
|
|
3148
2708
|
}
|
|
3149
|
-
catch
|
|
3150
|
-
|
|
2709
|
+
catch {
|
|
2710
|
+
execSync(`trash "${filePath.replace(/"/g, '\\"')}"`);
|
|
3151
2711
|
}
|
|
3152
2712
|
}
|
|
3153
2713
|
break;
|
|
3154
2714
|
}
|
|
3155
2715
|
}
|
|
3156
2716
|
catch (e) {
|
|
3157
|
-
|
|
2717
|
+
rmSync(filePath);
|
|
3158
2718
|
}
|
|
3159
2719
|
return true;
|
|
3160
2720
|
}
|
|
@@ -3194,31 +2754,21 @@ const modelExtensions = new Set([
|
|
|
3194
2754
|
const imageSequenceExtensions = new Set([
|
|
3195
2755
|
'dpx', 'exr', 'tga'
|
|
3196
2756
|
]);
|
|
3197
|
-
function isOfType(extension, extensions) {
|
|
2757
|
+
export function isOfType(extension, extensions) {
|
|
3198
2758
|
return extensions.has(extension);
|
|
3199
2759
|
}
|
|
3200
2760
|
// --- Exports ---
|
|
3201
|
-
const isPicture = (extension) => isOfType(extension, pictureExtensions);
|
|
3202
|
-
|
|
3203
|
-
const
|
|
3204
|
-
|
|
3205
|
-
const
|
|
3206
|
-
|
|
3207
|
-
const
|
|
3208
|
-
|
|
3209
|
-
const
|
|
3210
|
-
|
|
3211
|
-
const
|
|
3212
|
-
exports.isArchive = isArchive;
|
|
3213
|
-
const isDocument = (extension) => isOfType(extension, documentExtensions);
|
|
3214
|
-
exports.isDocument = isDocument;
|
|
3215
|
-
const isCode = (extension) => isOfType(extension, codeExtensions);
|
|
3216
|
-
exports.isCode = isCode;
|
|
3217
|
-
const isModel = (extension) => isOfType(extension, modelExtensions);
|
|
3218
|
-
exports.isModel = isModel;
|
|
3219
|
-
const isImageSequence = (extension) => isOfType(extension, imageSequenceExtensions);
|
|
3220
|
-
exports.isImageSequence = isImageSequence;
|
|
3221
|
-
const classifyExt = (ext) => {
|
|
2761
|
+
export const isPicture = (extension) => isOfType(extension, pictureExtensions);
|
|
2762
|
+
export const isVideo = (extension) => isOfType(extension, videoExtensions);
|
|
2763
|
+
export const isAudio = (extension) => isOfType(extension, audioExtensions);
|
|
2764
|
+
export const isSubtitle = (extension) => isOfType(extension, subtitleExtensions);
|
|
2765
|
+
export const isFont = (extension) => isOfType(extension, fontExtensions);
|
|
2766
|
+
export const isArchive = (extension) => isOfType(extension, archiveExtensions);
|
|
2767
|
+
export const isDocument = (extension) => isOfType(extension, documentExtensions);
|
|
2768
|
+
export const isCode = (extension) => isOfType(extension, codeExtensions);
|
|
2769
|
+
export const isModel = (extension) => isOfType(extension, modelExtensions);
|
|
2770
|
+
export const isImageSequence = (extension) => isOfType(extension, imageSequenceExtensions);
|
|
2771
|
+
export const classifyExt = (ext) => {
|
|
3222
2772
|
ext = ext.toLowerCase();
|
|
3223
2773
|
switch (true) {
|
|
3224
2774
|
case pictureExtensions.has(ext): return 'picture';
|
|
@@ -3234,16 +2784,15 @@ const classifyExt = (ext) => {
|
|
|
3234
2784
|
default: return 'unknown';
|
|
3235
2785
|
}
|
|
3236
2786
|
};
|
|
3237
|
-
exports.classifyExt = classifyExt;
|
|
3238
2787
|
//endregion extensions
|
|
3239
|
-
function subtitlesStreamInfoToString(info) {
|
|
2788
|
+
export function subtitlesStreamInfoToString(info) {
|
|
3240
2789
|
return `${info.language}:${info.streamIndex}`;
|
|
3241
2790
|
}
|
|
3242
|
-
async function extractsubtitlesStreamsInfo(videoWithSubtitlesPath) {
|
|
2791
|
+
export async function extractsubtitlesStreamsInfo(videoWithSubtitlesPath) {
|
|
3243
2792
|
const command = `ffmpeg -i "${sanitizeStringForFFMPEG(videoWithSubtitlesPath)}"`;
|
|
3244
2793
|
const result = await runCommandRejectAsResolve(command);
|
|
3245
2794
|
const subtitles = [];
|
|
3246
|
-
for (const match of result.matchAll(
|
|
2795
|
+
for (const match of result.matchAll(SUBTITLE_METADATA_REGEX)) {
|
|
3247
2796
|
let format = null;
|
|
3248
2797
|
const formatGroup1 = match[3].toLowerCase();
|
|
3249
2798
|
switch (formatGroup1) {
|
|
@@ -3285,7 +2834,7 @@ async function extractsubtitlesStreamsInfo(videoWithSubtitlesPath) {
|
|
|
3285
2834
|
}
|
|
3286
2835
|
return subtitles;
|
|
3287
2836
|
}
|
|
3288
|
-
async function tryExtractSubtitles(videoWithSubtitlesPath, subtitlesOutputPath, streamId = 0) {
|
|
2837
|
+
export async function tryExtractSubtitles(videoWithSubtitlesPath, subtitlesOutputPath, streamId = 0) {
|
|
3289
2838
|
const command = `ffmpeg -y -i "${sanitizeStringForFFMPEG(videoWithSubtitlesPath)}" -map 0:${streamId} -c copy "${sanitizeStringForFFMPEG(subtitlesOutputPath)}"`;
|
|
3290
2839
|
try {
|
|
3291
2840
|
trashSoft(subtitlesOutputPath);
|
|
@@ -3298,7 +2847,7 @@ async function tryExtractSubtitles(videoWithSubtitlesPath, subtitlesOutputPath,
|
|
|
3298
2847
|
return false;
|
|
3299
2848
|
}
|
|
3300
2849
|
}
|
|
3301
|
-
async function addSubtitles(videoToAddSubtitlesToFile, subtitlesFile, customSubtitlesName = "", clearExistingSubtitles = false) {
|
|
2850
|
+
export async function addSubtitles(videoToAddSubtitlesToFile, subtitlesFile, customSubtitlesName = "", clearExistingSubtitles = false) {
|
|
3302
2851
|
const tempOutputFile = `${videoToAddSubtitlesToFile.directory}/temp_${videoToAddSubtitlesToFile.fullName}`;
|
|
3303
2852
|
trashSoft(tempOutputFile);
|
|
3304
2853
|
// let command = `ffmpeg -i "${sanitizeStringForFFMPEG(videoToAddSubtitlesToFile.path)}" -i "${sanitizeStringForFFMPEG(subtitlesFile.path)}" -c copy -map 0 -map 1`
|
|
@@ -3319,23 +2868,23 @@ async function addSubtitles(videoToAddSubtitlesToFile, subtitlesFile, customSubt
|
|
|
3319
2868
|
return false;
|
|
3320
2869
|
}
|
|
3321
2870
|
trashSoft(videoToAddSubtitlesToFile.path);
|
|
3322
|
-
|
|
2871
|
+
renameSync(tempOutputFile, videoToAddSubtitlesToFile.path);
|
|
3323
2872
|
return true;
|
|
3324
2873
|
}
|
|
3325
|
-
|
|
3326
|
-
function noteFromMIDI(n) {
|
|
3327
|
-
return
|
|
2874
|
+
export const MUSICAL_NOTES = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'];
|
|
2875
|
+
export function noteFromMIDI(n) {
|
|
2876
|
+
return MUSICAL_NOTES[n % MUSICAL_NOTES.length];
|
|
3328
2877
|
}
|
|
3329
|
-
function octaveFromMIDI(n) {
|
|
3330
|
-
return `${Math.floor(n /
|
|
2878
|
+
export function octaveFromMIDI(n) {
|
|
2879
|
+
return `${Math.floor(n / MUSICAL_NOTES.length - 1)}`;
|
|
3331
2880
|
}
|
|
3332
|
-
function fullNoteFromMIDI(n) {
|
|
2881
|
+
export function fullNoteFromMIDI(n) {
|
|
3333
2882
|
return `${noteFromMIDI(n)}${octaveFromMIDI(n)}`;
|
|
3334
2883
|
}
|
|
3335
|
-
function clearTerminal() {
|
|
2884
|
+
export function clearTerminal() {
|
|
3336
2885
|
process.stdout.write('\x1B[2J\x1B[0f');
|
|
3337
2886
|
}
|
|
3338
|
-
async function connectMidiByName(midiInput, targetName) {
|
|
2887
|
+
export async function connectMidiByName(midiInput, targetName) {
|
|
3339
2888
|
const ports = [];
|
|
3340
2889
|
let foundPort = -1;
|
|
3341
2890
|
let attemptCount = 0;
|
|
@@ -3343,7 +2892,7 @@ async function connectMidiByName(midiInput, targetName) {
|
|
|
3343
2892
|
++attemptCount;
|
|
3344
2893
|
let output = "";
|
|
3345
2894
|
if (midiInput.getPortCount() === 0) {
|
|
3346
|
-
output +=
|
|
2895
|
+
output += chalk.red('No MIDI devices found!');
|
|
3347
2896
|
output += "\n";
|
|
3348
2897
|
}
|
|
3349
2898
|
else {
|
|
@@ -3358,7 +2907,7 @@ async function connectMidiByName(midiInput, targetName) {
|
|
|
3358
2907
|
}
|
|
3359
2908
|
}
|
|
3360
2909
|
if (foundPort === -1) {
|
|
3361
|
-
output +=
|
|
2910
|
+
output += chalk.yellow(`\n[${attemptCount}] No MIDI device matching "${targetName}" found. Retrying in 1s...`);
|
|
3362
2911
|
}
|
|
3363
2912
|
setTerminalOutput(output);
|
|
3364
2913
|
if (foundPort === -1) {
|
|
@@ -3369,7 +2918,7 @@ async function connectMidiByName(midiInput, targetName) {
|
|
|
3369
2918
|
midiInput.openPort(foundPort);
|
|
3370
2919
|
return foundPort;
|
|
3371
2920
|
}
|
|
3372
|
-
function joinSet(set, joinText = ", ", itemToString = objectToString) {
|
|
2921
|
+
export function joinSet(set, joinText = ", ", itemToString = objectToString) {
|
|
3373
2922
|
let output = "";
|
|
3374
2923
|
if (set.size <= 0) {
|
|
3375
2924
|
return output;
|
|
@@ -3384,7 +2933,7 @@ function joinSet(set, joinText = ", ", itemToString = objectToString) {
|
|
|
3384
2933
|
}
|
|
3385
2934
|
return output;
|
|
3386
2935
|
}
|
|
3387
|
-
function verboseModText(originalText, modifications) {
|
|
2936
|
+
export function verboseModText(originalText, modifications) {
|
|
3388
2937
|
let text = originalText;
|
|
3389
2938
|
let oldText;
|
|
3390
2939
|
for (const modify of modifications) {
|
|
@@ -3393,52 +2942,51 @@ function verboseModText(originalText, modifications) {
|
|
|
3393
2942
|
}
|
|
3394
2943
|
return text;
|
|
3395
2944
|
}
|
|
3396
|
-
function printDifferenceIfDifferent(oldText, newText, prefix = "") {
|
|
2945
|
+
export function printDifferenceIfDifferent(oldText, newText, prefix = "") {
|
|
3397
2946
|
if (oldText !== newText) {
|
|
3398
2947
|
print(`${prefix}${highlightDifference(oldText, newText)}`);
|
|
3399
2948
|
}
|
|
3400
2949
|
return newText;
|
|
3401
2950
|
}
|
|
3402
|
-
function highlightDifference(oldText, newText) {
|
|
2951
|
+
export function highlightDifference(oldText, newText) {
|
|
3403
2952
|
if (oldText.includes(newText)) {
|
|
3404
2953
|
return yellowUnderline(modMatchAndNotMatch(oldText, newText));
|
|
3405
2954
|
}
|
|
3406
2955
|
else if (newText.includes(oldText)) {
|
|
3407
|
-
return greenUnderline(modMatchAndNotMatch(newText, oldText,
|
|
2956
|
+
return greenUnderline(modMatchAndNotMatch(newText, oldText, chalk.yellowBright, greenUnderlineBold));
|
|
3408
2957
|
}
|
|
3409
2958
|
else {
|
|
3410
|
-
return
|
|
2959
|
+
return chalk.yellowBright(`${redUnderline(oldText)}\nto\n${greenUnderlineBold(newText)}`);
|
|
3411
2960
|
}
|
|
3412
2961
|
}
|
|
3413
|
-
function toRegexpAsExactString(text, flags = "i") {
|
|
2962
|
+
export function toRegexpAsExactString(text, flags = "i") {
|
|
3414
2963
|
return new RegExp(`${text.replaceAll(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')}`, "i");
|
|
3415
2964
|
}
|
|
3416
|
-
function greenUnderlineBold(text) {
|
|
3417
|
-
return underlineBold(
|
|
2965
|
+
export function greenUnderlineBold(text) {
|
|
2966
|
+
return underlineBold(chalk.greenBright(text));
|
|
3418
2967
|
}
|
|
3419
|
-
function greenUnderline(text) {
|
|
3420
|
-
return
|
|
2968
|
+
export function greenUnderline(text) {
|
|
2969
|
+
return chalk.underline(chalk.greenBright(text));
|
|
3421
2970
|
}
|
|
3422
|
-
function redUnderlineBold(text) {
|
|
3423
|
-
return underlineBold(
|
|
2971
|
+
export function redUnderlineBold(text) {
|
|
2972
|
+
return underlineBold(chalk.redBright(text));
|
|
3424
2973
|
}
|
|
3425
|
-
function redUnderline(text) {
|
|
3426
|
-
return
|
|
2974
|
+
export function redUnderline(text) {
|
|
2975
|
+
return chalk.underline(chalk.redBright(text));
|
|
3427
2976
|
}
|
|
3428
|
-
function yellowUnderline(text) {
|
|
3429
|
-
return
|
|
2977
|
+
export function yellowUnderline(text) {
|
|
2978
|
+
return chalk.underline(chalk.yellowBright(text));
|
|
3430
2979
|
}
|
|
3431
|
-
function underlineBold(text) {
|
|
3432
|
-
return
|
|
2980
|
+
export function underlineBold(text) {
|
|
2981
|
+
return chalk.underline(chalk.bold(text));
|
|
3433
2982
|
}
|
|
3434
|
-
function modAllMatchAndNotMatch(fullText, partsToModify, insideTextModifier = greenUnderlineBold, outsideTextModifier = redUnderline) {
|
|
3435
|
-
var _a;
|
|
2983
|
+
export function modAllMatchAndNotMatch(fullText, partsToModify, insideTextModifier = greenUnderlineBold, outsideTextModifier = redUnderline) {
|
|
3436
2984
|
fullText = fullText.trim();
|
|
3437
2985
|
const regex = typeof partsToModify === "string" ? toRegexpAsExactString(partsToModify.trim(), "gi") : partsToModify;
|
|
3438
2986
|
let result = "";
|
|
3439
2987
|
let lastIndex = 0;
|
|
3440
2988
|
for (const match of fullText.matchAll(regex)) {
|
|
3441
|
-
const start =
|
|
2989
|
+
const start = match.index ?? 0;
|
|
3442
2990
|
const end = start + match[0].length;
|
|
3443
2991
|
result += outsideTextModifier(fullText.slice(lastIndex, start));
|
|
3444
2992
|
result += insideTextModifier(match[0]);
|
|
@@ -3447,15 +2995,14 @@ function modAllMatchAndNotMatch(fullText, partsToModify, insideTextModifier = gr
|
|
|
3447
2995
|
result += outsideTextModifier(fullText.slice(lastIndex));
|
|
3448
2996
|
return result;
|
|
3449
2997
|
}
|
|
3450
|
-
function modMatchAndNotMatch(fullText, partsToModify, insideTextModifier = greenUnderlineBold, outsideTextModifier = redUnderline) {
|
|
3451
|
-
var _a;
|
|
2998
|
+
export function modMatchAndNotMatch(fullText, partsToModify, insideTextModifier = greenUnderlineBold, outsideTextModifier = redUnderline) {
|
|
3452
2999
|
fullText = fullText.trim();
|
|
3453
3000
|
const regex = typeof partsToModify === "string" ? toRegexpAsExactString(partsToModify.trim(), "i") : partsToModify;
|
|
3454
3001
|
const match = fullText.match(regex);
|
|
3455
3002
|
if (!match) {
|
|
3456
3003
|
return outsideTextModifier(fullText);
|
|
3457
3004
|
}
|
|
3458
|
-
const start =
|
|
3005
|
+
const start = match.index ?? 0;
|
|
3459
3006
|
const end = start + match[0].length;
|
|
3460
3007
|
let result = "";
|
|
3461
3008
|
result += outsideTextModifier(fullText.slice(0, start));
|
|
@@ -3463,7 +3010,7 @@ function modMatchAndNotMatch(fullText, partsToModify, insideTextModifier = green
|
|
|
3463
3010
|
result += outsideTextModifier(fullText.slice(end));
|
|
3464
3011
|
return result;
|
|
3465
3012
|
}
|
|
3466
|
-
function createRunnableScriptFiles(scriptPath, scriptName, scriptCommand) {
|
|
3013
|
+
export function createRunnableScriptFiles(scriptPath, scriptName, scriptCommand) {
|
|
3467
3014
|
let wroteCount = 0;
|
|
3468
3015
|
let scriptCommandWindows = scriptCommand.replaceAll("/", "\\");
|
|
3469
3016
|
let scriptCommandLinux = scriptCommand.replaceAll("\\", "/");
|
|
@@ -3472,25 +3019,25 @@ function createRunnableScriptFiles(scriptPath, scriptName, scriptCommand) {
|
|
|
3472
3019
|
// .map(line => `call ${line}`)
|
|
3473
3020
|
// .join("\n")) ? 0 : 1
|
|
3474
3021
|
// wroteCount += writeFileSyncCheck(path.resolve(scriptPath, `${scriptName}_pause.bat`), `.\\${scriptName}.bat\nPAUSE`) ? 0 : 1
|
|
3475
|
-
wroteCount += writeFileSyncCheck(
|
|
3476
|
-
wroteCount += writeFileSyncCheck(
|
|
3477
|
-
let linuxScriptPath =
|
|
3022
|
+
wroteCount += writeFileSyncCheck(path.resolve(scriptPath, `${scriptName}.ps1`), scriptCommandWindows) ? 0 : 1;
|
|
3023
|
+
wroteCount += writeFileSyncCheck(path.resolve(scriptPath, `${scriptName}_pause.ps1`), `.\\${scriptName}.ps1\nPAUSE`) ? 0 : 1;
|
|
3024
|
+
let linuxScriptPath = path.resolve(scriptPath, `${scriptName}.sh`);
|
|
3478
3025
|
wroteCount += writeFileSyncCheck(linuxScriptPath, `#!/bin/bash\n${scriptCommandLinux}`) ? 0 : 1;
|
|
3479
3026
|
makeRunnable(linuxScriptPath);
|
|
3480
|
-
linuxScriptPath =
|
|
3481
|
-
wroteCount += writeFileSyncCheck(linuxScriptPath, `#!/bin/bash\n./${scriptName}.sh\n${
|
|
3027
|
+
linuxScriptPath = path.resolve(scriptPath, `${scriptName}_pause.sh`);
|
|
3028
|
+
wroteCount += writeFileSyncCheck(linuxScriptPath, `#!/bin/bash\n./${scriptName}.sh\n${PRESS_ENTER_TO_EXIT_SH}`) ? 0 : 1;
|
|
3482
3029
|
makeRunnable(linuxScriptPath);
|
|
3483
3030
|
return wroteCount;
|
|
3484
3031
|
}
|
|
3485
|
-
async function createProject(projectPath, projectName) {
|
|
3486
|
-
projectPath = projectPath.replaceAll(
|
|
3032
|
+
export async function createProject(projectPath, projectName) {
|
|
3033
|
+
projectPath = projectPath.replaceAll(SEPARATOR_REGEX, SEP);
|
|
3487
3034
|
mkdirSoftRecursive(projectPath);
|
|
3488
|
-
projectPath =
|
|
3489
|
-
const pathAlreadyExists =
|
|
3035
|
+
projectPath = path.resolve(projectPath, projectName);
|
|
3036
|
+
const pathAlreadyExists = existsSync(projectPath);
|
|
3490
3037
|
if (pathAlreadyExists) {
|
|
3491
|
-
const stat =
|
|
3038
|
+
const stat = statSync(projectPath);
|
|
3492
3039
|
if (!stat.isDirectory()) {
|
|
3493
|
-
print(
|
|
3040
|
+
print(chalk.redBright(`A file with the name "${projectPath.replaceAll(SEPARATOR_REGEX, SEP)}" already exists.`));
|
|
3494
3041
|
return false;
|
|
3495
3042
|
}
|
|
3496
3043
|
}
|
|
@@ -3503,92 +3050,91 @@ async function createProject(projectPath, projectName) {
|
|
|
3503
3050
|
newScriptsCount += createRunnableScriptFiles(projectPath, "brun", `${buildScript}\nnode ./build/index.js`);
|
|
3504
3051
|
newScriptsCount += createRunnableScriptFiles(projectPath, "update", `pnpm i ahegao@latest`);
|
|
3505
3052
|
if (pathAlreadyExists) {
|
|
3506
|
-
if (
|
|
3507
|
-
print(
|
|
3053
|
+
if (readdirSync(projectPath).length > 0) {
|
|
3054
|
+
print(chalk.yellowBright(`Project folder "${projectPath.replaceAll(SEPARATOR_REGEX, SEP)}" already exists.`));
|
|
3508
3055
|
if (newScriptsCount > 0) {
|
|
3509
|
-
print(
|
|
3056
|
+
print(chalk.greenBright(`Added ${newScriptsCount} script${sIfNot1(newScriptsCount)} to the existing folder!`));
|
|
3510
3057
|
}
|
|
3511
3058
|
return false;
|
|
3512
3059
|
}
|
|
3513
3060
|
}
|
|
3514
|
-
const vsCodePath =
|
|
3061
|
+
const vsCodePath = path.resolve(projectPath, ".vscode");
|
|
3515
3062
|
mkdirSoft(vsCodePath);
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3063
|
+
writeFileSync(path.resolve(vsCodePath, "launch.json"), VSCODE_TS_LAUNCH_JSON);
|
|
3064
|
+
writeFileSync(path.resolve(projectPath, "pnpm-workspace.yaml"), "dangerouslyAllowAllBuilds: true\n");
|
|
3065
|
+
writeFileSync(path.resolve(projectPath, "tsconfig.json"), TSCONFIG_JSON);
|
|
3519
3066
|
const options = { cwd: projectPath };
|
|
3520
|
-
await spawnLiveCmd(`pnpm`, ["init"], options);
|
|
3521
|
-
await spawnLiveCmd(`pnpm`, [`pkg`, `set`, `name=
|
|
3067
|
+
await spawnLiveCmd(`pnpm`, ["init", "--type", "module"], options);
|
|
3068
|
+
await spawnLiveCmd(`pnpm`, [`pkg`, `set`, `name='${projectName}'`, `version='1.0.0'`, `description='${projectName}'`], options);
|
|
3522
3069
|
await spawnLiveCmd(`pnpm`, ["add", "-D", "ts-node"], options);
|
|
3523
3070
|
await spawnLiveCmd(`pnpm`, ["add", "-D", "@types/node"], options);
|
|
3524
3071
|
await spawnLiveCmd(`pnpm`, ["add", "-D", "tsconfig-paths"], options);
|
|
3525
3072
|
await spawnLiveCmd(`pnpm`, [`i`, `ahegao@latest`], options);
|
|
3526
|
-
const srcPath =
|
|
3073
|
+
const srcPath = path.resolve(projectPath, "src");
|
|
3527
3074
|
mkdirSoft(srcPath);
|
|
3528
|
-
|
|
3529
|
-
print(
|
|
3075
|
+
writeFileSync(path.resolve(srcPath, "index.ts"), `import { print, chalk } from "ahegao/dist"\n\n`);
|
|
3076
|
+
print(chalk.greenBright(`Successfully created project "${projectPath}"!`));
|
|
3530
3077
|
return true;
|
|
3531
3078
|
}
|
|
3532
|
-
async function spawnLiveCmd(command, args =
|
|
3079
|
+
export async function spawnLiveCmd(command, args = EMPTY_ARRAY, options = EXEC_NO_WINDOWS) {
|
|
3533
3080
|
return spawnLive("cmd", ["/c", command, ...args], options);
|
|
3534
3081
|
}
|
|
3535
|
-
async function spawnLivePowershell(command, args =
|
|
3082
|
+
export async function spawnLivePowershell(command, args = EMPTY_ARRAY, options = EXEC_NO_WINDOWS) {
|
|
3536
3083
|
return spawnLive("powershell", ["/c", command, ...args], options);
|
|
3537
3084
|
}
|
|
3538
|
-
async function spawnLiveSilent(command, args =
|
|
3085
|
+
export async function spawnLiveSilent(command, args = EMPTY_ARRAY, options = EXEC_NO_WINDOWS) {
|
|
3539
3086
|
return spawnLive(command, args, options, false);
|
|
3540
3087
|
}
|
|
3541
|
-
async function spawnLive(command, args =
|
|
3088
|
+
export async function spawnLive(command, args = EMPTY_ARRAY, options = EXEC_NO_WINDOWS, verbose = true, onData = noop) {
|
|
3542
3089
|
return new Promise((resolve, reject) => {
|
|
3543
|
-
var _a, _b;
|
|
3544
3090
|
const identifier = `"${command} ${args.join(" ")}"`;
|
|
3545
3091
|
if (verbose) {
|
|
3546
|
-
print(
|
|
3092
|
+
print(chalk.blueBright(`Spawning process: ${identifier}`));
|
|
3547
3093
|
}
|
|
3548
|
-
const task =
|
|
3094
|
+
const task = spawn(command, args, options);
|
|
3549
3095
|
if (verbose) {
|
|
3550
|
-
|
|
3096
|
+
task.stdout?.on('data', (data) => {
|
|
3551
3097
|
const text = data.toString().trim();
|
|
3552
3098
|
onData(text, true);
|
|
3553
|
-
print(
|
|
3099
|
+
print(chalk.greenBright(text));
|
|
3554
3100
|
});
|
|
3555
|
-
|
|
3101
|
+
task.stderr?.on('data', (data) => {
|
|
3556
3102
|
const text = data.toString().trim();
|
|
3557
3103
|
onData(text, true);
|
|
3558
|
-
print(
|
|
3104
|
+
print(chalk.redBright(text));
|
|
3559
3105
|
});
|
|
3560
3106
|
}
|
|
3561
3107
|
task.on('error', (err) => {
|
|
3562
3108
|
if (verbose) {
|
|
3563
|
-
print(
|
|
3109
|
+
print(chalk.redBright(`${args}: Process error: ${err.message}`));
|
|
3564
3110
|
}
|
|
3565
3111
|
reject(err);
|
|
3566
3112
|
});
|
|
3567
3113
|
task.on('close', (code) => {
|
|
3568
3114
|
if (verbose) {
|
|
3569
|
-
const colorer = code === 0 ?
|
|
3115
|
+
const colorer = code === 0 ? chalk.greenBright : chalk.redBright;
|
|
3570
3116
|
print(colorer(`${identifier}: Process exited with code ${code}`));
|
|
3571
3117
|
}
|
|
3572
|
-
resolve(
|
|
3118
|
+
resolve(code?.toString() || "0");
|
|
3573
3119
|
});
|
|
3574
3120
|
});
|
|
3575
3121
|
}
|
|
3576
|
-
function isWindows() {
|
|
3577
|
-
return
|
|
3122
|
+
export function isWindows() {
|
|
3123
|
+
return platform() === "win32";
|
|
3578
3124
|
}
|
|
3579
|
-
function isMacOS() {
|
|
3580
|
-
return
|
|
3125
|
+
export function isMacOS() {
|
|
3126
|
+
return platform() === "darwin";
|
|
3581
3127
|
}
|
|
3582
|
-
function isLinux() {
|
|
3583
|
-
return
|
|
3128
|
+
export function isLinux() {
|
|
3129
|
+
return platform() === "linux";
|
|
3584
3130
|
}
|
|
3585
|
-
function isUnixLike() {
|
|
3131
|
+
export function isUnixLike() {
|
|
3586
3132
|
return isLinux() || isMacOS();
|
|
3587
3133
|
}
|
|
3588
|
-
function makeRunnable(filePath) {
|
|
3589
|
-
|
|
3134
|
+
export function makeRunnable(filePath) {
|
|
3135
|
+
chmodSync(filePath, '755');
|
|
3590
3136
|
}
|
|
3591
|
-
async function acceptUserInput(prefix = "") {
|
|
3137
|
+
export async function acceptUserInput(prefix = "") {
|
|
3592
3138
|
const rl = readline.createInterface({
|
|
3593
3139
|
input: process.stdin,
|
|
3594
3140
|
output: process.stdout
|
|
@@ -3600,19 +3146,19 @@ async function acceptUserInput(prefix = "") {
|
|
|
3600
3146
|
});
|
|
3601
3147
|
});
|
|
3602
3148
|
}
|
|
3603
|
-
function writeFileSyncCheck(filePath, data) {
|
|
3604
|
-
const existed =
|
|
3605
|
-
|
|
3149
|
+
export function writeFileSyncCheck(filePath, data) {
|
|
3150
|
+
const existed = existsSync(filePath);
|
|
3151
|
+
writeFileSync(filePath, data);
|
|
3606
3152
|
return existed;
|
|
3607
3153
|
}
|
|
3608
|
-
function isLibTs() {
|
|
3154
|
+
export function isLibTs() {
|
|
3609
3155
|
return __filename.endsWith("ts");
|
|
3610
3156
|
}
|
|
3611
|
-
function removeDuplicateLines(path) {
|
|
3157
|
+
export function removeDuplicateLines(path) {
|
|
3612
3158
|
const itemsSet = new Set();
|
|
3613
3159
|
const items = [];
|
|
3614
3160
|
const duplicateItems = new Set();
|
|
3615
|
-
for (const item of
|
|
3161
|
+
for (const item of readFileSync(path, "utf-8").split(/[\n\r]/)) {
|
|
3616
3162
|
if (item.length === 0) {
|
|
3617
3163
|
continue;
|
|
3618
3164
|
}
|
|
@@ -3624,46 +3170,46 @@ function removeDuplicateLines(path) {
|
|
|
3624
3170
|
items.push(item);
|
|
3625
3171
|
}
|
|
3626
3172
|
if (duplicateItems.size > 0) {
|
|
3627
|
-
|
|
3173
|
+
writeFileSync(path, items.join("\n"));
|
|
3628
3174
|
}
|
|
3629
3175
|
return duplicateItems;
|
|
3630
3176
|
}
|
|
3631
3177
|
//#region Audio
|
|
3632
|
-
function openCDTray() {
|
|
3178
|
+
export function openCDTray() {
|
|
3633
3179
|
if (process.platform === 'win32') {
|
|
3634
|
-
|
|
3180
|
+
exec('powershell (new-object -comObject WMPlayer.OCX.7).cdromCollection.item(0).Eject()');
|
|
3635
3181
|
}
|
|
3636
3182
|
else if (process.platform === 'darwin') {
|
|
3637
|
-
|
|
3183
|
+
exec('drutil tray eject');
|
|
3638
3184
|
}
|
|
3639
3185
|
else {
|
|
3640
|
-
|
|
3186
|
+
exec('eject');
|
|
3641
3187
|
}
|
|
3642
3188
|
}
|
|
3643
|
-
function closeCDTray() {
|
|
3189
|
+
export function closeCDTray() {
|
|
3644
3190
|
if (process.platform === 'win32') {
|
|
3645
|
-
|
|
3191
|
+
exec('powershell (new-object -comObject WMPlayer.OCX.7).cdromCollection.item(0).Eject()');
|
|
3646
3192
|
}
|
|
3647
3193
|
else if (process.platform === 'darwin') {
|
|
3648
|
-
|
|
3194
|
+
exec('drutil tray close');
|
|
3649
3195
|
}
|
|
3650
3196
|
else {
|
|
3651
|
-
|
|
3197
|
+
exec('eject -t');
|
|
3652
3198
|
}
|
|
3653
3199
|
}
|
|
3654
|
-
function toggleCDTray() {
|
|
3200
|
+
export function toggleCDTray() {
|
|
3655
3201
|
if (process.platform === 'win32') {
|
|
3656
|
-
|
|
3202
|
+
exec('powershell (new-object -comObject WMPlayer.OCX.7).cdromCollection.item(0).Eject()');
|
|
3657
3203
|
}
|
|
3658
3204
|
else if (process.platform === 'darwin') {
|
|
3659
|
-
|
|
3205
|
+
exec('drutil tray close || drutil tray eject');
|
|
3660
3206
|
}
|
|
3661
3207
|
else {
|
|
3662
|
-
|
|
3208
|
+
exec('eject -T');
|
|
3663
3209
|
}
|
|
3664
3210
|
}
|
|
3665
3211
|
const SPEECH_COUNT_THRESHOLD = 2;
|
|
3666
|
-
async function recordAudioUntilX(wavePath = "./recording.wav", bitrate = 48000, exitIfSilentForS = 0, maxRecordingLengthS = 0, channels = 1, debug = false) {
|
|
3212
|
+
export async function recordAudioUntilX(wavePath = "./recording.wav", bitrate = 48000, exitIfSilentForS = 0, maxRecordingLengthS = 0, channels = 1, debug = false) {
|
|
3667
3213
|
return new Promise((resolve, reject) => {
|
|
3668
3214
|
let stopOnSilence = maxRecordingLengthS <= 0;
|
|
3669
3215
|
let speechCount = 0;
|
|
@@ -3671,9 +3217,9 @@ async function recordAudioUntilX(wavePath = "./recording.wav", bitrate = 48000,
|
|
|
3671
3217
|
let forceStopTask = null;
|
|
3672
3218
|
const startTime = Date.now();
|
|
3673
3219
|
if (debug) {
|
|
3674
|
-
print(
|
|
3220
|
+
print(chalk.blueBright(`${timestampWithMs()} Starting recording~`));
|
|
3675
3221
|
}
|
|
3676
|
-
const micInstance = (
|
|
3222
|
+
const micInstance = mic({
|
|
3677
3223
|
rate: bitrate.toString(),
|
|
3678
3224
|
channels: channels.toString(),
|
|
3679
3225
|
debug,
|
|
@@ -3681,11 +3227,11 @@ async function recordAudioUntilX(wavePath = "./recording.wav", bitrate = 48000,
|
|
|
3681
3227
|
});
|
|
3682
3228
|
const micInputStream = micInstance.getAudioStream();
|
|
3683
3229
|
rmSoft(wavePath);
|
|
3684
|
-
const outputFileStream =
|
|
3230
|
+
const outputFileStream = createWriteStream(wavePath);
|
|
3685
3231
|
micInputStream.pipe(outputFileStream);
|
|
3686
3232
|
micInstance.start();
|
|
3687
3233
|
micInputStream.on("error", (err) => {
|
|
3688
|
-
print(
|
|
3234
|
+
print(chalk.redBright(`${timestampWithMs()} Error in Input Stream: ${err}`));
|
|
3689
3235
|
micInstance.stop();
|
|
3690
3236
|
outputFileStream.end();
|
|
3691
3237
|
if (stopOnSilenceTask != null) {
|
|
@@ -3700,7 +3246,7 @@ async function recordAudioUntilX(wavePath = "./recording.wav", bitrate = 48000,
|
|
|
3700
3246
|
if (SPEECH_COUNT_THRESHOLD <= speechCount) {
|
|
3701
3247
|
if (stopOnSilence) {
|
|
3702
3248
|
if (debug) {
|
|
3703
|
-
print(
|
|
3249
|
+
print(chalk.yellowBright(`${timestampWithMs()} Silence detected, stopping recording...`));
|
|
3704
3250
|
}
|
|
3705
3251
|
micInstance.stop();
|
|
3706
3252
|
}
|
|
@@ -3715,7 +3261,7 @@ async function recordAudioUntilX(wavePath = "./recording.wav", bitrate = 48000,
|
|
|
3715
3261
|
});
|
|
3716
3262
|
micInputStream.on("stopComplete", () => {
|
|
3717
3263
|
if (debug) {
|
|
3718
|
-
print(
|
|
3264
|
+
print(chalk.blueBright(`${timestampWithMs()} Finished recording ${(statSync(wavePath).size / 1024).toFixed(2)}kb in ${Date.now() - startTime}ms! Saved to: ${wavePath}`));
|
|
3719
3265
|
}
|
|
3720
3266
|
if (stopOnSilenceTask != null) {
|
|
3721
3267
|
clearTimeout(stopOnSilenceTask);
|
|
@@ -3739,7 +3285,7 @@ async function recordAudioUntilX(wavePath = "./recording.wav", bitrate = 48000,
|
|
|
3739
3285
|
}
|
|
3740
3286
|
});
|
|
3741
3287
|
}
|
|
3742
|
-
function createSherpaCanaryOfflineSpeechRecognizer(encoderPath, decoderPath, tokensPath, sourceLanguage = "en", targetLanguage = "en", debug = false) {
|
|
3288
|
+
export function createSherpaCanaryOfflineSpeechRecognizer(encoderPath, decoderPath, tokensPath, sourceLanguage = "en", targetLanguage = "en", debug = false) {
|
|
3743
3289
|
const config = {
|
|
3744
3290
|
modelConfig: {
|
|
3745
3291
|
canary: {
|
|
@@ -3755,46 +3301,46 @@ function createSherpaCanaryOfflineSpeechRecognizer(encoderPath, decoderPath, tok
|
|
|
3755
3301
|
};
|
|
3756
3302
|
return createSherpaOfflineSpeechRecognizer(config, debug);
|
|
3757
3303
|
}
|
|
3758
|
-
function createSherpaOfflineSpeechRecognizer(config, debug = false) {
|
|
3304
|
+
export function createSherpaOfflineSpeechRecognizer(config, debug = false) {
|
|
3759
3305
|
let timer = null;
|
|
3760
3306
|
if (debug) {
|
|
3761
|
-
timer = new
|
|
3762
|
-
console.log(
|
|
3307
|
+
timer = new Timer();
|
|
3308
|
+
console.log(chalk.yellowBright(`Loading Offline Speech Recognition Model...\n${stringify(config)}`));
|
|
3763
3309
|
}
|
|
3764
|
-
const recognizer =
|
|
3310
|
+
const recognizer = sherpa_onnx.createOfflineRecognizer(config);
|
|
3765
3311
|
if (debug) {
|
|
3766
|
-
console.log(
|
|
3312
|
+
console.log(chalk.greenBright(`Model loaded in ${timer.elapsedS}s!`));
|
|
3767
3313
|
}
|
|
3768
3314
|
return recognizer;
|
|
3769
3315
|
}
|
|
3770
|
-
function isTerminalAvailable() {
|
|
3316
|
+
export function isTerminalAvailable() {
|
|
3771
3317
|
return process.stdout.isTTY && process.stdin.isTTY;
|
|
3772
3318
|
}
|
|
3773
|
-
function interpretWave(recognizer, waveFilePath, debug = false) {
|
|
3774
|
-
const timer = new
|
|
3319
|
+
export function interpretWave(recognizer, waveFilePath, debug = false) {
|
|
3320
|
+
const timer = new Timer();
|
|
3775
3321
|
if (debug) {
|
|
3776
|
-
console.log(
|
|
3322
|
+
console.log(chalk.yellowBright(`Reading samples from ${waveFilePath}...`));
|
|
3777
3323
|
timer.reset();
|
|
3778
3324
|
}
|
|
3779
3325
|
const stream = recognizer.createStream();
|
|
3780
|
-
const wave =
|
|
3326
|
+
const wave = sherpa_onnx.readWave(waveFilePath);
|
|
3781
3327
|
stream.acceptWaveform(wave.sampleRate, wave.samples);
|
|
3782
3328
|
if (debug) {
|
|
3783
|
-
console.log(
|
|
3784
|
-
console.log(
|
|
3329
|
+
console.log(chalk.greenBright(`Accepted ${wave.samples.length} samples in ${timer.elapsedS}s!`));
|
|
3330
|
+
console.log(chalk.yellowBright(`Recognizing Speech...`));
|
|
3785
3331
|
timer.reset();
|
|
3786
3332
|
}
|
|
3787
3333
|
recognizer.decode(stream);
|
|
3788
3334
|
const speech = recognizer.getResult(stream).text.trim();
|
|
3789
3335
|
if (debug) {
|
|
3790
|
-
console.log(
|
|
3336
|
+
console.log(chalk.greenBright(`Recognized "${chalk.magentaBright(chalk.bold(speech))}" in ${timer.elapsedS}s!`));
|
|
3791
3337
|
}
|
|
3792
3338
|
stream.free();
|
|
3793
3339
|
return speech;
|
|
3794
3340
|
}
|
|
3795
|
-
async function getAudioFileDuration(filePath) {
|
|
3341
|
+
export async function getAudioFileDuration(filePath) {
|
|
3796
3342
|
return new Promise((resolve, reject) => {
|
|
3797
|
-
|
|
3343
|
+
exec(`ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${filePath}"`, (error, stdout) => {
|
|
3798
3344
|
if (error) {
|
|
3799
3345
|
reject(error);
|
|
3800
3346
|
}
|
|
@@ -3806,27 +3352,27 @@ async function getAudioFileDuration(filePath) {
|
|
|
3806
3352
|
}
|
|
3807
3353
|
//#endregion Audio
|
|
3808
3354
|
let DEBUG_PATHS = false;
|
|
3809
|
-
function getDebugPaths() {
|
|
3355
|
+
export function getDebugPaths() {
|
|
3810
3356
|
return DEBUG_PATHS;
|
|
3811
3357
|
}
|
|
3812
|
-
function setDebugPaths(value) {
|
|
3358
|
+
export function setDebugPaths(value) {
|
|
3813
3359
|
DEBUG_PATHS = value;
|
|
3814
3360
|
}
|
|
3815
|
-
function dogPaths(text) {
|
|
3361
|
+
export function dogPaths(text) {
|
|
3816
3362
|
if (DEBUG_PATHS) {
|
|
3817
3363
|
print(text);
|
|
3818
3364
|
}
|
|
3819
3365
|
}
|
|
3820
|
-
function getTempPath() {
|
|
3366
|
+
export function getTempPath() {
|
|
3821
3367
|
return process.env.TEMP || process.env.TMPDIR || process.env.TMP || require("os").tmpdir();
|
|
3822
3368
|
}
|
|
3823
|
-
function patchMicLib(libPath = "./node_modules/mic/lib/mic.js") {
|
|
3369
|
+
export function patchMicLib(libPath = "./node_modules/mic/lib/mic.js") {
|
|
3824
3370
|
try {
|
|
3825
|
-
if (!
|
|
3826
|
-
print(
|
|
3371
|
+
if (!existsSync(libPath)) {
|
|
3372
|
+
print(chalk.redBright(`Mic lib path does not exist, cannot patch: ${path.resolve(libPath)}`));
|
|
3827
3373
|
return false;
|
|
3828
3374
|
}
|
|
3829
|
-
const micLibFile =
|
|
3375
|
+
const micLibFile = readFileSync(libPath, "utf-8");
|
|
3830
3376
|
const patchedMicLibFile = micLibFile.replace(`var audioProcessOptions = {
|
|
3831
3377
|
stdio: ['ignore', 'pipe', 'ignore']
|
|
3832
3378
|
};`, `var audioProcessOptions = {
|
|
@@ -3834,20 +3380,23 @@ function patchMicLib(libPath = "./node_modules/mic/lib/mic.js") {
|
|
|
3834
3380
|
windowsHide: true,
|
|
3835
3381
|
};`);
|
|
3836
3382
|
if (micLibFile !== patchedMicLibFile) {
|
|
3837
|
-
print(
|
|
3838
|
-
|
|
3839
|
-
print(
|
|
3383
|
+
print(chalk.yellowBright(`Patching mic lib to hide windows terminal... ${path.resolve(libPath)}`));
|
|
3384
|
+
writeFileSync(libPath, patchedMicLibFile, "utf-8");
|
|
3385
|
+
print(chalk.greenBright(`Patched mic lib successfully!`));
|
|
3840
3386
|
return true;
|
|
3841
3387
|
}
|
|
3842
3388
|
}
|
|
3843
3389
|
catch (e) {
|
|
3844
|
-
print(
|
|
3390
|
+
print(chalk.redBright(`Failed to patch mic lib: ${e}`));
|
|
3845
3391
|
}
|
|
3846
3392
|
return false;
|
|
3847
3393
|
}
|
|
3848
|
-
async function softSyncGitRepo(repoInfo) {
|
|
3394
|
+
export async function softSyncGitRepo(repoInfo) {
|
|
3849
3395
|
try {
|
|
3850
|
-
const options =
|
|
3396
|
+
const options = {
|
|
3397
|
+
...EXEC_NO_WINDOWS,
|
|
3398
|
+
cwd: repoInfo.path,
|
|
3399
|
+
};
|
|
3851
3400
|
const stopIfFailed = (response) => {
|
|
3852
3401
|
if (response !== "0") {
|
|
3853
3402
|
return true;
|
|
@@ -3864,10 +3413,9 @@ async function softSyncGitRepo(repoInfo) {
|
|
|
3864
3413
|
return;
|
|
3865
3414
|
if (stopIfFailed(await spawnLive(`git`, [`push`], options, false)))
|
|
3866
3415
|
return;
|
|
3867
|
-
print(
|
|
3416
|
+
print(chalk.greenBright(`Successfully synced repository: ${repoInfo.path}`));
|
|
3868
3417
|
}
|
|
3869
3418
|
catch (e) {
|
|
3870
3419
|
printError(`Failed to sync repository at: ${repoInfo.path}\n${e}`);
|
|
3871
3420
|
}
|
|
3872
3421
|
}
|
|
3873
|
-
//# sourceMappingURL=util.js.map
|