alltheutils 0.1.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/LICENSE +7 -0
- package/README.md +64 -0
- package/dist/index.cjs +78 -0
- package/dist/index.mjs +75 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 Jacob Lockett
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# <p align="center">Alltheutils</p>
|
|
2
|
+
|
|
3
|
+
_<p align="center">A utility library with functions I'd rather not recreate if I can help it.</p>_
|
|
4
|
+
|
|
5
|
+
> 🍕 This is mostly just a util library I'm maintaining for personal projects. If you find it useful, great! If you have a specific utility you want added, just let me know and I'll try to get around to it, or you can submit a PR.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Strings/Text](#stringstext)
|
|
10
|
+
|
|
11
|
+
## Strings/Text
|
|
12
|
+
|
|
13
|
+
[Click to go back to main table of contents](#table-of-contents)
|
|
14
|
+
|
|
15
|
+
Utilities that analyze or modify strings.
|
|
16
|
+
|
|
17
|
+
### Methods
|
|
18
|
+
|
|
19
|
+
- [isWhitespace](#iswhitespace)
|
|
20
|
+
- [truncateWhitespace](#truncatewhitespace)
|
|
21
|
+
|
|
22
|
+
### `isWhitespace`
|
|
23
|
+
|
|
24
|
+
[Click to go back to strings/text table of contents](#stringstext)
|
|
25
|
+
|
|
26
|
+
Checks if the given value is a whitespace character. Whitespace characters are any character outlined on https://en.wikipedia.org/wiki/Whitespace_character.
|
|
27
|
+
|
|
28
|
+
#### Arguments:
|
|
29
|
+
|
|
30
|
+
| Name | Type | Description |
|
|
31
|
+
| ----- | ------- | --------------------- |
|
|
32
|
+
| value | unknown | The value to evaluate |
|
|
33
|
+
|
|
34
|
+
#### Example:
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
isWhitespace(" ") // true
|
|
38
|
+
isWhitespace("a") // false
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### `truncateWhitespace`
|
|
42
|
+
|
|
43
|
+
[Click to go back to strings/text table of contents](#stringstext)
|
|
44
|
+
|
|
45
|
+
Truncates all multiple-sequenced whitespace characters into a single space (U+0020) character. Whitespace characters are any character outlined on https://en.wikipedia.org/wiki/Whitespace_character.
|
|
46
|
+
|
|
47
|
+
#### Arguments:
|
|
48
|
+
|
|
49
|
+
| Name | Type | Description |
|
|
50
|
+
| ---- | ------ | ---------------------------------------- |
|
|
51
|
+
| str | string | The string to truncate whitespace within |
|
|
52
|
+
|
|
53
|
+
#### Example:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
truncateWhitespace(" ") // " "
|
|
57
|
+
truncateWhitespace(" a ") // " a "
|
|
58
|
+
truncateWhitespace("a a a") // "a a a"
|
|
59
|
+
truncateWhitespace("aaa") // "aaa"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
#### <p align="center">© Jacob Lockett 2025</p>
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const WHITESPACE = {
|
|
4
|
+
"\u0009": true, // CHARACTER_TABULATION
|
|
5
|
+
"\u000A": true, // LINE_FEED
|
|
6
|
+
"\u000B": true, // LINE_TABULATION
|
|
7
|
+
"\u000C": true, // FORM_FEED
|
|
8
|
+
"\u000D": true, // CARRIAGE_RETURN
|
|
9
|
+
"\u0020": true, // SPACE
|
|
10
|
+
"\u0085": true, // NEXT_LINE
|
|
11
|
+
"\u00A0": true, // NO_BREAK_SPACE
|
|
12
|
+
"\u1680": true, // OGHAM_SPACE_MARK
|
|
13
|
+
"\u2000": true, // EN_QUAD
|
|
14
|
+
"\u2001": true, // EM_QUAD
|
|
15
|
+
"\u2002": true, // EN_SPACE
|
|
16
|
+
"\u2003": true, // EM_SPACE
|
|
17
|
+
"\u2004": true, // THREE_PER_EM_SPACE
|
|
18
|
+
"\u2005": true, // FOUR_PER_EM_SPACE
|
|
19
|
+
"\u2006": true, // SIX_PER_EM_SPACE
|
|
20
|
+
"\u2007": true, // FIGURE_SPACE
|
|
21
|
+
"\u2008": true, // PUNCTUATION_SPACE
|
|
22
|
+
"\u2009": true, // THIN_SPACE
|
|
23
|
+
"\u200A": true, // HAIR_SPACE
|
|
24
|
+
"\u2028": true, // LINE_SEPARATOR
|
|
25
|
+
"\u2029": true, // PARAGRAPH_SEPARATOR
|
|
26
|
+
"\u202F": true, // NARROW_NO_BREAK_SPACE
|
|
27
|
+
"\u205F": true, // MEDIUM_MATHEMATICAL_SPACE
|
|
28
|
+
"\u3000": true, // IDEOGRAPHIC_SPACE
|
|
29
|
+
"\u180E": true, // MONGOLIAN_VOWEL_SEPARATOR
|
|
30
|
+
"\u200B": true, // ZERO_WIDTH_SPACE
|
|
31
|
+
"\u200C": true, // ZERO_WIDTH_NON_JOINER
|
|
32
|
+
"\u200D": true, // ZERO_WIDTH_JOINER
|
|
33
|
+
"\u2060": true, // WORD_JOINER
|
|
34
|
+
"\uFEFF": true // ZERO_WIDTH_NON_BREAKING_SPACE
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Checks if the given value is a whitespace character. Whitespace characters are any
|
|
39
|
+
* character outlined on https://en.wikipedia.org/wiki/Whitespace_character.
|
|
40
|
+
*
|
|
41
|
+
* @param {unknown} value The value to evaluate
|
|
42
|
+
* @returns {boolean}
|
|
43
|
+
*/
|
|
44
|
+
function isWhitespace(value) {
|
|
45
|
+
return !!WHITESPACE[value]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Truncates all multiple-sequenced whitespace characters into a single space (U+0020)
|
|
50
|
+
* character. Whitespace characters are any character outlined on
|
|
51
|
+
* https://en.wikipedia.org/wiki/Whitespace_character.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} str The string to truncate whitespace within
|
|
54
|
+
* @returns {string}
|
|
55
|
+
*/
|
|
56
|
+
function truncateWhitespace(str) {
|
|
57
|
+
if (typeof str !== "string") throw new TypeError(`Expected str to be a string, instead got ${typeof str}`)
|
|
58
|
+
|
|
59
|
+
let n = "";
|
|
60
|
+
|
|
61
|
+
for (let c of str) {
|
|
62
|
+
const p = n[n.length - 1];
|
|
63
|
+
|
|
64
|
+
if (isWhitespace(c)) {
|
|
65
|
+
if (p === "\u0020") continue
|
|
66
|
+
|
|
67
|
+
n = `${n}\u0020`;
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
n = `${n}${c}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return n
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
exports.isWhitespace = isWhitespace;
|
|
78
|
+
exports.truncateWhitespace = truncateWhitespace;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const WHITESPACE = {
|
|
2
|
+
"\u0009": true, // CHARACTER_TABULATION
|
|
3
|
+
"\u000A": true, // LINE_FEED
|
|
4
|
+
"\u000B": true, // LINE_TABULATION
|
|
5
|
+
"\u000C": true, // FORM_FEED
|
|
6
|
+
"\u000D": true, // CARRIAGE_RETURN
|
|
7
|
+
"\u0020": true, // SPACE
|
|
8
|
+
"\u0085": true, // NEXT_LINE
|
|
9
|
+
"\u00A0": true, // NO_BREAK_SPACE
|
|
10
|
+
"\u1680": true, // OGHAM_SPACE_MARK
|
|
11
|
+
"\u2000": true, // EN_QUAD
|
|
12
|
+
"\u2001": true, // EM_QUAD
|
|
13
|
+
"\u2002": true, // EN_SPACE
|
|
14
|
+
"\u2003": true, // EM_SPACE
|
|
15
|
+
"\u2004": true, // THREE_PER_EM_SPACE
|
|
16
|
+
"\u2005": true, // FOUR_PER_EM_SPACE
|
|
17
|
+
"\u2006": true, // SIX_PER_EM_SPACE
|
|
18
|
+
"\u2007": true, // FIGURE_SPACE
|
|
19
|
+
"\u2008": true, // PUNCTUATION_SPACE
|
|
20
|
+
"\u2009": true, // THIN_SPACE
|
|
21
|
+
"\u200A": true, // HAIR_SPACE
|
|
22
|
+
"\u2028": true, // LINE_SEPARATOR
|
|
23
|
+
"\u2029": true, // PARAGRAPH_SEPARATOR
|
|
24
|
+
"\u202F": true, // NARROW_NO_BREAK_SPACE
|
|
25
|
+
"\u205F": true, // MEDIUM_MATHEMATICAL_SPACE
|
|
26
|
+
"\u3000": true, // IDEOGRAPHIC_SPACE
|
|
27
|
+
"\u180E": true, // MONGOLIAN_VOWEL_SEPARATOR
|
|
28
|
+
"\u200B": true, // ZERO_WIDTH_SPACE
|
|
29
|
+
"\u200C": true, // ZERO_WIDTH_NON_JOINER
|
|
30
|
+
"\u200D": true, // ZERO_WIDTH_JOINER
|
|
31
|
+
"\u2060": true, // WORD_JOINER
|
|
32
|
+
"\uFEFF": true // ZERO_WIDTH_NON_BREAKING_SPACE
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Checks if the given value is a whitespace character. Whitespace characters are any
|
|
37
|
+
* character outlined on https://en.wikipedia.org/wiki/Whitespace_character.
|
|
38
|
+
*
|
|
39
|
+
* @param {unknown} value The value to evaluate
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
function isWhitespace(value) {
|
|
43
|
+
return !!WHITESPACE[value]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Truncates all multiple-sequenced whitespace characters into a single space (U+0020)
|
|
48
|
+
* character. Whitespace characters are any character outlined on
|
|
49
|
+
* https://en.wikipedia.org/wiki/Whitespace_character.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} str The string to truncate whitespace within
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
function truncateWhitespace(str) {
|
|
55
|
+
if (typeof str !== "string") throw new TypeError(`Expected str to be a string, instead got ${typeof str}`)
|
|
56
|
+
|
|
57
|
+
let n = "";
|
|
58
|
+
|
|
59
|
+
for (let c of str) {
|
|
60
|
+
const p = n[n.length - 1];
|
|
61
|
+
|
|
62
|
+
if (isWhitespace(c)) {
|
|
63
|
+
if (p === "\u0020") continue
|
|
64
|
+
|
|
65
|
+
n = `${n}\u0020`;
|
|
66
|
+
continue
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
n = `${n}${c}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return n
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { isWhitespace, truncateWhitespace };
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "alltheutils",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A utility library with functions I'd rather not recreate if I can help it.",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
"require": "./dist/index.cjs",
|
|
9
|
+
"import": "./dist/index.mjs"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "rollup -c"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"utility",
|
|
17
|
+
"utilities",
|
|
18
|
+
"util",
|
|
19
|
+
"utils",
|
|
20
|
+
"tools",
|
|
21
|
+
"lodash",
|
|
22
|
+
"underscore"
|
|
23
|
+
],
|
|
24
|
+
"author": "Jacob Lockett",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/jacoblockett/alltheutils.git"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist/",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"packageManager": "pnpm@10.21.0",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
38
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
39
|
+
"rollup": "^4.54.0"
|
|
40
|
+
}
|
|
41
|
+
}
|