bare-script 3.0.11 → 3.0.13
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 +35 -16
- package/lib/value.js +9 -3
- package/package.json +3 -3
package/lib/library.js
CHANGED
|
@@ -40,6 +40,26 @@ const arrayCopyArgs = valueArgsModel([
|
|
|
40
40
|
]);
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
// $function: arrayDelete
|
|
44
|
+
// $group: Array
|
|
45
|
+
// $doc: Delete an array element
|
|
46
|
+
// $arg array: The array
|
|
47
|
+
// $arg index: The index of the element to delete
|
|
48
|
+
function arrayDelete(args) {
|
|
49
|
+
const [array, index] = valueArgsValidate(arrayDeleteArgs, args);
|
|
50
|
+
if (index >= array.length) {
|
|
51
|
+
throw new ValueArgsError('index', index);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
array.splice(index, 1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const arrayDeleteArgs = valueArgsModel([
|
|
58
|
+
{'name': 'array', 'type': 'array'},
|
|
59
|
+
{'name': 'index', 'type': 'number', 'integer': true, 'gte': 0}
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
|
|
43
63
|
// $function: arrayExtend
|
|
44
64
|
// $group: Array
|
|
45
65
|
// $doc: Extend one array with another
|
|
@@ -2016,21 +2036,20 @@ function systemType([value = null]) {
|
|
|
2016
2036
|
// $group: URL
|
|
2017
2037
|
// $doc: Encode a URL
|
|
2018
2038
|
// $arg url: The URL string
|
|
2019
|
-
// $arg extra: Optional (default is true). If true, encode extra characters for wider compatibility.
|
|
2020
2039
|
// $return: The encoded URL string
|
|
2021
2040
|
function urlEncode(args) {
|
|
2022
|
-
const [url
|
|
2041
|
+
const [url] = valueArgsValidate(urlEncodeArgs, args);
|
|
2023
2042
|
let urlEncoded = encodeURI(url);
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2043
|
+
|
|
2044
|
+
// Encode '(' and ')' (for Markdown links)
|
|
2045
|
+
urlEncoded = urlEncoded.replaceAll('(', '%28');
|
|
2046
|
+
urlEncoded = urlEncoded.replaceAll(')', '%29');
|
|
2047
|
+
|
|
2028
2048
|
return urlEncoded;
|
|
2029
2049
|
}
|
|
2030
2050
|
|
|
2031
2051
|
const urlEncodeArgs = valueArgsModel([
|
|
2032
|
-
{'name': 'url', 'type': 'string'}
|
|
2033
|
-
{'name': 'extra', 'type': 'boolean', 'default': true}
|
|
2052
|
+
{'name': 'url', 'type': 'string'}
|
|
2034
2053
|
]);
|
|
2035
2054
|
|
|
2036
2055
|
|
|
@@ -2038,27 +2057,27 @@ const urlEncodeArgs = valueArgsModel([
|
|
|
2038
2057
|
// $group: URL
|
|
2039
2058
|
// $doc: Encode a URL component
|
|
2040
2059
|
// $arg url: The URL component string
|
|
2041
|
-
// $arg extra: Optional (default is true). If true, encode extra characters for wider compatibility.
|
|
2042
2060
|
// $return: The encoded URL component string
|
|
2043
2061
|
function urlEncodeComponent(args) {
|
|
2044
|
-
const [url
|
|
2062
|
+
const [url] = valueArgsValidate(urlEncodeComponentArgs, args);
|
|
2045
2063
|
let urlEncoded = encodeURIComponent(url);
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2064
|
+
|
|
2065
|
+
// Encode '(' and ')' (for Markdown links)
|
|
2066
|
+
urlEncoded = urlEncoded.replaceAll('(', '%28');
|
|
2067
|
+
urlEncoded = urlEncoded.replaceAll(')', '%29');
|
|
2068
|
+
|
|
2050
2069
|
return urlEncoded;
|
|
2051
2070
|
}
|
|
2052
2071
|
|
|
2053
2072
|
const urlEncodeComponentArgs = valueArgsModel([
|
|
2054
|
-
{'name': 'url', 'type': 'string'}
|
|
2055
|
-
{'name': 'extra', 'type': 'boolean', 'default': true}
|
|
2073
|
+
{'name': 'url', 'type': 'string'}
|
|
2056
2074
|
]);
|
|
2057
2075
|
|
|
2058
2076
|
|
|
2059
2077
|
// The built-in script functions
|
|
2060
2078
|
export const scriptFunctions = {
|
|
2061
2079
|
arrayCopy,
|
|
2080
|
+
arrayDelete,
|
|
2062
2081
|
arrayExtend,
|
|
2063
2082
|
arrayGet,
|
|
2064
2083
|
arrayIndexOf,
|
package/lib/value.js
CHANGED
|
@@ -313,7 +313,7 @@ export function valueArgsValidate(fnArgs, args, errorReturnValue = null) {
|
|
|
313
313
|
|
|
314
314
|
// Extra arguments?
|
|
315
315
|
if (args.length > fnArgsLength) {
|
|
316
|
-
args.
|
|
316
|
+
throw new ValueArgsError(null, args.length, errorReturnValue);
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
return args;
|
|
@@ -331,12 +331,18 @@ export class ValueArgsError extends Error {
|
|
|
331
331
|
/**
|
|
332
332
|
* Create a BareScript runtime error
|
|
333
333
|
*
|
|
334
|
-
* @param {string} argName - The function argument name
|
|
334
|
+
* @param {string} argName - The function argument name. If `arg_name` is null, there are too many arguments,
|
|
335
|
+
* and `arg_value` is the number of arguments.
|
|
335
336
|
* @param {*} argValue - The function argument value
|
|
336
337
|
* @param {*} [returnValue = null] - The function's error return value
|
|
337
338
|
*/
|
|
338
339
|
constructor(argName, argValue, returnValue = null) {
|
|
339
|
-
|
|
340
|
+
let message;
|
|
341
|
+
if (argName === null) {
|
|
342
|
+
message = `Too many arguments (${valueJSON(argValue)})`;
|
|
343
|
+
} else {
|
|
344
|
+
message = `Invalid "${argName}" argument value, ${valueJSON(argValue)}`;
|
|
345
|
+
}
|
|
340
346
|
super(message);
|
|
341
347
|
this.name = this.constructor.name;
|
|
342
348
|
this.returnValue = returnValue;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "bare-script",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.13",
|
|
5
5
|
"description": "BareScript; a lightweight scripting and expression language",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"expression",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"schema-markdown": "~1.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"c8": "~
|
|
34
|
-
"eslint": "~9.
|
|
33
|
+
"c8": "~10.1",
|
|
34
|
+
"eslint": "~9.14",
|
|
35
35
|
"jsdoc": "~4.0"
|
|
36
36
|
}
|
|
37
37
|
}
|