@sera4/essentia 1.0.28 → 1.0.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sera4/essentia",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "description": "A library of utilities for Teleporte Web Services",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/package.tar.gz CHANGED
Binary file
package/utils/index.js CHANGED
@@ -7,5 +7,32 @@ module.exports = {
7
7
  } else {
8
8
  return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(input);
9
9
  }
10
+ },
11
+ // convert a regular string or Array to array (ie, "[1,2,3]", "1,2,3")
12
+ // useful for controller inputs
13
+ convertToIntegerArray: (input) => {
14
+ return module.exports.convertToArray(input)
15
+ .filter((el) => /^[0-9]+/.test(el))
16
+ .map((el) => parseInt(el));
17
+ },
18
+ convertToArray: (input) => {
19
+ if (Array.isArray(input)){
20
+ return input
21
+ } else {
22
+ if (!!input) {
23
+ if (typeof input === "number") {
24
+ return [ input ]
25
+ }
26
+ let matches;
27
+ if (matches = input.match(/\[(.*?)\]/)) {
28
+ input = matches[1]
29
+ }
30
+ input = input.replace(/[\[\]]/, '')
31
+
32
+ return input.split(',').filter((el) => /^[0-9A-Za-z-.]+/.test(el))
33
+ } else {
34
+ return []
35
+ }
36
+ }
10
37
  }
11
- }
38
+ }