@amandeepsingh13/modify-str 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.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ ![CI](https://github.com/Amandeep-tech/modify-str/actions/workflows/ci.yml/badge.svg)
2
+
3
+ # modify-str
4
+
5
+ A small, lightweight utility to **modify strings using a single, configurable API**.
6
+ Built with **TypeScript**, shipped with **JavaScript + type definitions**, and designed to be **pure, immutable, and predictable**.
7
+
8
+ ---
9
+
10
+ ## ✨ Features
11
+
12
+ - Single API for multiple string transformations
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
18
+
19
+ ---
20
+
21
+ ## 📦 Installation
22
+
23
+ ```bash
24
+ npm install modify-str
@@ -0,0 +1,13 @@
1
+ type ModifyOptions = {
2
+ capitaliseFirstChar?: boolean;
3
+ toUpperCase?: boolean;
4
+ toLowerCase?: boolean;
5
+ snakeCase?: boolean;
6
+ camelCase?: boolean;
7
+ trim?: boolean;
8
+ removeExtraSpaces?: boolean;
9
+ };
10
+
11
+ declare function modifyStr(input: string, options?: ModifyOptions): string;
12
+
13
+ export { type ModifyOptions, modifyStr };
@@ -0,0 +1,13 @@
1
+ type ModifyOptions = {
2
+ capitaliseFirstChar?: boolean;
3
+ toUpperCase?: boolean;
4
+ toLowerCase?: boolean;
5
+ snakeCase?: boolean;
6
+ camelCase?: boolean;
7
+ trim?: boolean;
8
+ removeExtraSpaces?: boolean;
9
+ };
10
+
11
+ declare function modifyStr(input: string, options?: ModifyOptions): string;
12
+
13
+ export { type ModifyOptions, modifyStr };
package/dist/index.js ADDED
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ modifyStr: () => modifyStr
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/transformers/camelCase.ts
28
+ var camelCase = (str) => str.toLowerCase().replace(/[_-\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : "");
29
+
30
+ // src/transformers/snakeCase.ts
31
+ var snakeCase = (str) => str.trim().replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[\s-]+/g, "_").replace(/_+/g, "_").toLowerCase();
32
+
33
+ // src/modifyStr.ts
34
+ var validKeys = /* @__PURE__ */ new Set([
35
+ "capitaliseFirstChar",
36
+ "toUpperCase",
37
+ "toLowerCase",
38
+ "snakeCase",
39
+ "camelCase",
40
+ "trim",
41
+ "removeExtraSpaces"
42
+ ]);
43
+ function modifyStr(input, options = {}) {
44
+ if (input === null || input === void 0) {
45
+ throw new Error("modifyStr: input string cannot be null or undefined");
46
+ }
47
+ let result = input;
48
+ Object.keys(options).forEach((key) => {
49
+ if (!validKeys.has(key)) {
50
+ if (process.env.NODE_ENV !== "production") {
51
+ console.warn(`modifyStr: unknown option "${key}" ignored`);
52
+ }
53
+ return;
54
+ }
55
+ if (!options[key]) return;
56
+ switch (key) {
57
+ case "trim":
58
+ result = result.trim();
59
+ break;
60
+ case "removeExtraSpaces":
61
+ result = result.replace(/\s+/g, " ");
62
+ break;
63
+ case "capitaliseFirstChar":
64
+ result = result.charAt(0).toUpperCase() + result.slice(1);
65
+ break;
66
+ case "toUpperCase":
67
+ result = result.toUpperCase();
68
+ break;
69
+ case "toLowerCase":
70
+ result = result.toLowerCase();
71
+ break;
72
+ case "snakeCase":
73
+ result = snakeCase(result);
74
+ break;
75
+ case "camelCase":
76
+ result = camelCase(result);
77
+ break;
78
+ }
79
+ });
80
+ return result;
81
+ }
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ modifyStr
85
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,58 @@
1
+ // src/transformers/camelCase.ts
2
+ var camelCase = (str) => str.toLowerCase().replace(/[_-\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : "");
3
+
4
+ // src/transformers/snakeCase.ts
5
+ var snakeCase = (str) => str.trim().replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[\s-]+/g, "_").replace(/_+/g, "_").toLowerCase();
6
+
7
+ // src/modifyStr.ts
8
+ var validKeys = /* @__PURE__ */ new Set([
9
+ "capitaliseFirstChar",
10
+ "toUpperCase",
11
+ "toLowerCase",
12
+ "snakeCase",
13
+ "camelCase",
14
+ "trim",
15
+ "removeExtraSpaces"
16
+ ]);
17
+ function modifyStr(input, options = {}) {
18
+ if (input === null || input === void 0) {
19
+ throw new Error("modifyStr: input string cannot be null or undefined");
20
+ }
21
+ let result = input;
22
+ Object.keys(options).forEach((key) => {
23
+ if (!validKeys.has(key)) {
24
+ if (process.env.NODE_ENV !== "production") {
25
+ console.warn(`modifyStr: unknown option "${key}" ignored`);
26
+ }
27
+ return;
28
+ }
29
+ if (!options[key]) return;
30
+ switch (key) {
31
+ case "trim":
32
+ result = result.trim();
33
+ break;
34
+ case "removeExtraSpaces":
35
+ result = result.replace(/\s+/g, " ");
36
+ break;
37
+ case "capitaliseFirstChar":
38
+ result = result.charAt(0).toUpperCase() + result.slice(1);
39
+ break;
40
+ case "toUpperCase":
41
+ result = result.toUpperCase();
42
+ break;
43
+ case "toLowerCase":
44
+ result = result.toLowerCase();
45
+ break;
46
+ case "snakeCase":
47
+ result = snakeCase(result);
48
+ break;
49
+ case "camelCase":
50
+ result = camelCase(result);
51
+ break;
52
+ }
53
+ });
54
+ return result;
55
+ }
56
+ export {
57
+ modifyStr
58
+ };
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@amandeepsingh13/modify-str",
3
+ "version": "1.0.0",
4
+ "description": "A configurable, immutable string modification utility written in TypeScript",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": ["dist"],
9
+ "scripts": {
10
+ "build": "tsup",
11
+ "test": "vitest run",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "keywords": [
15
+ "string",
16
+ "utility",
17
+ "typescript",
18
+ "npm",
19
+ "formatter"
20
+ ],
21
+ "author": "Amandeep Singh",
22
+ "license": "MIT"
23
+ }