@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 CHANGED
@@ -10,14 +10,14 @@
10
10
  ![Node.js](https://img.shields.io/badge/Node.js-%3E%3D16.11.0-green)
11
11
  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/harnuma9/modify-js/blob/main/LICENSE)
12
12
  ![Verify Status](https://github.com/harnuma9/modify-js/actions/workflows/verify.yml/badge.svg)
13
- [![Socket Badge](https://badge.socket.dev/npm/package/@stless/modify-js/1.1.0)](https://badge.socket.dev/npm/package/@stless/modify-js/1.1.0)
13
+ [![Socket Badge](https://badge.socket.dev/npm/package/@stless/modify-js/1.1.1)](https://badge.socket.dev/npm/package/@stless/modify-js/1.1.1)
14
14
  [![Donate](https://img.shields.io/badge/@Harnuma9-Donate-FF4D4D)](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 “Hardened Pipe can transform data through readable, linear pipelines. This eliminates the “Callback Hell” of nested functions and ensures your data remains encapsulated and secure throughout its lifecycle.
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) allows for a clean, top-down data flow.
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
- * **🔒 Hardened Security**: Uses **[ES2022 Private Class Fields](https://dev.to/smitterhane/private-class-fields-in-javascript-es2022-3b8)** (`#value`) to keep your data invisible to external scripts and loggers.
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
- * **🧼 Auto-Sanitization**: Optionally wipes internal state and freezes the pipe instance upon exit.
36
+ * **🧼 Explicit Sanitization**: Prevents memory lingering by optionally wiping the internal state (`null`) and freezing the instance immediately upon extraction.
37
37
 
38
- * **🎯 Zero Side-Effects**: This version does not touch native prototypes or lead to syntax errors, making it 100% safe for production environments and compatible for modern use.
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
- * **⚡ High Performance**: Optimized for the V8 engine with a single-allocation design that is friendly to the Garbage Collector.
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
- const user = chain$(apiResponse)
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 most powerful part of the library. It **handles extraction and cleanup** simultaneously.
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
- // Default:
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()); // Output: true
153
+ console.log(pipe.isLocked()); // true
153
154
  ```
154
155
 
155
- * **Defaulting**: If the pipe resulted in `null` or `undefined`, it returns your default.
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 impossible to reuse or hijack.
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
@@ -1 +1 @@
1
- {"version":3,"file":"dist/index.min.js.map","names":["Pipe","value","constructor","val","this","modify","fn","_p","$p","out","def","lock","Object","freeze","_o","$o","isLocked","isFrozen","_l","$l","chain_","chain$"],"sources":["src/index.js"],"mappings":";;;;;;OAkCO,MAAMA,KAMTC,GAMA,WAAAC,CAAYC,GAAOC,MAAKH,EAASE,CAAK,CAUtC,MAAAE,CAAOC,GAEH,OADAF,MAAKH,EAASK,EAAGF,MAAKH,GACfG,IACX,CAOA,EAAAG,CAAGD,GAAM,OAAOF,KAAKC,OAAOC,EAAK,CAOjC,EAAAE,CAAGF,GAAM,OAAOF,KAAKC,OAAOC,EAAK,CAWjC,GAAAG,CAAIC,EAAKC,GAAO,GACZ,IACI,OAAsB,MAAfP,MAAKH,EACNS,EACAN,MAAKH,CAEf,CAAE,QACMU,IACAP,MAAKH,EAAS,KACdW,OAAOC,OAAOT,MAEtB,CACJ,CAQA,EAAAU,CAAGJ,EAAKC,GAAQ,OAAOP,KAAKK,IAAIC,EAAKC,EAAO,CAQ5C,EAAAI,CAAGL,EAAKC,GAAQ,OAAOP,KAAKK,IAAIC,EAAKC,EAAO,CAS5C,QAAAK,GAAa,OAAOJ,OAAOK,SAASb,KAAO,CAG3C,EAAAc,GAAO,OAAOd,KAAKY,UAAY,CAG/B,EAAAG,GAAO,OAAOf,KAAKY,UAAY,SAc5B,MAAMI,OAAUjB,GAAQ,IAAIH,KAAKG,UAQjC,MAAMkB,OAAUlB,GAAQ,IAAIH,KAAKG,kBAEzBiB","ignoreList":[]}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stless/modify-js",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Lightweight, high-performance, zero-dependency, hardened polyfill for the TC39 Pipeline Operator.",
5
5
  "author": "Aries Harbinger",
6
6
  "license": "Apache-2.0",
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
  }