trousse 1.0.0 → 1.0.1
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/dist/is.js +4 -1
- package/dist/json.js +10 -5
- package/dist/matching.js +10 -1
- package/package.json +1 -1
package/dist/is.js
CHANGED
|
@@ -25,7 +25,10 @@ const isPlainObject = (value) => {
|
|
|
25
25
|
};
|
|
26
26
|
const whitespaceOnlyRegex = /^\p{White_Space}*$/u;
|
|
27
27
|
const isNonEmptyString = (value) => {
|
|
28
|
-
|
|
28
|
+
if (!isString(value) || value === "") return false;
|
|
29
|
+
const code = value.charCodeAt(0);
|
|
30
|
+
if (code > 32 && code < 127) return true;
|
|
31
|
+
return !whitespaceOnlyRegex.test(value);
|
|
29
32
|
};
|
|
30
33
|
const isValidDate = (value) => {
|
|
31
34
|
return value instanceof Date && !Number.isNaN(value.getTime());
|
package/dist/json.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
//#region src/json.ts
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const jsonArrayEndRegex = /\]\s*$/;
|
|
2
|
+
const isWhitespaceCode = (code) => {
|
|
3
|
+
return code >= 9 && code <= 13 || code === 32 || code === 160 || code === 5760 || code >= 8192 && code <= 8202 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288 || code === 65279;
|
|
4
|
+
};
|
|
6
5
|
const isJsonLike = (value) => {
|
|
7
6
|
if (value.length < 2) return false;
|
|
8
|
-
|
|
7
|
+
let start = 0;
|
|
8
|
+
let end = value.length - 1;
|
|
9
|
+
while (start < end && isWhitespaceCode(value.charCodeAt(start))) start++;
|
|
10
|
+
while (end > start && isWhitespaceCode(value.charCodeAt(end))) end--;
|
|
11
|
+
const first = value.charCodeAt(start);
|
|
12
|
+
const last = value.charCodeAt(end);
|
|
13
|
+
return first === 123 && last === 125 || first === 91 && last === 93;
|
|
9
14
|
};
|
|
10
15
|
const isParseableJson = (value) => {
|
|
11
16
|
try {
|
package/dist/matching.js
CHANGED
|
@@ -29,7 +29,16 @@ const endsWithAnyOf = (value, patterns) => {
|
|
|
29
29
|
});
|
|
30
30
|
};
|
|
31
31
|
const anyWordMatchesAnyOf = (value, patterns) => {
|
|
32
|
-
|
|
32
|
+
const stringPatterns = [];
|
|
33
|
+
const regexPatterns = [];
|
|
34
|
+
for (const pattern of patterns) if (pattern instanceof RegExp) regexPatterns.push(pattern);
|
|
35
|
+
else stringPatterns.push(pattern.toLowerCase().trim());
|
|
36
|
+
const words = value.toLowerCase().split(whitespaceRegex);
|
|
37
|
+
for (const word of words) {
|
|
38
|
+
for (const stringPattern of stringPatterns) if (word === stringPattern) return true;
|
|
39
|
+
for (const regexPattern of regexPatterns) if (regexPattern.test(word)) return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
33
42
|
};
|
|
34
43
|
//#endregion
|
|
35
44
|
export { anyWordMatchesAnyOf, endsWithAnyOf, includesAnyOf, isAnyOf, startsWithAnyOf };
|
package/package.json
CHANGED