tiny-essentials 1.25.5 → 1.26.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/TinyFork.mjs +608 -0
- package/changelog/1/25/5.md +5 -0
- package/changelog/1/25/6.md +7 -0
- package/changelog/1/26/0.md +5 -0
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyMaInSys.min.js +1 -1
- package/dist/v1/libs/TinyMamdaniInferenceSystem.cjs +25 -9
- package/dist/v1/libs/TinyMamdaniInferenceSystem.d.mts +7 -3
- package/dist/v1/libs/TinyMamdaniInferenceSystem.mjs +26 -11
- package/docs/TinyFork.md +89 -0
- package/docs/v1/README.md +8 -0
- package/docs/v1/libs/TinyMamdaniInferenceSystem.md +6 -4
- package/package.json +14 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e={d:(t,r)=>{for(var a in r)e.o(r,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:r[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{FuzzySet:()=>s,MamdaniInferenceSystem:()=>
|
|
1
|
+
(()=>{"use strict";var e={d:(t,r)=>{for(var a in r)e.o(r,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:r[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{FuzzySet:()=>s,MamdaniInferenceSystem:()=>o,defuzzifyCentroid:()=>a,trapezoid:()=>i});const r=e=>{if(!Array.isArray(e))throw new TypeError("Parameter 'sets' must be an array.");if(!e.every(e=>e instanceof s))throw new TypeError("All elements in the array must be instances of FuzzySet.")},a=(e,t,a=.5)=>{n(e,"object","defuzzifyCentroid.fuzzyOutput");for(const t in e)n(e[t],"number",`fuzzyOutput['${t}']`);r(t),n(a,"number","defuzzifyCentroid.step");let i=0,s=0;for(let r=0;r<=100;r+=a){let a=0;t.forEach(t=>{const i=e[t.name]||0,n=Math.min(i,t.calculate(r));a=Math.max(a,n)}),i+=r*a,s+=a}return 0===s?0:i/s},i=(e,t,r,a,i,n=!1)=>{if(n){if(e<=t||e>=i)return 0;if(e>=r&&e<=a)return 1}const s=t===r?1:(e-t)/(r-t),o=a===i?1:(i-e)/(i-a),u=Math.max(0,Math.min(s,1,o));return isNaN(u)?0:u},n=(e,t,r)=>{if(typeof e!==t)throw new TypeError(`Parameter '${r}' must be a ${t}.`)};class s{static trapezoid(e,t,r,a,n,s=!1){return i(e,t,r,a,n,s)}#e="";#t=0;#r=0;#a=0;#i=0;#n=!1;get name(){return this.#e}set name(e){n(e,"string","FuzzySet.name"),this.#e=e}get a(){return this.#t}set a(e){n(e,"number","FuzzySet.a"),this.#t=e}get b(){return this.#r}set b(e){n(e,"number","FuzzySet.b"),this.#r=e}get c(){return this.#a}set c(e){n(e,"number","FuzzySet.c"),this.#a=e}get d(){return this.#i}set d(e){n(e,"number","FuzzySet.d"),this.#i=e}get optimize(){return this.#n}set optimize(e){n(e,"boolean","FuzzySet.optimize"),this.#n=e}constructor(e,t,r,a,i,n=!1){this.name=e,this.a=t,this.b=r,this.c=a,this.d=i,this.optimize=n}calculate(e){return n(e,"number","calculate.x"),s.trapezoid(e,this.#t,this.#r,this.#a,this.#i,this.#n)}}class o{#s=new Map;addVariable(e,t){n(e,"string","addVariable.name"),r(t),this.#s.set(e,t)}removeVariable(e){return n(e,"string","removeVariable.name"),this.#s.delete(e)}getVariable(e){n(e,"string","getVariable.name");const t=this.#s.get(e);if(!t)throw new Error(`Linguistic variable '${e}' not found in the inference system.`);return[...t]}hasVariable(e){return n(e,"string","hasVariable.name"),this.#s.has(e)}fuzzify(e,t){n(e,"string","fuzzify.varName"),n(t,"number","fuzzify.value");const r=this.#s.get(e)||[],a={};return r.forEach(e=>{a[e.name]=e.calculate(t)}),a}}window.TinyMaInSys=t})();
|
|
@@ -63,13 +63,16 @@ const defuzzifyCentroid = (fuzzyOutput, outputSets, step = 0.5) => {
|
|
|
63
63
|
* @param {number} b - End of the rise (start of plateau).
|
|
64
64
|
* @param {number} c - Start of the fall (end of plateau).
|
|
65
65
|
* @param {number} d - End of the fall.
|
|
66
|
+
* @param {boolean} [optimize=false] - Optimizes performance by skipping math for absolute bounds.
|
|
66
67
|
* @returns {number} Degree of membership [0, 1].
|
|
67
68
|
*/
|
|
68
|
-
const trapezoid = (value, a, b, c, d) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
const trapezoid = (value, a, b, c, d, optimize = false) => {
|
|
70
|
+
if (optimize) {
|
|
71
|
+
// If the value is completely outside the outer bounds, return 0 immediately
|
|
72
|
+
if (value <= a || value >= d) return 0;
|
|
73
|
+
// If the value is entirely within the plateau, return 1 immediately
|
|
74
|
+
if (value >= b && value <= c) return 1;
|
|
75
|
+
}
|
|
73
76
|
|
|
74
77
|
/** @type {number} - Safely calculate rising slope */
|
|
75
78
|
const rise = a === b ? 1 : (value - a) / (b - a);
|
|
@@ -106,10 +109,11 @@ class FuzzySet {
|
|
|
106
109
|
* @param {number} b - End of the rise (start of plateau).
|
|
107
110
|
* @param {number} c - Start of the fall (end of plateau).
|
|
108
111
|
* @param {number} d - End of the fall.
|
|
112
|
+
* @param {boolean} [optimize=false] - Performance optimization flag.
|
|
109
113
|
* @returns {number} Degree of membership [0, 1].
|
|
110
114
|
*/
|
|
111
|
-
static trapezoid(value, a, b, c, d) {
|
|
112
|
-
return trapezoid(value, a, b, c, d);
|
|
115
|
+
static trapezoid(value, a, b, c, d, optimize = false) {
|
|
116
|
+
return trapezoid(value, a, b, c, d, optimize);
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
/** @type {string} - Internal name of the fuzzy set */
|
|
@@ -122,6 +126,8 @@ class FuzzySet {
|
|
|
122
126
|
#c = 0;
|
|
123
127
|
/** @type {number} - Internal right foot coordinate */
|
|
124
128
|
#d = 0;
|
|
129
|
+
/** @type {boolean} - Internal flag to enable calculation optimization */
|
|
130
|
+
#optimize = false;
|
|
125
131
|
|
|
126
132
|
get name() {
|
|
127
133
|
return this.#name;
|
|
@@ -163,19 +169,29 @@ class FuzzySet {
|
|
|
163
169
|
this.#d = value;
|
|
164
170
|
}
|
|
165
171
|
|
|
172
|
+
get optimize() {
|
|
173
|
+
return this.#optimize;
|
|
174
|
+
}
|
|
175
|
+
set optimize(value) {
|
|
176
|
+
validateType(value, 'boolean', 'FuzzySet.optimize');
|
|
177
|
+
this.#optimize = value;
|
|
178
|
+
}
|
|
179
|
+
|
|
166
180
|
/**
|
|
167
181
|
* @param {string} name - Name of the set (e.g., "Hot").
|
|
168
182
|
* @param {number} a - Left foot.
|
|
169
183
|
* @param {number} b - Left shoulder.
|
|
170
184
|
* @param {number} c - Right shoulder.
|
|
171
185
|
* @param {number} d - Right feet.
|
|
186
|
+
* @param {boolean} [optimize=false] - Enables performance optimization.
|
|
172
187
|
*/
|
|
173
|
-
constructor(name, a, b, c, d) {
|
|
188
|
+
constructor(name, a, b, c, d, optimize = false) {
|
|
174
189
|
this.name = name;
|
|
175
190
|
this.a = a;
|
|
176
191
|
this.b = b;
|
|
177
192
|
this.c = c;
|
|
178
193
|
this.d = d;
|
|
194
|
+
this.optimize = optimize;
|
|
179
195
|
}
|
|
180
196
|
|
|
181
197
|
/**
|
|
@@ -185,7 +201,7 @@ class FuzzySet {
|
|
|
185
201
|
*/
|
|
186
202
|
calculate(x) {
|
|
187
203
|
validateType(x, 'number', 'calculate.x');
|
|
188
|
-
return FuzzySet.trapezoid(x, this.#a, this.#b, this.#c, this.#d);
|
|
204
|
+
return FuzzySet.trapezoid(x, this.#a, this.#b, this.#c, this.#d, this.#optimize);
|
|
189
205
|
}
|
|
190
206
|
}
|
|
191
207
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function defuzzifyCentroid(fuzzyOutput: {
|
|
2
2
|
[x: string]: number;
|
|
3
3
|
}, outputSets: FuzzySet[], step?: number): number;
|
|
4
|
-
export function trapezoid(value: number, a: number, b: number, c: number, d: number): number;
|
|
4
|
+
export function trapezoid(value: number, a: number, b: number, c: number, d: number, optimize?: boolean): number;
|
|
5
5
|
/**
|
|
6
6
|
* Represents a single Membership Function (Trapezoidal).
|
|
7
7
|
*/
|
|
@@ -13,17 +13,19 @@ export class FuzzySet {
|
|
|
13
13
|
* @param {number} b - End of the rise (start of plateau).
|
|
14
14
|
* @param {number} c - Start of the fall (end of plateau).
|
|
15
15
|
* @param {number} d - End of the fall.
|
|
16
|
+
* @param {boolean} [optimize=false] - Performance optimization flag.
|
|
16
17
|
* @returns {number} Degree of membership [0, 1].
|
|
17
18
|
*/
|
|
18
|
-
static trapezoid(value: number, a: number, b: number, c: number, d: number): number;
|
|
19
|
+
static trapezoid(value: number, a: number, b: number, c: number, d: number, optimize?: boolean): number;
|
|
19
20
|
/**
|
|
20
21
|
* @param {string} name - Name of the set (e.g., "Hot").
|
|
21
22
|
* @param {number} a - Left foot.
|
|
22
23
|
* @param {number} b - Left shoulder.
|
|
23
24
|
* @param {number} c - Right shoulder.
|
|
24
25
|
* @param {number} d - Right feet.
|
|
26
|
+
* @param {boolean} [optimize=false] - Enables performance optimization.
|
|
25
27
|
*/
|
|
26
|
-
constructor(name: string, a: number, b: number, c: number, d: number);
|
|
28
|
+
constructor(name: string, a: number, b: number, c: number, d: number, optimize?: boolean);
|
|
27
29
|
set name(value: string);
|
|
28
30
|
get name(): string;
|
|
29
31
|
set a(value: number);
|
|
@@ -34,6 +36,8 @@ export class FuzzySet {
|
|
|
34
36
|
get c(): number;
|
|
35
37
|
set d(value: number);
|
|
36
38
|
get d(): number;
|
|
39
|
+
set optimize(value: boolean);
|
|
40
|
+
get optimize(): boolean;
|
|
37
41
|
/**
|
|
38
42
|
* Calculates the membership degree.
|
|
39
43
|
* @param {number} x - Crisp input.
|
|
@@ -51,15 +51,18 @@ export const defuzzifyCentroid = (fuzzyOutput, outputSets, step = 0.5) => {
|
|
|
51
51
|
* @param {number} b - End of the rise (start of plateau).
|
|
52
52
|
* @param {number} c - Start of the fall (end of plateau).
|
|
53
53
|
* @param {number} d - End of the fall.
|
|
54
|
+
* @param {boolean} [optimize=false] - Optimizes performance by skipping math for absolute bounds.
|
|
54
55
|
* @returns {number} Degree of membership [0, 1].
|
|
55
56
|
*/
|
|
56
|
-
export const trapezoid = (value, a, b, c, d) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
export const trapezoid = (value, a, b, c, d, optimize = false) => {
|
|
58
|
+
if (optimize) {
|
|
59
|
+
// If the value is completely outside the outer bounds, return 0 immediately
|
|
60
|
+
if (value <= a || value >= d)
|
|
61
|
+
return 0;
|
|
62
|
+
// If the value is entirely within the plateau, return 1 immediately
|
|
63
|
+
if (value >= b && value <= c)
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
63
66
|
/** @type {number} - Safely calculate rising slope */
|
|
64
67
|
const rise = a === b ? 1 : (value - a) / (b - a);
|
|
65
68
|
/** @type {number} - Safely calculate falling slope */
|
|
@@ -90,10 +93,11 @@ class FuzzySet {
|
|
|
90
93
|
* @param {number} b - End of the rise (start of plateau).
|
|
91
94
|
* @param {number} c - Start of the fall (end of plateau).
|
|
92
95
|
* @param {number} d - End of the fall.
|
|
96
|
+
* @param {boolean} [optimize=false] - Performance optimization flag.
|
|
93
97
|
* @returns {number} Degree of membership [0, 1].
|
|
94
98
|
*/
|
|
95
|
-
static trapezoid(value, a, b, c, d) {
|
|
96
|
-
return trapezoid(value, a, b, c, d);
|
|
99
|
+
static trapezoid(value, a, b, c, d, optimize = false) {
|
|
100
|
+
return trapezoid(value, a, b, c, d, optimize);
|
|
97
101
|
}
|
|
98
102
|
/** @type {string} - Internal name of the fuzzy set */
|
|
99
103
|
#name = '';
|
|
@@ -105,6 +109,8 @@ class FuzzySet {
|
|
|
105
109
|
#c = 0;
|
|
106
110
|
/** @type {number} - Internal right foot coordinate */
|
|
107
111
|
#d = 0;
|
|
112
|
+
/** @type {boolean} - Internal flag to enable calculation optimization */
|
|
113
|
+
#optimize = false;
|
|
108
114
|
get name() {
|
|
109
115
|
return this.#name;
|
|
110
116
|
}
|
|
@@ -140,19 +146,28 @@ class FuzzySet {
|
|
|
140
146
|
validateType(value, 'number', 'FuzzySet.d');
|
|
141
147
|
this.#d = value;
|
|
142
148
|
}
|
|
149
|
+
get optimize() {
|
|
150
|
+
return this.#optimize;
|
|
151
|
+
}
|
|
152
|
+
set optimize(value) {
|
|
153
|
+
validateType(value, 'boolean', 'FuzzySet.optimize');
|
|
154
|
+
this.#optimize = value;
|
|
155
|
+
}
|
|
143
156
|
/**
|
|
144
157
|
* @param {string} name - Name of the set (e.g., "Hot").
|
|
145
158
|
* @param {number} a - Left foot.
|
|
146
159
|
* @param {number} b - Left shoulder.
|
|
147
160
|
* @param {number} c - Right shoulder.
|
|
148
161
|
* @param {number} d - Right feet.
|
|
162
|
+
* @param {boolean} [optimize=false] - Enables performance optimization.
|
|
149
163
|
*/
|
|
150
|
-
constructor(name, a, b, c, d) {
|
|
164
|
+
constructor(name, a, b, c, d, optimize = false) {
|
|
151
165
|
this.name = name;
|
|
152
166
|
this.a = a;
|
|
153
167
|
this.b = b;
|
|
154
168
|
this.c = c;
|
|
155
169
|
this.d = d;
|
|
170
|
+
this.optimize = optimize;
|
|
156
171
|
}
|
|
157
172
|
/**
|
|
158
173
|
* Calculates the membership degree.
|
|
@@ -161,7 +176,7 @@ class FuzzySet {
|
|
|
161
176
|
*/
|
|
162
177
|
calculate(x) {
|
|
163
178
|
validateType(x, 'number', 'calculate.x');
|
|
164
|
-
return FuzzySet.trapezoid(x, this.#a, this.#b, this.#c, this.#d);
|
|
179
|
+
return FuzzySet.trapezoid(x, this.#a, this.#b, this.#c, this.#d, this.#optimize);
|
|
165
180
|
}
|
|
166
181
|
}
|
|
167
182
|
/**
|
package/docs/TinyFork.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# 🍴 TinyFork CLI (BETA)
|
|
2
|
+
|
|
3
|
+
**The smart, AST-powered tree-shaking extractor for `tiny-essentials`.**
|
|
4
|
+
|
|
5
|
+
Welcome to TinyFork! This is a friendly command-line interface (CLI) designed to extract specific functions, classes, and modules from the `tiny-essentials` library. Instead of forcing you to bundle the entire library into your project, TinyFork performs a deep Abstract Syntax Tree (AST) analysis to cherry-pick exactly what you need. It automatically resolves and extracts all necessary local dependencies, imports, and jsDocs without bringing in any dead code.
|
|
6
|
+
|
|
7
|
+
### 📦 Prerequisites
|
|
8
|
+
|
|
9
|
+
Before running TinyFork, make sure you have the required Babel core packages installed in your project so the AST parsing can work its magic:
|
|
10
|
+
```bash
|
|
11
|
+
npm install @babel/core @babel/parser @babel/traverse @babel/generator @babel/types
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## ✨ Key Features
|
|
15
|
+
|
|
16
|
+
* 🌳 **Deep Tree-Shaking:** Uses `@babel/parser` to deeply trace your code. If you extract one function, TinyFork automatically finds and includes its dependencies (variables, other functions, dynamic imports) while leaving the rest behind.
|
|
17
|
+
* 📁 **Structure Mirroring:** Extracted files are automatically saved maintaining their original folder structure inside your project, preventing naming conflicts and keeping imports clean.
|
|
18
|
+
* 🧩 **Smart Class Extraction:** Can extract static methods from default exported classes and convert them into clean, standalone functions.
|
|
19
|
+
* 🔄 **Version Fallback:** Automatically scans for the requested files starting from the latest version down to `v1`. You can also explicitly request a specific version.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 🚀 Usage
|
|
24
|
+
|
|
25
|
+
You can run TinyFork directly using `npx` from any project that has `tiny-essentials` installed.
|
|
26
|
+
|
|
27
|
+
**Basic Syntax:**
|
|
28
|
+
```bash
|
|
29
|
+
npx tiny-essentials-fork [--out-dir=custom/path] <target1> [target2] ...
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
By default, all files are extracted to: `./vendor/tiny-essentials/` at the root of your project.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 📖 Examples & Capabilities
|
|
37
|
+
|
|
38
|
+
### 1. Extracting a Full File
|
|
39
|
+
If you want to extract an entire JavaScript module, simply provide the path to the file (without the extension). TinyFork will extract it and automatically trace all of its internal imports!
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx tiny-essentials-fork basics/array
|
|
43
|
+
```
|
|
44
|
+
*Result:* Creates `vendor/tiny-essentials/basics/array.mjs` and includes any other internal modules that `array.mjs` depends on.
|
|
45
|
+
|
|
46
|
+
### 2. Extracting Specific Functions
|
|
47
|
+
To extract only specific exports from a file, append them to the path separated by commas.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npx tiny-essentials-fork basics/array/multiplyArrayBlocks,diffArrayList
|
|
51
|
+
```
|
|
52
|
+
*Result:* Extracts **only** `multiplyArrayBlocks` and `diffArrayList` (and their specific local dependencies) from the `basics/array.mjs` file, discarding all other unused functions.
|
|
53
|
+
|
|
54
|
+
### 3. Extracting Static Methods from a Class
|
|
55
|
+
If a module exports a default class filled with static methods, you can extract those methods just like regular functions. TinyFork will intelligently detach them from the class and export them as standalone functions!
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx tiny-essentials-fork libs/TinyArrayComparator/generateHash
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 4. Extracting Multiple Targets at Once
|
|
62
|
+
You can queue as many targets as you want in a single command. TinyFork will orchestrate the entire extraction, mapping all dependencies together.
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npx tiny-essentials-fork libs/TinyHtml basics/array/multiplyArrayBlocks libs/TinyArrayComparator/generateHash
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 5. Specifying a Library Version
|
|
69
|
+
If you need a file from a specific version of `tiny-essentials` (e.g., `v1`), prepend the version number to the path. If no version is specified, TinyFork starts searching from the latest version downwards.
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npx tiny-essentials-fork v1/basics/array/multiplyArrayBlocks
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 6. Using a Custom Output Directory
|
|
76
|
+
Don't want to use the default `vendor/tiny-essentials` folder? Use the `--out-dir` flag to specify your own path.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npx tiny-essentials-fork --out-dir=src/assets/tiny-modules basics/array
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## ⚙️ How it Works Under the Hood
|
|
85
|
+
|
|
86
|
+
1. **Target Parsing:** TinyFork reads your CLI arguments and resolves the correct file path and version inside the `tiny-essentials/dist` folder.
|
|
87
|
+
2. **Dependency Tracing (Bottom-Up):** Using Babel, it builds an AST of the requested file. It traces all identifiers used by your target functions, finding exactly which local variables and internal imports are required to make them work.
|
|
88
|
+
3. **Surgical Pruning:** It removes all AST nodes (dead code) that are not part of the required trace.
|
|
89
|
+
4. **Formatting & Output:** The optimized AST is generated back into standard JavaScript (preserving your original `jsDoc` comments) and written to your project's file system, perfectly mirroring the original directory structure.
|
package/docs/v1/README.md
CHANGED
|
@@ -86,6 +86,14 @@ To get started, navigate to the appropriate directory and explore the files list
|
|
|
86
86
|
|
|
87
87
|
---
|
|
88
88
|
|
|
89
|
+
## 🍴 TinyFork CLI
|
|
90
|
+
|
|
91
|
+
Want to extract only specific modules, classes, or functions into your project without carrying the whole library? We built a powerful AST-based CLI specifically for this!
|
|
92
|
+
|
|
93
|
+
👉 Discover how to use our smart tree-shaking tool by visiting the [**TinyFork CLI Documentation**](../TinyFork.md) for important usage information and commands.
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
89
97
|
## 📖 More Regex Goodies
|
|
90
98
|
|
|
91
99
|
Looking for practical regex examples and migration helpers?
|
|
@@ -6,7 +6,7 @@ Welcome to the official documentation for the **Fuzzy Logic Engine**! 🚀 This
|
|
|
6
6
|
|
|
7
7
|
## 🛠️ Core Utilities
|
|
8
8
|
|
|
9
|
-
### 📐 `trapezoid(value, a, b, c, d)`
|
|
9
|
+
### 📐 `trapezoid(value, a, b, c, d, optimize = false)`
|
|
10
10
|
A high-performance utility to safely calculate the fuzzy membership degree using a trapezoidal shape. It includes built-in protections against division by zero and short-circuit optimizations.
|
|
11
11
|
|
|
12
12
|
**Parameters:**
|
|
@@ -17,6 +17,7 @@ A high-performance utility to safely calculate the fuzzy membership degree using
|
|
|
17
17
|
| `b` | `number` | End of the rise / start of plateau (membership = 1). |
|
|
18
18
|
| `c` | `number` | Start of the fall / end of plateau (membership = 1). |
|
|
19
19
|
| `d` | `number` | End of the fall (membership = 0). |
|
|
20
|
+
| `optimize` | `boolean`, optional | Enables performance optimization by skipping math for absolute bounds. Default is `false`. |
|
|
20
21
|
|
|
21
22
|
**Returns:** * `number` - The degree of membership, safely clamped between `[0, 1]`.
|
|
22
23
|
|
|
@@ -44,20 +45,21 @@ Represents a single linguistic term (e.g., "Cold", "High", "Severe") defined by
|
|
|
44
45
|
|
|
45
46
|
#### ⚙️ Constructor
|
|
46
47
|
```javascript
|
|
47
|
-
new FuzzySet(name, a, b, c, d)
|
|
48
|
+
new FuzzySet(name, a, b, c, d, optimize = false)
|
|
48
49
|
```
|
|
49
50
|
|
|
50
51
|
#### 📦 Properties
|
|
51
52
|
* **`name`** (`string`): The name of the fuzzy set.
|
|
52
53
|
* **`a`, `b`, `c`, `d`** (`number`): The coordinates defining the trapezoidal shape.
|
|
54
|
+
* **`optimize`** (`boolean`): Internal flag to enable calculation optimization for absolute bounds.
|
|
53
55
|
|
|
54
56
|
#### 🧮 Methods
|
|
55
57
|
* **`calculate(x)`**
|
|
56
|
-
Calculates the membership degree for a specific input using the set's coordinates.
|
|
58
|
+
Calculates the membership degree for a specific input using the set's coordinates and optimization flag.
|
|
57
59
|
* **Parameters:** `x` (`number`) - The crisp input value.
|
|
58
60
|
* **Returns:** `number` - Degree of membership `[0, 1]`.
|
|
59
61
|
|
|
60
|
-
* **`static trapezoid(value, a, b, c, d)`**
|
|
62
|
+
* **`static trapezoid(value, a, b, c, d, optimize = false)`**
|
|
61
63
|
Static wrapper for the global `trapezoid` utility.
|
|
62
64
|
|
|
63
65
|
---
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0",
|
|
4
4
|
"description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"tiny-essentials-fork": "./TinyFork.mjs"
|
|
7
|
+
},
|
|
5
8
|
"scripts": {
|
|
6
9
|
"test": "npm run test:mjs && npm run test:cjs && npm run test:js",
|
|
7
10
|
"test:js": "npx babel-node test/index.js",
|
|
@@ -15,11 +18,12 @@
|
|
|
15
18
|
"test:mjs:levelup": "node test/index.mjs levelUp",
|
|
16
19
|
"test:mjs:filemanager": "node test/index.mjs fileManager",
|
|
17
20
|
"test:mjs:i18": "node test/index.mjs i18",
|
|
18
|
-
"fix:prettier": "npm run fix:prettier:src && npm run fix:prettier:test && npm run fix:prettier:rollup.config && npm run fix:prettier:webpack.config",
|
|
21
|
+
"fix:prettier": "npm run fix:prettier:src && npm run fix:prettier:test && npm run fix:prettier:rollup.config && npm run fix:prettier:webpack.config && npm run fix:prettier:tiny_fork",
|
|
19
22
|
"fix:prettier:src": "prettier --write ./src/*",
|
|
20
23
|
"fix:prettier:test": "prettier --write ./test/*",
|
|
21
24
|
"fix:prettier:rollup.config": "prettier --write ./rollup.config.mjs",
|
|
22
25
|
"fix:prettier:webpack.config": "prettier --write ./webpack.config.mjs",
|
|
26
|
+
"fix:prettier:tiny_fork": "prettier --write ./TinyFork.mjs",
|
|
23
27
|
"auto-build": "npm run build",
|
|
24
28
|
"build": "npm run build:js && npm run build:css",
|
|
25
29
|
"build:js": "tsc -p tsconfig.json && rollup -c && webpack --mode production",
|
|
@@ -493,10 +497,14 @@
|
|
|
493
497
|
},
|
|
494
498
|
"homepage": "https://github.com/Tiny-Essentials/Tiny-Essentials#readme",
|
|
495
499
|
"devDependencies": {
|
|
496
|
-
"@babel/cli": "^7.
|
|
497
|
-
"@babel/core": "^7.
|
|
498
|
-
"@babel/
|
|
499
|
-
"@babel/
|
|
500
|
+
"@babel/cli": "^7.28.6",
|
|
501
|
+
"@babel/core": "^7.29.0",
|
|
502
|
+
"@babel/generator": "^7.29.1",
|
|
503
|
+
"@babel/node": "^7.29.0",
|
|
504
|
+
"@babel/parser": "^7.29.2",
|
|
505
|
+
"@babel/preset-env": "^7.29.2",
|
|
506
|
+
"@babel/traverse": "^7.29.0",
|
|
507
|
+
"@babel/types": "^7.29.0",
|
|
500
508
|
"@rollup/plugin-commonjs": "^28.0.3",
|
|
501
509
|
"@rollup/plugin-json": "^6.1.0",
|
|
502
510
|
"@rollup/plugin-node-resolve": "^16.0.1",
|