bare-script 3.0.11 → 3.0.12
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 +14 -16
- package/lib/value.js +9 -3
- package/package.json +3 -3
package/lib/library.js
CHANGED
|
@@ -2016,21 +2016,20 @@ function systemType([value = null]) {
|
|
|
2016
2016
|
// $group: URL
|
|
2017
2017
|
// $doc: Encode a URL
|
|
2018
2018
|
// $arg url: The URL string
|
|
2019
|
-
// $arg extra: Optional (default is true). If true, encode extra characters for wider compatibility.
|
|
2020
2019
|
// $return: The encoded URL string
|
|
2021
2020
|
function urlEncode(args) {
|
|
2022
|
-
const [url
|
|
2021
|
+
const [url] = valueArgsValidate(urlEncodeArgs, args);
|
|
2023
2022
|
let urlEncoded = encodeURI(url);
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2023
|
+
|
|
2024
|
+
// Encode '(' and ')' (for Markdown links)
|
|
2025
|
+
urlEncoded = urlEncoded.replaceAll('(', '%28');
|
|
2026
|
+
urlEncoded = urlEncoded.replaceAll(')', '%29');
|
|
2027
|
+
|
|
2028
2028
|
return urlEncoded;
|
|
2029
2029
|
}
|
|
2030
2030
|
|
|
2031
2031
|
const urlEncodeArgs = valueArgsModel([
|
|
2032
|
-
{'name': 'url', 'type': 'string'}
|
|
2033
|
-
{'name': 'extra', 'type': 'boolean', 'default': true}
|
|
2032
|
+
{'name': 'url', 'type': 'string'}
|
|
2034
2033
|
]);
|
|
2035
2034
|
|
|
2036
2035
|
|
|
@@ -2038,21 +2037,20 @@ const urlEncodeArgs = valueArgsModel([
|
|
|
2038
2037
|
// $group: URL
|
|
2039
2038
|
// $doc: Encode a URL component
|
|
2040
2039
|
// $arg url: The URL component string
|
|
2041
|
-
// $arg extra: Optional (default is true). If true, encode extra characters for wider compatibility.
|
|
2042
2040
|
// $return: The encoded URL component string
|
|
2043
2041
|
function urlEncodeComponent(args) {
|
|
2044
|
-
const [url
|
|
2042
|
+
const [url] = valueArgsValidate(urlEncodeComponentArgs, args);
|
|
2045
2043
|
let urlEncoded = encodeURIComponent(url);
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2044
|
+
|
|
2045
|
+
// Encode '(' and ')' (for Markdown links)
|
|
2046
|
+
urlEncoded = urlEncoded.replaceAll('(', '%28');
|
|
2047
|
+
urlEncoded = urlEncoded.replaceAll(')', '%29');
|
|
2048
|
+
|
|
2050
2049
|
return urlEncoded;
|
|
2051
2050
|
}
|
|
2052
2051
|
|
|
2053
2052
|
const urlEncodeComponentArgs = valueArgsModel([
|
|
2054
|
-
{'name': 'url', 'type': 'string'}
|
|
2055
|
-
{'name': 'extra', 'type': 'boolean', 'default': true}
|
|
2053
|
+
{'name': 'url', 'type': 'string'}
|
|
2056
2054
|
]);
|
|
2057
2055
|
|
|
2058
2056
|
|
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.12",
|
|
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.9",
|
|
35
35
|
"jsdoc": "~4.0"
|
|
36
36
|
}
|
|
37
37
|
}
|