cafe-utility 1.29.1 → 1.30.0
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/index.js +15 -17
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -32,11 +32,19 @@ const shuffle = array => {
|
|
|
32
32
|
return array
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
const onlyOrThrow = array => {
|
|
36
|
+
if (array && array.length === 1) {
|
|
37
|
+
return array[0]
|
|
38
|
+
}
|
|
39
|
+
if (array && 'length' in array) {
|
|
40
|
+
throw Error('Expected array to have length 1, got: ' + array.length)
|
|
41
|
+
}
|
|
42
|
+
throw Error('Expected array, got: ' + array)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const onlyOrNull = array => {
|
|
46
|
+
if (array && array.length === 1) {
|
|
47
|
+
return array[0]
|
|
40
48
|
}
|
|
41
49
|
return null
|
|
42
50
|
}
|
|
@@ -604,16 +612,6 @@ const asNotConflicting = (data, options) => {
|
|
|
604
612
|
}
|
|
605
613
|
}
|
|
606
614
|
|
|
607
|
-
const asOnly = array => {
|
|
608
|
-
if (!array) {
|
|
609
|
-
throw new Error('Expected array, was: ' + array)
|
|
610
|
-
}
|
|
611
|
-
if (array.length !== 1) {
|
|
612
|
-
throw new Error('Expected array length to be exactly 1, was: ' + array.length)
|
|
613
|
-
}
|
|
614
|
-
return array[0]
|
|
615
|
-
}
|
|
616
|
-
|
|
617
615
|
const asBetween = (data, minimum, maximum, options) => {
|
|
618
616
|
const number = parseInt(data, 10)
|
|
619
617
|
if (isNaN(number) || number < minimum || number > maximum) {
|
|
@@ -1268,8 +1266,9 @@ module.exports = {
|
|
|
1268
1266
|
splitBySize,
|
|
1269
1267
|
splitByCount,
|
|
1270
1268
|
index: indexArray,
|
|
1269
|
+
onlyOrThrow,
|
|
1270
|
+
onlyOrNull,
|
|
1271
1271
|
firstOrNull,
|
|
1272
|
-
findFirst,
|
|
1273
1272
|
shuffle,
|
|
1274
1273
|
takeRandomly,
|
|
1275
1274
|
initialize: initializeArray,
|
|
@@ -1431,7 +1430,6 @@ module.exports = {
|
|
|
1431
1430
|
asFound,
|
|
1432
1431
|
asSame,
|
|
1433
1432
|
asNotConflicting,
|
|
1434
|
-
asOnly,
|
|
1435
1433
|
asBetween,
|
|
1436
1434
|
asLengthBetween,
|
|
1437
1435
|
expectThrow
|