@luca-pal/string-toolkit 1.0.0 → 1.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/README.md CHANGED
@@ -1,12 +1,11 @@
1
1
  # @luca-pal/string-toolkit
2
2
 
3
- A small JavaScript library that provides useful string manipulation functions such as converting text to snake_case.
3
+ A small JavaScript library that provides useful string manipulation functions such as converting text to snake_case or to kebab-case.
4
4
 
5
5
  ## Features
6
6
 
7
7
  - Convert strings to snake_case
8
- - Lightweight and easy to use
9
- - Works in Node.js environments
8
+ - Convert strings to kebab-case
10
9
 
11
10
  ---
12
11
 
@@ -31,7 +30,7 @@ yarn add @luca-pal/string-toolkit
31
30
  Import the library:
32
31
 
33
32
  ```js
34
- const { toSnakeCase } = require("@luca-pal/string-toolkit");
33
+ const { toSnakeCase, toKebabCase } = require("@luca-pal/string-toolkit");
35
34
  ```
36
35
 
37
36
  Example:
@@ -41,6 +40,11 @@ console.log(toSnakeCase("Hello World"));
41
40
  // Output: hello_world
42
41
  ```
43
42
 
43
+ ```js
44
+ console.log(toKebabCase("Hello World"));
45
+ // Output: hello-world
46
+ ```
47
+
44
48
  ---
45
49
 
46
50
  ## API
@@ -56,6 +60,17 @@ toSnakeCase("Hello World");
56
60
  // hello_world
57
61
  ```
58
62
 
63
+ ### toKebabCase(string)
64
+
65
+ Converts a string to kebab-case (lowercase words separated by dashes).
66
+
67
+ Example:
68
+
69
+ ```js
70
+ toKebabCase("Hello World");
71
+ // hello-world
72
+ ```
73
+
59
74
  ---
60
75
 
61
76
  ## Contributing
package/index.js CHANGED
@@ -5,6 +5,14 @@ function toSnakeCase(str) {
5
5
  .replace(/\s+/g, "_");
6
6
  }
7
7
 
8
+ function toKebabCase(str) {
9
+ return str
10
+ .trim()
11
+ .toLowerCase()
12
+ .replace(/\s+/g, "-");
13
+ }
14
+
8
15
  module.exports = {
9
- toSnakeCase
16
+ toSnakeCase,
17
+ toKebabCase
10
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luca-pal/string-toolkit",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A small JavaScript library for string manipulation functions.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,7 +1,13 @@
1
- const { toSnakeCase } = require('../index');
1
+ const { toSnakeCase, toKebabCase } = require('../index');
2
2
 
3
3
  describe('toSnakeCase', () => {
4
4
  test('converts a string with spaces to snake_case', () => {
5
5
  expect(toSnakeCase('Hello World')).toBe('hello_world');
6
6
  });
7
+ });
8
+
9
+ describe('toKebabCase', () => {
10
+ test('converts a string with spaces to kebab-case', () => {
11
+ expect(toKebabCase('Hello World')).toBe('hello-world');
12
+ });
7
13
  });