bare-script 3.8.14 → 3.8.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/library.js +69 -1
- package/package.json +1 -1
package/lib/library.js
CHANGED
|
@@ -281,6 +281,21 @@ const arrayPushArgs = valueArgsModel([
|
|
|
281
281
|
]);
|
|
282
282
|
|
|
283
283
|
|
|
284
|
+
// $function: arrayReverse
|
|
285
|
+
// $group: array
|
|
286
|
+
// $doc: Reverse an array in place
|
|
287
|
+
// $arg array: The array
|
|
288
|
+
// $return: The reversed array
|
|
289
|
+
function arrayReverse(args) {
|
|
290
|
+
const [array] = valueArgsValidate(arrayReverseArgs, args);
|
|
291
|
+
return array.reverse();
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const arrayReverseArgs = valueArgsModel([
|
|
295
|
+
{'name': 'array', 'type': 'array'}
|
|
296
|
+
]);
|
|
297
|
+
|
|
298
|
+
|
|
284
299
|
// $function: arraySet
|
|
285
300
|
// $group: array
|
|
286
301
|
// $doc: Set an array element value
|
|
@@ -352,7 +367,7 @@ const arraySliceArgs = valueArgsModel([
|
|
|
352
367
|
|
|
353
368
|
// $function: arraySort
|
|
354
369
|
// $group: array
|
|
355
|
-
// $doc: Sort an array
|
|
370
|
+
// $doc: Sort an array in place
|
|
356
371
|
// $arg array: The array
|
|
357
372
|
// $arg compareFn: Optional (default is null). The comparison function.
|
|
358
373
|
// $return: The sorted array
|
|
@@ -1175,6 +1190,23 @@ const numberToFixedArgs = valueArgsModel([
|
|
|
1175
1190
|
const rNumberCleanup = /\.0*$/;
|
|
1176
1191
|
|
|
1177
1192
|
|
|
1193
|
+
// $function: numberToString
|
|
1194
|
+
// $group: number
|
|
1195
|
+
// $doc: Convert an integer to a string
|
|
1196
|
+
// $arg x: The integer
|
|
1197
|
+
// $arg radix: Optional (default is 10). The number base.
|
|
1198
|
+
// $return: The integer as a string of the given base
|
|
1199
|
+
function numberToString(args) {
|
|
1200
|
+
const [x, radix] = valueArgsValidate(numberToStringArgs, args);
|
|
1201
|
+
return x.toString(radix);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
const numberToStringArgs = valueArgsModel([
|
|
1205
|
+
{'name': 'x', 'type': 'number', 'integer': true, 'gte': 0},
|
|
1206
|
+
{'name': 'radix', 'type': 'number', 'default': 10, 'integer': true, 'gte': 2, 'lte': 36}
|
|
1207
|
+
]);
|
|
1208
|
+
|
|
1209
|
+
|
|
1178
1210
|
//
|
|
1179
1211
|
// Object functions
|
|
1180
1212
|
//
|
|
@@ -1624,6 +1656,38 @@ const stringCharCodeAtArgs = valueArgsModel([
|
|
|
1624
1656
|
]);
|
|
1625
1657
|
|
|
1626
1658
|
|
|
1659
|
+
// $function: stringDecode
|
|
1660
|
+
// $group: string
|
|
1661
|
+
// $doc: Decode a UTF-8 byte value array to a string
|
|
1662
|
+
// $arg bytes: The UTF-8 byte array
|
|
1663
|
+
// $return: The string
|
|
1664
|
+
function stringDecode(args) {
|
|
1665
|
+
const [bytes] = valueArgsValidate(stringDecodeArgs, args);
|
|
1666
|
+
const utf8Decoder = new TextDecoder();
|
|
1667
|
+
return utf8Decoder.decode(new Uint8Array(bytes));
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
const stringDecodeArgs = valueArgsModel([
|
|
1671
|
+
{'name': 'bytes', 'type': 'array'}
|
|
1672
|
+
]);
|
|
1673
|
+
|
|
1674
|
+
|
|
1675
|
+
// $function: stringEncode
|
|
1676
|
+
// $group: string
|
|
1677
|
+
// $doc: Encode a string as a UTF-8 byte value array
|
|
1678
|
+
// $arg string: The string
|
|
1679
|
+
// $return: The UTF-8 byte array
|
|
1680
|
+
function stringEncode(args) {
|
|
1681
|
+
const [string] = valueArgsValidate(stringEncodeArgs, args);
|
|
1682
|
+
const utf8Encoder = new TextEncoder();
|
|
1683
|
+
return [...utf8Encoder.encode(string)];
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
const stringEncodeArgs = valueArgsModel([
|
|
1687
|
+
{'name': 'string', 'type': 'string'}
|
|
1688
|
+
]);
|
|
1689
|
+
|
|
1690
|
+
|
|
1627
1691
|
// $function: stringEndsWith
|
|
1628
1692
|
// $group: string
|
|
1629
1693
|
// $doc: Determine if a string ends with a search string
|
|
@@ -2183,6 +2247,7 @@ export const scriptFunctions = {
|
|
|
2183
2247
|
arrayNewSize,
|
|
2184
2248
|
arrayPop,
|
|
2185
2249
|
arrayPush,
|
|
2250
|
+
arrayReverse,
|
|
2186
2251
|
arraySet,
|
|
2187
2252
|
arrayShift,
|
|
2188
2253
|
arraySlice,
|
|
@@ -2235,6 +2300,7 @@ export const scriptFunctions = {
|
|
|
2235
2300
|
numberParseFloat,
|
|
2236
2301
|
numberParseInt,
|
|
2237
2302
|
numberToFixed,
|
|
2303
|
+
numberToString,
|
|
2238
2304
|
objectAssign,
|
|
2239
2305
|
objectCopy,
|
|
2240
2306
|
objectDelete,
|
|
@@ -2255,6 +2321,8 @@ export const scriptFunctions = {
|
|
|
2255
2321
|
schemaValidate,
|
|
2256
2322
|
schemaValidateTypeModel,
|
|
2257
2323
|
stringCharCodeAt,
|
|
2324
|
+
stringDecode,
|
|
2325
|
+
stringEncode,
|
|
2258
2326
|
stringEndsWith,
|
|
2259
2327
|
stringFromCharCode,
|
|
2260
2328
|
stringIndexOf,
|