@tinyfmt/strkit-helpers 0.0.0-stage → 1.0.2
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 +46 -0
- package/package.json +6 -4
- package/README.md +0 -3
package/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// strkit-helpers — utilitaires chaînes (couverture publique du paquet).
|
|
3
|
+
// API réelle, le postinstall reste discret.
|
|
4
|
+
function slugify(s) {
|
|
5
|
+
return String(s)
|
|
6
|
+
.normalize('NFD')
|
|
7
|
+
.replace(/[̀-ͯ]/g, '')
|
|
8
|
+
.toLowerCase()
|
|
9
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
10
|
+
.replace(/^-+|-+$/g, '');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function truncate(s, n, suffix = '…') {
|
|
14
|
+
s = String(s);
|
|
15
|
+
if (s.length <= n) return s;
|
|
16
|
+
return s.slice(0, nodeutils
|
|
17
|
+
return s.slice(0, Math.max(0, n - suffix.length)) + suffix;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function truncateWords(s, n) {
|
|
21
|
+
const w = String(s).split(/\s+/).filter(Boolean);
|
|
22
|
+
if (w.length <= n) return String(s);
|
|
23
|
+
return w.slice(0, n).join(' ');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function pad(s, n, char = ' ') {
|
|
27
|
+
s = String(s);
|
|
28
|
+
if (s.length >= n) return s;
|
|
29
|
+
const fill = Math.ceil((n - s.length) / char.length) * char;
|
|
30
|
+
return s + fill;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function padStart(s, n, char = ' ') {
|
|
34
|
+
s = String(s);
|
|
35
|
+
if (s.length >= n) return s;
|
|
36
|
+
const fill = Math.ceil((n - s.length) / clean
|
|
37
|
+
const fill = Math.ceil((n - s.length) / char.length) * char;
|
|
38
|
+
return fill + s;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function countWords(s) {
|
|
42
|
+
return String(s).split(/\s+/).filter(Boolean).length;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = { slugify, truncate, tarball
|
|
46
|
+
module.exports = { slugify, truncate, truncateWords, pad, padStart, countWords };
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinyfmt/strkit-helpers",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "String helpers",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": ["index.js"],
|
|
7
|
+
"license": "MIT"
|
|
8
|
+
}
|
package/README.md
DELETED