@amandeepsingh13/modify-str 1.0.0 → 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/README.md +99 -13
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -2,23 +2,109 @@
|
|
|
2
2
|
|
|
3
3
|
# modify-str
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
`modify-str` is a small, lightweight utility that allows you to **modify strings using a single, configurable function**.
|
|
6
|
+
|
|
7
|
+
It is designed to be:
|
|
8
|
+
- **Immutable & pure** (no side effects)
|
|
9
|
+
- **Predictable** (clear rules when multiple options are used)
|
|
10
|
+
- **Type-safe** (written in TypeScript, ships JavaScript + type definitions)
|
|
7
11
|
|
|
8
12
|
---
|
|
9
13
|
|
|
10
|
-
## ✨
|
|
14
|
+
## ✨ Why modify-str?
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
- Immutable & pure (no side effects)
|
|
14
|
-
- Supports chaining via config (last option wins)
|
|
15
|
-
- Written in TypeScript, ships JS + `.d.ts`
|
|
16
|
-
- Unit tested
|
|
17
|
-
- Tree-shakable and lightweight
|
|
16
|
+
Instead of manually chaining multiple string operations:
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
```js
|
|
19
|
+
str.trim().toUpperCase().replace(/\s+/g, "_");
|
|
20
|
+
|
|
21
|
+
You can declaratively describe what you want:
|
|
22
|
+
|
|
23
|
+
modifyStr("Hello World", {
|
|
24
|
+
trim: true,
|
|
25
|
+
snakeCase: true,
|
|
26
|
+
toUpperCase: true,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
This makes string transformations:
|
|
30
|
+
|
|
31
|
+
- **Easier to read**
|
|
32
|
+
|
|
33
|
+
- **Easier to maintain**
|
|
34
|
+
|
|
35
|
+
- **Easier to extend**
|
|
36
|
+
|
|
37
|
+
📦 Installation
|
|
38
|
+
npm install @amandeepsingh13/modify-str
|
|
39
|
+
|
|
40
|
+
Basic Usage
|
|
41
|
+
|
|
42
|
+
ESM
|
|
43
|
+
import { modifyStr } from "@amandeepsingh13/modify-str";
|
|
44
|
+
|
|
45
|
+
const result = modifyStr("Hello World", {
|
|
46
|
+
snakeCase: true,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
console.log(result);
|
|
50
|
+
// hello_world
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
CommonJS
|
|
54
|
+
const { modifyStr } = require("@amandeepsingh13/modify-str");
|
|
55
|
+
|
|
56
|
+
console.log(
|
|
57
|
+
modifyStr("Hello World", { toUpperCase: true })
|
|
58
|
+
);
|
|
59
|
+
// HELLO WORLD
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
Core API
|
|
63
|
+
modifyStr(input, options)
|
|
64
|
+
modifyStr(input: string, options?: ModifyOptions): string
|
|
65
|
+
|
|
66
|
+
input → the string you want to modify
|
|
67
|
+
|
|
68
|
+
options → configuration describing which transformations to apply
|
|
69
|
+
|
|
70
|
+
The function always returns a new string and never mutates the input.
|
|
71
|
+
|
|
72
|
+
⚙️ Available Options
|
|
73
|
+
|
|
74
|
+
trim Removes leading & trailing spaces " hi " → "hi"
|
|
75
|
+
removeExtraSpaces Collapses multiple spaces into one "hi there" → "hi there"
|
|
76
|
+
capitaliseFirstChar Capitalizes the first character "hello" → "Hello"
|
|
77
|
+
toUpperCase Converts string to upper case "hi" → "HI"
|
|
78
|
+
toLowerCase Converts string to lower case "HI" → "hi"
|
|
79
|
+
snakeCase Converts to snake_case "Hello World" → "hello_world"
|
|
80
|
+
camelCase Converts to camelCase "hello world" → "helloWorld"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
Applying Multiple Transformations
|
|
84
|
+
|
|
85
|
+
modifyStr(" Hello World ", {
|
|
86
|
+
trim: true,
|
|
87
|
+
snakeCase: true,
|
|
88
|
+
toUpperCase: true,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
OUTPUT
|
|
92
|
+
-------
|
|
93
|
+
HELLO_WORLD
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
Conflict Resolution (Important)
|
|
98
|
+
|
|
99
|
+
If conflicting options are provided,
|
|
100
|
+
👉 the last option wins.
|
|
101
|
+
modifyStr("Hello World", {
|
|
102
|
+
toUpperCase: true,
|
|
103
|
+
toLowerCase: true,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
OUTPUT
|
|
107
|
+
------
|
|
108
|
+
hello world
|
|
20
109
|
|
|
21
|
-
## 📦 Installation
|
|
22
110
|
|
|
23
|
-
```bash
|
|
24
|
-
npm install modify-str
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amandeepsingh13/modify-str",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A configurable, immutable string modification utility written in TypeScript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
-
"files": [
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
9
12
|
"scripts": {
|
|
10
13
|
"build": "tsup",
|
|
11
|
-
"test": "vitest run",
|
|
14
|
+
"test": "npx vitest run",
|
|
12
15
|
"prepublishOnly": "npm run build"
|
|
13
16
|
},
|
|
14
17
|
"keywords": [
|