@stless/modify-js 1.1.0 → 1.1.1
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 +15 -14
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +4 -0
package/README.md
CHANGED
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|

|
|
11
11
|
[](https://github.com/harnuma9/modify-js/blob/main/LICENSE)
|
|
12
12
|

|
|
13
|
-
[](https://badge.socket.dev/npm/package/@stless/modify-js/1.1.1)
|
|
14
14
|
[](https://harnuma9.github.io/donate/)
|
|
15
15
|
|
|
16
16
|
<br />
|
|
17
17
|
|
|
18
18
|
`@stless/modify-js` is a lightweight, zero-dependency utility that brings functional piping to JavaScript. It provides a secure, high-performance alternative to the proposed **[TC39 Pipeline Operator](https://github.com/tc39/proposal-pipeline-operator)**.
|
|
19
19
|
|
|
20
|
-
Values wrapped in a
|
|
20
|
+
Values wrapped in a **Pipe container** can transform data through readable, linear pipelines. It is designed for **defense-in-depth**, utilizing modern JS features to reduce data exposure and ensure state integrity throughout the transformation lifecycle.
|
|
21
21
|
|
|
22
22
|
<br />
|
|
23
23
|
|
|
@@ -27,17 +27,17 @@ Values wrapped in a “Hardened Pipe” can transform data through readable, lin
|
|
|
27
27
|
|
|
28
28
|
## ✨ Why `[modify](JS)`?
|
|
29
29
|
|
|
30
|
-
While standard JavaScript requires nested function calls or intermediate variables, [modify-js](https://www.npmjs.com/package/@stless/modify-js)
|
|
30
|
+
While standard JavaScript requires nested function calls or intermediate variables, [modify-js](https://www.npmjs.com/package/@stless/modify-js) enables a clean, top-down data flow with enhanced lifecycle management.
|
|
31
31
|
|
|
32
32
|
<br />
|
|
33
33
|
|
|
34
|
-
*
|
|
34
|
+
* **🛡️ Data Encapsulation**: Leverages **[ES2022 Private Class Fields](https://dev.to/smitterhane/private-class-fields-in-javascript-es2022-3b8)** (`#value`) to ensure internal state is inaccessible to external scripts, loggers, or enumeration.
|
|
35
35
|
|
|
36
|
-
* **🧼
|
|
36
|
+
* **🧼 Explicit Sanitization**: Prevents memory lingering by optionally wiping the internal state (`null`) and freezing the instance immediately upon extraction.
|
|
37
37
|
|
|
38
|
-
* **🎯
|
|
38
|
+
* **🎯 Environment Safety**: Operates as a standalone wrapper with **zero prototype pollution**, making it safe for sensitive production environments and legacy codebases.
|
|
39
39
|
|
|
40
|
-
* **⚡
|
|
40
|
+
* **⚡ GC-Friendly**: Optimized for the V8 engine with a single-allocation design that minimizes overhead during high-frequency transformations.
|
|
41
41
|
|
|
42
42
|
<br />
|
|
43
43
|
|
|
@@ -109,7 +109,9 @@ const result = chain_(" hello world ")
|
|
|
109
109
|
Transform data from left-to-right. Use `._p()`, `.$p()`, or `.modify()` to chain functions.
|
|
110
110
|
|
|
111
111
|
```javascript
|
|
112
|
-
|
|
112
|
+
import { Pipe } from '@stless/modify-js';
|
|
113
|
+
|
|
114
|
+
const user = new Pipe(apiResponse)
|
|
113
115
|
._p(res => res.data)
|
|
114
116
|
._p(data => ({ ...data, timestamp: Date.now() }))
|
|
115
117
|
.out({ error: "No data found" }); // Safe fallback
|
|
@@ -142,21 +144,20 @@ console.log(val2); // Output: 180
|
|
|
142
144
|
|
|
143
145
|
### The “Security Exit”
|
|
144
146
|
|
|
145
|
-
The `.out()` method is the
|
|
147
|
+
The `.out()` method is the termination point of the pipe. It is designed to handle extraction and cleanup as a single atomic-like operation.
|
|
146
148
|
|
|
147
149
|
```javascript
|
|
148
|
-
//
|
|
149
|
-
// .out(fallbackValue, shouldLock=true)
|
|
150
|
+
// Signature: .out(fallbackValue?, shouldLock=true)
|
|
150
151
|
|
|
151
152
|
const data = pipe.out("Unknown", true);
|
|
152
|
-
console.log(pipe.isLocked());
|
|
153
|
+
console.log(pipe.isLocked()); // true
|
|
153
154
|
```
|
|
154
155
|
|
|
155
|
-
* **
|
|
156
|
+
* **Safe Fallback**: If the internal pipeline results in `null` or `undefined`, it returns your provided default value.
|
|
156
157
|
|
|
157
158
|
* **Wiping**: It clears the internal private state.
|
|
158
159
|
|
|
159
|
-
* **Locking**: It freezes the pipe object, making it
|
|
160
|
+
* **Locking**: It freezes the pipe object, making it unable to reuse.
|
|
160
161
|
|
|
161
162
|
<br />
|
|
162
163
|
|
package/dist/index.min.js
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* @author Aries Harbinger
|
|
5
5
|
* @license Apache-2.0
|
|
6
6
|
*/
|
|
7
|
-
export class Pipe{#t;constructor(t){this.#t=t}modify(t){return this.#t=t(this.#t),this}_p(t){return this.modify(t)}$p(t){return this.modify(t)}out(t,e=!0){try{return null==this.#t?t:this.#t}finally{e&&(this.#t=null,Object.freeze(this))}}_o(t,e){return this.out(t,e)}$o(t,e){return this.out(t,e)}isLocked(){return Object.isFrozen(this)}_l(){return this.isLocked()}$l(){return this.isLocked()}}export const chain_=t=>new Pipe(t);export const chain$=t=>new Pipe(t);export default chain_;
|
|
7
|
+
export class Pipe{#t;constructor(t){this.#t=t}modify(t){if(Object.isFrozen(this))return this;if("function"!=typeof t)throw new TypeError("[modify-js] Expected a function, but received: "+typeof t);return this.#t=t(this.#t),this}_p(t){return this.modify(t)}$p(t){return this.modify(t)}out(t,e=!0){try{return null==this.#t?t:this.#t}finally{e&&(this.#t=null,Object.freeze(this))}}_o(t,e){return this.out(t,e)}$o(t,e){return this.out(t,e)}isLocked(){return Object.isFrozen(this)}_l(){return this.isLocked()}$l(){return this.isLocked()}}export const chain_=t=>new Pipe(t);export const chain$=t=>new Pipe(t);export default chain_;
|
|
8
8
|
//# sourceMappingURL=index.min.js.map
|
package/dist/index.min.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dist/index.min.js.map","names":["Pipe","value","constructor","val","this","modify","fn","_p","$p","out","def","lock","
|
|
1
|
+
{"version":3,"file":"dist/index.min.js.map","names":["Pipe","value","constructor","val","this","modify","fn","Object","isFrozen","TypeError","_p","$p","out","def","lock","freeze","_o","$o","isLocked","_l","$l","chain_","chain$"],"sources":["src/index.js"],"mappings":";;;;;;OAkCO,MAAMA,KAMTC,GAMA,WAAAC,CAAYC,GAAOC,MAAKH,EAASE,CAAK,CAUtC,MAAAE,CAAOC,GACH,GAAIC,OAAOC,SAASJ,MAAO,OAAOA,KAClC,GAAkB,mBAAPE,EACP,MAAM,IAAIG,UAAU,yDAAyDH,GAGjF,OADAF,MAAKH,EAASK,EAAGF,MAAKH,GACfG,IACX,CAOA,EAAAM,CAAGJ,GAAM,OAAOF,KAAKC,OAAOC,EAAK,CAOjC,EAAAK,CAAGL,GAAM,OAAOF,KAAKC,OAAOC,EAAK,CAWjC,GAAAM,CAAIC,EAAKC,GAAO,GACZ,IACI,OAAsB,MAAfV,MAAKH,EACNY,EACAT,MAAKH,CAEf,CAAE,QACMa,IACAV,MAAKH,EAAS,KACdM,OAAOQ,OAAOX,MAEtB,CACJ,CAQA,EAAAY,CAAGH,EAAKC,GAAQ,OAAOV,KAAKQ,IAAIC,EAAKC,EAAO,CAQ5C,EAAAG,CAAGJ,EAAKC,GAAQ,OAAOV,KAAKQ,IAAIC,EAAKC,EAAO,CAS5C,QAAAI,GAAa,OAAOX,OAAOC,SAASJ,KAAO,CAG3C,EAAAe,GAAO,OAAOf,KAAKc,UAAY,CAG/B,EAAAE,GAAO,OAAOhB,KAAKc,UAAY,SAc5B,MAAMG,OAAUlB,GAAQ,IAAIH,KAAKG,UAQjC,MAAMmB,OAAUnB,GAAQ,IAAIH,KAAKG,kBAEzBkB","ignoreList":[]}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -55,6 +55,10 @@ export class Pipe {
|
|
|
55
55
|
* @returns {this} The current Pipe instance for further chaining.
|
|
56
56
|
*/
|
|
57
57
|
modify(fn) {
|
|
58
|
+
if (Object.isFrozen(this)) return this; // Silent guard for locked pipes
|
|
59
|
+
if (typeof fn !== 'function')
|
|
60
|
+
throw new TypeError(`[modify-js] Expected a function, but received: ${typeof fn}`);
|
|
61
|
+
|
|
58
62
|
this.#value = fn(this.#value);
|
|
59
63
|
return this;
|
|
60
64
|
}
|