bare-script 2.2.1 → 2.2.3
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 +23 -23
- package/package.json +2 -2
package/lib/library.js
CHANGED
|
@@ -28,7 +28,7 @@ export const scriptFunctions = {
|
|
|
28
28
|
// $doc: Create a copy of an array
|
|
29
29
|
// $arg array: The array to copy
|
|
30
30
|
// $return: The array copy
|
|
31
|
-
'arrayCopy': ([array]) => (Array.isArray(array) ? [...array] :
|
|
31
|
+
'arrayCopy': ([array]) => (Array.isArray(array) ? [...array] : []),
|
|
32
32
|
|
|
33
33
|
// $function: arrayExtend
|
|
34
34
|
// $group: Array
|
|
@@ -37,10 +37,9 @@ export const scriptFunctions = {
|
|
|
37
37
|
// $arg array2: The array to extend with
|
|
38
38
|
// $return: The extended array
|
|
39
39
|
'arrayExtend': ([array, array2]) => {
|
|
40
|
-
if (
|
|
41
|
-
|
|
40
|
+
if (Array.isArray(array) && Array.isArray(array2)) {
|
|
41
|
+
array.push(...array2);
|
|
42
42
|
}
|
|
43
|
-
array.push(...array2);
|
|
44
43
|
return array;
|
|
45
44
|
},
|
|
46
45
|
|
|
@@ -59,7 +58,7 @@ export const scriptFunctions = {
|
|
|
59
58
|
// $arg value: The value to find in the array
|
|
60
59
|
// $arg index: Optional (default is 0). The index at which to start the search.
|
|
61
60
|
// $return: The first index of the value in the array; -1 if not found.
|
|
62
|
-
'arrayIndexOf': ([array, value, index = 0]) => (Array.isArray(array) ? array.indexOf(value, index) :
|
|
61
|
+
'arrayIndexOf': ([array, value, index = 0]) => (Array.isArray(array) ? array.indexOf(value, index) : -1),
|
|
63
62
|
|
|
64
63
|
// $function: arrayJoin
|
|
65
64
|
// $group: Array
|
|
@@ -67,7 +66,7 @@ export const scriptFunctions = {
|
|
|
67
66
|
// $arg array: The array
|
|
68
67
|
// $arg separator: The separator string
|
|
69
68
|
// $return: The joined string
|
|
70
|
-
'arrayJoin': ([array, separator]) => (Array.isArray(array) ? array.join(separator) :
|
|
69
|
+
'arrayJoin': ([array, separator]) => (Array.isArray(array) ? array.join(separator) : ''),
|
|
71
70
|
|
|
72
71
|
// $function: arrayLastIndexOf
|
|
73
72
|
// $group: Array
|
|
@@ -77,14 +76,14 @@ export const scriptFunctions = {
|
|
|
77
76
|
// $arg index: Optional (default is the end of the array). The index at which to start the search.
|
|
78
77
|
// $return: The last index of the value in the array; -1 if not found.
|
|
79
78
|
'arrayLastIndexOf': ([array, value, index = null]) => (
|
|
80
|
-
Array.isArray(array) ? (index === null ? array.lastIndexOf(value) : array.lastIndexOf(value, index)) :
|
|
79
|
+
Array.isArray(array) ? (index === null ? array.lastIndexOf(value) : array.lastIndexOf(value, index)) : -1
|
|
81
80
|
),
|
|
82
81
|
|
|
83
82
|
// $function: arrayLength
|
|
84
83
|
// $group: Array
|
|
85
84
|
// $doc: Get the length of an array
|
|
86
85
|
// $arg array: The array
|
|
87
|
-
// $return: The array's length
|
|
86
|
+
// $return: The array's length; null if not an array
|
|
88
87
|
'arrayLength': ([array]) => (Array.isArray(array) ? array.length : null),
|
|
89
88
|
|
|
90
89
|
// $function: arrayNew
|
|
@@ -114,8 +113,13 @@ export const scriptFunctions = {
|
|
|
114
113
|
// $doc: Add one or more values to the end of the array
|
|
115
114
|
// $arg array: The array
|
|
116
115
|
// $arg values: The values to add to the end of the array
|
|
117
|
-
// $return: The
|
|
118
|
-
'arrayPush': ([array, ...values]) =>
|
|
116
|
+
// $return: The array
|
|
117
|
+
'arrayPush': ([array, ...values]) => {
|
|
118
|
+
if (Array.isArray(array)) {
|
|
119
|
+
array.push(...values);
|
|
120
|
+
}
|
|
121
|
+
return array;
|
|
122
|
+
},
|
|
119
123
|
|
|
120
124
|
// $function: arraySet
|
|
121
125
|
// $group: Array
|
|
@@ -127,9 +131,8 @@ export const scriptFunctions = {
|
|
|
127
131
|
'arraySet': ([array, index, value]) => {
|
|
128
132
|
if (Array.isArray(array)) {
|
|
129
133
|
array[index] = value;
|
|
130
|
-
return value;
|
|
131
134
|
}
|
|
132
|
-
return
|
|
135
|
+
return value;
|
|
133
136
|
},
|
|
134
137
|
|
|
135
138
|
// $function: arraySlice
|
|
@@ -568,9 +571,9 @@ export const scriptFunctions = {
|
|
|
568
571
|
'objectAssign': ([object, object2]) => {
|
|
569
572
|
if (object !== null && typeof object === 'object' && !Array.isArray(object) &&
|
|
570
573
|
object2 !== null && typeof object2 === 'object' && !Array.isArray(object2)) {
|
|
571
|
-
|
|
574
|
+
Object.assign(object, object2);
|
|
572
575
|
}
|
|
573
|
-
return
|
|
576
|
+
return object;
|
|
574
577
|
},
|
|
575
578
|
|
|
576
579
|
// $function: objectCopy
|
|
@@ -578,7 +581,7 @@ export const scriptFunctions = {
|
|
|
578
581
|
// $doc: Create a copy of an object
|
|
579
582
|
// $arg object: The object to copy
|
|
580
583
|
// $return: The object copy
|
|
581
|
-
'objectCopy': ([object]) => (object !== null && typeof object === 'object' && !Array.isArray(object) ? {...object} :
|
|
584
|
+
'objectCopy': ([object]) => (object !== null && typeof object === 'object' && !Array.isArray(object) ? {...object} : {}),
|
|
582
585
|
|
|
583
586
|
// $function: objectDelete
|
|
584
587
|
// $group: Object
|
|
@@ -614,7 +617,7 @@ export const scriptFunctions = {
|
|
|
614
617
|
// $group: Object
|
|
615
618
|
// $doc: Get an object's keys
|
|
616
619
|
// $arg object: The object
|
|
617
|
-
// $return: The array of keys
|
|
620
|
+
// $return: The array of keys; null if not an object
|
|
618
621
|
'objectKeys': ([object]) => (object !== null && typeof object === 'object' && !Array.isArray(object) ? Object.keys(object) : null),
|
|
619
622
|
|
|
620
623
|
// $function: objectNew
|
|
@@ -640,9 +643,8 @@ export const scriptFunctions = {
|
|
|
640
643
|
'objectSet': ([object, key, value]) => {
|
|
641
644
|
if (object !== null && typeof object === 'object' && !Array.isArray(object)) {
|
|
642
645
|
object[key] = value;
|
|
643
|
-
return value;
|
|
644
646
|
}
|
|
645
|
-
return
|
|
647
|
+
return value;
|
|
646
648
|
},
|
|
647
649
|
|
|
648
650
|
|
|
@@ -774,7 +776,7 @@ export const scriptFunctions = {
|
|
|
774
776
|
// $arg searchString: The search string
|
|
775
777
|
// $arg index: Optional (default is 0). The index at which to start the search.
|
|
776
778
|
// $return: The first index of the search string; -1 if not found.
|
|
777
|
-
'stringIndexOf': ([string, searchString, index]) => (typeof string === 'string' ? string.indexOf(searchString, index) :
|
|
779
|
+
'stringIndexOf': ([string, searchString, index]) => (typeof string === 'string' ? string.indexOf(searchString, index) : -1),
|
|
778
780
|
|
|
779
781
|
// $function: stringLastIndexOf
|
|
780
782
|
// $group: String
|
|
@@ -783,15 +785,13 @@ export const scriptFunctions = {
|
|
|
783
785
|
// $arg searchString: The search string
|
|
784
786
|
// $arg index: Optional (default is the end of the string). The index at which to start the search.
|
|
785
787
|
// $return: The last index of the search string; -1 if not found.
|
|
786
|
-
'stringLastIndexOf': ([string, searchString, index]) => (
|
|
787
|
-
typeof string === 'string' ? string.lastIndexOf(searchString, index) : null
|
|
788
|
-
),
|
|
788
|
+
'stringLastIndexOf': ([string, searchString, index]) => (typeof string === 'string' ? string.lastIndexOf(searchString, index) : -1),
|
|
789
789
|
|
|
790
790
|
// $function: stringLength
|
|
791
791
|
// $group: String
|
|
792
792
|
// $doc: Get the length of a string
|
|
793
793
|
// $arg string: The string
|
|
794
|
-
// $return: The string's length
|
|
794
|
+
// $return: The string's length; null if not a string
|
|
795
795
|
'stringLength': ([string]) => (typeof string === 'string' ? string.length : null),
|
|
796
796
|
|
|
797
797
|
// $function: stringLower
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "bare-script",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.3",
|
|
5
5
|
"description": "BareScript; a lightweight scripting and expression language",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"expression",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"c8": "~8.0",
|
|
34
|
-
"eslint": "~8.
|
|
34
|
+
"eslint": "~8.50",
|
|
35
35
|
"jsdoc": "~4.0"
|
|
36
36
|
}
|
|
37
37
|
}
|