node-str-utils 1.0.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.
Files changed (3) hide show
  1. package/README.md +24 -0
  2. package/index.js +15 -0
  3. package/package.json +8 -0
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # node-str-utils
2
+
3
+ Small, zero-dependency string helpers.
4
+
5
+ ## Install
6
+ ```
7
+ npm install node-str-utils
8
+ ```
9
+
10
+ ## Usage
11
+ ```js
12
+ const { slugify, truncate, titleCase } = require('node-str-utils');
13
+
14
+ slugify('Hello World!'); // "hello-world"
15
+ truncate('long text here', 8); // "long tex…"
16
+ titleCase('the quick fox'); // "The Quick Fox"
17
+ ```
18
+
19
+ ## API
20
+ - `slugify(str)` — URL-safe slug
21
+ - `truncate(str, len, tail='…')` — clip with ellipsis
22
+ - `titleCase(str)` — capitalize each word
23
+
24
+ MIT
package/index.js ADDED
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+ // Small string helpers, no dependencies.
3
+ function slugify(s) {
4
+ return String(s).toLowerCase().trim()
5
+ .replace(/[^a-z0-9]+/g, '-')
6
+ .replace(/^-+|-+$/g, '');
7
+ }
8
+ function truncate(s, len, tail = '…') {
9
+ s = String(s);
10
+ return s.length > len ? s.slice(0, len).trimEnd() + tail : s;
11
+ }
12
+ function titleCase(s) {
13
+ return String(s).toLowerCase().replace(/\b\w/g, c => c.toUpperCase());
14
+ }
15
+ module.exports = { slugify, truncate, titleCase };
package/package.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "node-str-utils",
3
+ "version": "1.0.0",
4
+ "description": "Small string helpers: slugify, truncate, titleCase. No dependencies.",
5
+ "keywords": ["string", "slugify", "truncate", "titlecase", "utility"],
6
+ "license": "MIT",
7
+ "main": "index.js"
8
+ }