river-string 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,55 @@
1
+ # usage
2
+
3
+ ## Examples
4
+
5
+ raw javascript
6
+
7
+ ```
8
+ const raw = " Score: 85% ";
9
+ const score = Math.round(parseInt(raw.replace('Score: ', '').replace('%', ''), 10) * 1.1);
10
+ ```
11
+
12
+ river way
13
+
14
+ ```
15
+ const score = s(" Score: 85% ")
16
+ .replace('Score: ', '')
17
+ .replace('%', '')
18
+ .toNumber()
19
+ .multiply(1.1)
20
+ .round()
21
+ .value();
22
+ ```
23
+
24
+ # development
25
+
26
+ ## Running tests
27
+
28
+ need node version 25 to work properly the glob
29
+
30
+ ```
31
+ npm run test
32
+ ```
33
+
34
+ manually run
35
+
36
+ ```
37
+ npx tsx --test src/**/*.test.ts
38
+ ```
39
+
40
+ ## running demo
41
+
42
+ npx tsx demo.ts
43
+
44
+ ## overview
45
+
46
+ ```
47
+ /src
48
+ /logic
49
+ string-logic.ts <-- All string methods (toPascal, shout, etc.)
50
+ number-logic.ts <-- new math methods (add, multiply, round)
51
+ /types
52
+ types.ts <-- TypeScript interfaces for String and Number flows
53
+ core.ts <-- The "River" Proxy factory
54
+ index.ts <-- Entry point (export s)
55
+ ```
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Define the custom methods we want to add to our "River"
3
+ */
4
+ interface RiverMethods {
5
+ /** Converts string to PascalCase */
6
+ toPascal(): RiverString;
7
+ /** Adds a string to the beginning */
8
+ addPrefix(prefix: string): RiverString;
9
+ /** Truncates the string to a specific length */
10
+ shorten(len: number): RiverString;
11
+ /** Adds caps and exclamation points */
12
+ shout(): RiverString;
13
+ /** The "Terminal" command: Executes the queue and returns the raw string */
14
+ readonly value: string;
15
+ }
16
+ /**
17
+ * The "Magic" Type:
18
+ * Combines native String methods with our custom River methods.
19
+ * We use Omit to ensure our custom methods take priority over native ones.
20
+ */
21
+ export type RiverString = RiverMethods & Omit<String, keyof RiverMethods | 'valueOf' | 'toString'>;
22
+ /**
23
+ * The Main Entry Point
24
+ */
25
+ export declare function s(initialValue: string): RiverString;
26
+ export default s;
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,UAAU,YAAY;IACpB,oCAAoC;IACpC,QAAQ,IAAI,WAAW,CAAC;IACxB,qCAAqC;IACrC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC;IACvC,gDAAgD;IAChD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC;IAClC,uCAAuC;IACvC,KAAK,IAAI,WAAW,CAAC;IACrB,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,YAAY,GAAG,SAAS,GAAG,UAAU,CAAC,CAAC;AAYnG;;GAEG;AACH,wBAAgB,CAAC,CAAC,YAAY,EAAE,MAAM,GAAG,WAAW,CAiCnD;AAED,eAAe,CAAC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Internal map of the actual logic for our custom methods.
3
+ */
4
+ const MethodLogic = {
5
+ toPascal: (s) => s.replace(/(\w)(\w*)/g, (_, g1, g2) => g1.toUpperCase() + g2.toLowerCase()).replace(/\s/g, ''),
6
+ addPrefix: (s, prefix) => prefix + s,
7
+ shorten: (s, len) => s.substring(0, len),
8
+ shout: (s) => s.toUpperCase() + "!!!"
9
+ };
10
+ /**
11
+ * The Main Entry Point
12
+ */
13
+ export function s(initialValue) {
14
+ // The "Command Queue" - stores actions as { name, args }
15
+ const queue = [];
16
+ const handler = {
17
+ get(_target, prop) {
18
+ // 1. TERMINAL: If the user asks for .value, run the whole queue
19
+ if (prop === 'value') {
20
+ return queue.reduce((current, action) => action.fn(current, ...action.args), initialValue);
21
+ }
22
+ const implementation = MethodLogic[prop] || String.prototype[prop];
23
+ // 2. CUSTOM METHODS: Look in our MethodLogic map
24
+ if (typeof implementation === 'function') {
25
+ return (...args) => {
26
+ queue.push({
27
+ name: prop,
28
+ fn: (val, ...a) => val[prop](...a),
29
+ args
30
+ });
31
+ return proxy;
32
+ };
33
+ }
34
+ // 3. FALLBACK: Native properties (like .length) require immediate execution
35
+ const currentValue = queue.reduce((current, action) => action.fn(current, ...action.args), initialValue);
36
+ return currentValue[prop];
37
+ }
38
+ };
39
+ const proxy = new Proxy({}, handler);
40
+ return proxy;
41
+ }
42
+ export default s;
43
+ // --- USAGE ---
44
+ function main() {
45
+ const request = s("hello world")
46
+ .toPascal()
47
+ .addPrefix("ID_")
48
+ .shout();
49
+ console.log("Proxy created. No methods executed yet.");
50
+ console.log("---");
51
+ console.log("Result:", request.value);
52
+ }
53
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA;;GAEG;AACH,MAAM,WAAW,GAA4D;IAC3E,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IAC/G,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC;IACpC,OAAO,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC;IACxC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC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C,CAAC;IACrC,OAAO,KAA+B,CAAC;AACzC,CAAC;AAED,eAAe,CAAC,CAAC;AAEjB,gBAAgB;AAChB,SAAS,IAAI;IACX,MAAM,OAAO,GAAG,CAAC,CAAC,aAAa,CAAC;SAC7B,QAAQ,EAAE;SACV,SAAS,CAAC,KAAK,CAAC;SAChB,KAAK,EAAE,CAAC;IAEX,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;IACvD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "river-string",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.js",
7
+ "type": "module",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "tsx --test \"src/**/*.test.ts\""
11
+ },
12
+ "author": "Wesley Lin",
13
+ "license": "ISC",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "devDependencies": {
18
+ "@types/node": "^25.0.3",
19
+ "prettier": "^3.7.4",
20
+ "tsx": "^4.21.0"
21
+ }
22
+ }