@investorphem/string-tools 1.0.3 → 1.0.4
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/.github/workflows/publish.yml +4 -3
- package/README.md +32 -20
- package/index.js +5 -5
- package/package.json +24 -5
|
@@ -28,13 +28,14 @@ jobs:
|
|
|
28
28
|
env:
|
|
29
29
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
30
30
|
run: |
|
|
31
|
-
#
|
|
32
|
-
PACKAGE_NAME=$(
|
|
33
|
-
CURRENT_VERSION=$(
|
|
31
|
+
# Safely get the current version and name using jq (avoids ESM require errors)
|
|
32
|
+
PACKAGE_NAME=$(jq -r .name package.json)
|
|
33
|
+
CURRENT_VERSION=$(jq -r .version package.json)
|
|
34
34
|
|
|
35
35
|
# Check if this specific version is already on npm
|
|
36
36
|
if npm view "$PACKAGE_NAME@$CURRENT_VERSION" version > /dev/null 2>&1; then
|
|
37
37
|
echo "⚠️ Version $CURRENT_VERSION already exists on npm. Skipping publish."
|
|
38
|
+
echo "💡 Don't forget to run 'npm version patch' before your next commit!"
|
|
38
39
|
exit 0
|
|
39
40
|
else
|
|
40
41
|
echo "🚀 Publishing version $CURRENT_VERSION..."
|
package/README.md
CHANGED
|
@@ -13,16 +13,18 @@
|
|
|
13
13
|
|
|
14
14
|
`@investorphem/string-tools` is a robust, lightweight, and production-ready JavaScript utility library for handling common string operations.
|
|
15
15
|
|
|
16
|
-
It is designed for developers who want **simple, fast, and dependency-free utilities** with **automated CI/CD publishing via GitHub Actions**.
|
|
16
|
+
It is designed for developers who want **simple, fast, and dependency-free utilities** built for modern JavaScript environments with **automated CI/CD publishing via GitHub Actions**.
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
20
|
## ✨ Features
|
|
21
21
|
|
|
22
|
-
* 🔠 Capitalize the first letter of any string
|
|
23
|
-
* 🔗 Convert strings to kebab-case
|
|
24
|
-
* 🔄 Reverse strings efficiently
|
|
25
|
-
*
|
|
22
|
+
* 🔠 **Capitalize** the first letter of any string
|
|
23
|
+
* 🔗 Convert strings to **kebab-case**
|
|
24
|
+
* 🔄 **Reverse** strings efficiently
|
|
25
|
+
* 🛡️ **Null-Safe:** Safely handles empty or undefined inputs without crashing
|
|
26
|
+
* ⚡ **Modern ESM:** Native ES Module support (`import`/`export`)
|
|
27
|
+
* 🍃 **Zero dependencies** (ultra-lightweight)
|
|
26
28
|
* 🤖 Fully automated npm publishing with GitHub Actions
|
|
27
29
|
* 📦 Scoped package for better organization (`@investorphem/*`)
|
|
28
30
|
|
|
@@ -34,16 +36,27 @@ It is designed for developers who want **simple, fast, and dependency-free utili
|
|
|
34
36
|
npm install @investorphem/string-tools
|
|
35
37
|
```
|
|
36
38
|
|
|
39
|
+
or via yarn:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
yarn add @investorphem/string-tools
|
|
43
|
+
```
|
|
44
|
+
|
|
37
45
|
---
|
|
38
46
|
|
|
39
|
-
## 🧠 Usage
|
|
47
|
+
## 🧠 Usage (ES Modules)
|
|
40
48
|
|
|
41
|
-
|
|
42
|
-
const { capitalize, kebabCase, reverse } = require('@investorphem/string-tools');
|
|
49
|
+
Since version 1.0.3, this package uses standard ES Modules.
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
```javascript
|
|
52
|
+
import { capitalize, kebabCase, reverse } from '@investorphem/string-tools';
|
|
53
|
+
|
|
54
|
+
console.log(capitalize('hello')); // "Hello"
|
|
55
|
+
console.log(kebabCase('Hello World')); // "hello-world"
|
|
56
|
+
console.log(reverse('abc')); // "cba"
|
|
57
|
+
|
|
58
|
+
// Safely handles empty values
|
|
59
|
+
console.log(capitalize('')); // ""
|
|
47
60
|
```
|
|
48
61
|
|
|
49
62
|
---
|
|
@@ -60,13 +73,13 @@ Capitalizes the first character of a string.
|
|
|
60
73
|
|
|
61
74
|
**Returns:**
|
|
62
75
|
|
|
63
|
-
* *(string)* – Capitalized string
|
|
76
|
+
* *(string)* – Capitalized string (returns empty string if input is falsy)
|
|
64
77
|
|
|
65
78
|
---
|
|
66
79
|
|
|
67
80
|
### `kebabCase(str)`
|
|
68
81
|
|
|
69
|
-
Converts a string to kebab-case.
|
|
82
|
+
Converts a string to kebab-case. Handles spaces and camelCase transitions.
|
|
70
83
|
|
|
71
84
|
**Parameters:**
|
|
72
85
|
|
|
@@ -74,7 +87,7 @@ Converts a string to kebab-case.
|
|
|
74
87
|
|
|
75
88
|
**Returns:**
|
|
76
89
|
|
|
77
|
-
* *(string)* – Kebab-case string
|
|
90
|
+
* *(string)* – Kebab-case string (returns empty string if input is falsy)
|
|
78
91
|
|
|
79
92
|
---
|
|
80
93
|
|
|
@@ -88,7 +101,7 @@ Reverses the input string.
|
|
|
88
101
|
|
|
89
102
|
**Returns:**
|
|
90
103
|
|
|
91
|
-
* *(string)* – Reversed string
|
|
104
|
+
* *(string)* – Reversed string (returns empty string if input is falsy)
|
|
92
105
|
|
|
93
106
|
---
|
|
94
107
|
|
|
@@ -97,7 +110,6 @@ Reverses the input string.
|
|
|
97
110
|
This project is fully automated using GitHub Actions:
|
|
98
111
|
|
|
99
112
|
* On every push to `main`:
|
|
100
|
-
|
|
101
113
|
* Version is automatically bumped (patch)
|
|
102
114
|
* Package is published to npm
|
|
103
115
|
|
|
@@ -105,14 +117,14 @@ This project is fully automated using GitHub Actions:
|
|
|
105
117
|
|
|
106
118
|
If publishing fails with:
|
|
107
119
|
|
|
108
|
-
```
|
|
120
|
+
```text
|
|
109
121
|
403 Forbidden - You cannot publish over the previously published versions
|
|
110
122
|
```
|
|
111
123
|
|
|
112
124
|
It means:
|
|
113
125
|
|
|
114
|
-
* npm does **NOT allow publishing the same version twice
|
|
115
|
-
* Ensure version is properly incremented before publishing
|
|
126
|
+
* npm does **NOT allow publishing the same version twice**.
|
|
127
|
+
* Ensure the version is properly incremented before publishing.
|
|
116
128
|
|
|
117
129
|
---
|
|
118
130
|
|
|
@@ -163,7 +175,7 @@ npm version patch
|
|
|
163
175
|
before:
|
|
164
176
|
|
|
165
177
|
```bash
|
|
166
|
-
npm publish
|
|
178
|
+
npm publish --access public
|
|
167
179
|
```
|
|
168
180
|
|
|
169
181
|
---
|
package/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// Capitalize the first letter of a string
|
|
2
|
-
function capitalize(str) {
|
|
2
|
+
export function capitalize(str) {
|
|
3
3
|
if (!str) return "";
|
|
4
4
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
// Convert a string to kebab-case
|
|
8
|
-
function kebabCase(str) {
|
|
8
|
+
export function kebabCase(str) {
|
|
9
|
+
if (!str) return "";
|
|
9
10
|
return str
|
|
10
11
|
.replace(/\s+/g, "-")
|
|
11
12
|
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
@@ -13,8 +14,7 @@ function kebabCase(str) {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
// Reverse a string
|
|
16
|
-
function reverse(str) {
|
|
17
|
+
export function reverse(str) {
|
|
18
|
+
if (!str) return "";
|
|
17
19
|
return str.split("").reverse().join("");
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
module.exports = { capitalize, kebabCase, reverse };
|
package/package.json
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@investorphem/string-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "Handy string utility functions for developers.",
|
|
4
5
|
"main": "index.js",
|
|
5
|
-
"
|
|
6
|
+
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "node test.js"
|
|
8
9
|
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/investorphem/string-tools.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/investorphem/string-tools/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/investorphem/string-tools",
|
|
18
|
+
"funding": {
|
|
19
|
+
"type": "github",
|
|
20
|
+
"url": "https://github.com/sponsors/investorphem"
|
|
21
|
+
},
|
|
9
22
|
"keywords": [
|
|
10
23
|
"string",
|
|
11
24
|
"utils",
|
|
12
|
-
"investorphem"
|
|
25
|
+
"investorphem",
|
|
26
|
+
"helpers",
|
|
27
|
+
"formatting",
|
|
28
|
+
"tools"
|
|
13
29
|
],
|
|
14
30
|
"author": "Oluwafemi Olagoke",
|
|
15
|
-
"license": "MIT"
|
|
16
|
-
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|