Skip to content

Commit e14aa06

Browse files
committed
Updating documentation
1 parent af3b8be commit e14aa06

File tree

2 files changed

+73
-59
lines changed

2 files changed

+73
-59
lines changed

docs/TECHNICAL_DOCUMENTATION.md

Lines changed: 72 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -283,78 +283,85 @@ flowchart TD
283283
Start([Input: bytes, options]) --> Validate{Valid Input?}
284284
285285
Validate -->|No| Error[Throw TypeError]
286-
Validate -->|Yes| Normalize[Normalize Base & Standard]
286+
Validate -->|Yes| ValidateRounding{Valid Rounding Method?}
287287
288-
Normalize --> CalcExp[Calculate Exponent]
289-
CalcExp --> CheckExp{Exponent > 8?}
290-
CheckExp -->|Yes| LimitExp[Limit to 8, Adjust Precision]
291-
CheckExp -->|No| CheckZero{Input = 0?}
292-
LimitExp --> CheckZero
288+
ValidateRounding -->|No| Error
289+
ValidateRounding -->|Yes| Normalize[Normalize Base & Standard]
290+
291+
Normalize --> HandleNegative{Input < 0?}
292+
HandleNegative -->|Yes| FlipSign[Store negative flag, use absolute value]
293+
HandleNegative -->|No| CheckZero{Input = 0?}
294+
FlipSign --> CheckZero
293295
294-
CheckZero -->|Yes| ZeroCase[Set result = 0, unit = base unit]
295-
CheckZero -->|No| Convert[Convert Value & Calculate Unit]
296+
CheckZero -->|Yes| ZeroCase[Use handleZeroValue helper]
297+
CheckZero -->|No| CalcExp[Calculate Exponent using logarithms]
296298
297-
Convert --> CheckBits{Bits Mode?}
298-
CheckBits -->|Yes| MultiplyBy8[Multiply by 8]
299-
CheckBits -->|No| Round[Apply Rounding]
300-
MultiplyBy8 --> Round
299+
CalcExp --> CheckExp{Exponent > 8?}
300+
CheckExp -->|Yes| LimitExp[Limit to 8, Adjust Precision]
301+
CheckExp -->|No| CheckExpOutput{Output = 'exponent'?}
302+
LimitExp --> CheckExpOutput
301303
302-
Round --> CheckOverflow{Value >= ceil?}
303-
CheckOverflow -->|Yes| Increment[Increment Exponent]
304-
CheckOverflow -->|No| Format[Apply Formatting]
305-
Increment --> Format
304+
CheckExpOutput -->|Yes| ReturnExp[Return exponent value]
305+
CheckExpOutput -->|No| CalcValue[Calculate value using optimized lookup<br/>Includes bits conversion if needed]
306306
307-
ZeroCase --> Format
307+
CalcValue --> Round[Apply Rounding with power of 10]
308+
Round --> CheckOverflow{Value >= ceil & e < 8?}
309+
CheckOverflow -->|Yes| Increment[Set value=1, increment exponent]
310+
CheckOverflow -->|No| CheckPrecision{Precision > 0?}
311+
Increment --> CheckPrecision
308312
309-
Format --> Locale{Locale Set?}
310-
Locale -->|Yes| LocaleFormat[Apply Locale Formatting]
311-
Locale -->|No| Separator{Custom Separator?}
312-
LocaleFormat --> Padding
313-
Separator -->|Yes| CustomSep[Apply Custom Separator]
314-
Separator -->|No| Padding{Padding Enabled?}
315-
CustomSep --> Padding
313+
CheckPrecision -->|Yes| ApplyPrecision[Apply precision handling<br/>Handle scientific notation]
314+
CheckPrecision -->|No| GetSymbol[Lookup symbol from table]
315+
ApplyPrecision --> GetSymbol
316316
317-
Padding -->|Yes| PadDecimal[Pad Decimal Places]
318-
Padding -->|No| FullForm{Full Form?}
319-
PadDecimal --> FullForm
317+
GetSymbol --> RestoreSign{Was negative?}
318+
RestoreSign -->|Yes| ApplyNegative[Apply negative sign to value]
319+
RestoreSign -->|No| CheckCustomSymbols{Custom symbols?}
320+
ApplyNegative --> CheckCustomSymbols
320321
321-
FullForm -->|Yes| ExpandUnit[Use Full Unit Names]
322-
FullForm -->|No| CustomSymbols{Custom Symbols?}
323-
ExpandUnit --> CustomSymbols
322+
CheckCustomSymbols -->|Yes| ApplySymbols[Apply custom symbols]
323+
CheckCustomSymbols -->|No| FormatNumber[Apply number formatting<br/>locale, separator, padding]
324+
ApplySymbols --> FormatNumber
324325
325-
CustomSymbols -->|Yes| ApplySymbols[Apply Custom Symbols]
326-
CustomSymbols -->|No| Output[Generate Output]
327-
ApplySymbols --> Output
326+
FormatNumber --> CheckFullForm{Full form enabled?}
327+
CheckFullForm -->|Yes| ExpandUnit[Use full unit names]
328+
CheckFullForm -->|No| GenerateOutput[Generate output based on format]
329+
ExpandUnit --> GenerateOutput
328330
329-
Output --> Return([Return: Formatted Result])
331+
ZeroCase --> GenerateOutput
332+
ReturnExp --> Return([Return: Formatted Result])
333+
GenerateOutput --> Return
330334
331335
style Start fill:#166534,stroke:#15803d,stroke-width:2px,color:#ffffff
332336
style Error fill:#dc2626,stroke:#b91c1c,stroke-width:2px,color:#ffffff
333337
style Return fill:#1e40af,stroke:#1e3a8a,stroke-width:2px,color:#ffffff
338+
style CalcValue fill:#7c2d12,stroke:#92400e,stroke-width:2px,color:#ffffff
339+
style ApplyPrecision fill:#d97706,stroke:#b45309,stroke-width:2px,color:#ffffff
334340
```
335341

336342
### Standard Selection Logic
337343

338344
```mermaid
339345
flowchart TD
340-
Input[Input: standard, base] --> CheckStandard{Standard = SI?}
346+
Input[Input: standard, base] --> CheckCached{Standard in<br/>cached configs?}
341347
342-
CheckStandard -->|Yes| SetDecimal[base = 10<br/>standard = JEDEC]
343-
CheckStandard -->|No| CheckIEC{Standard = IEC or JEDEC?}
348+
CheckCached -->|Yes: SI| ReturnSI[isDecimal: true<br/>ceil: 1000<br/>actualStandard: JEDEC]
349+
CheckCached -->|Yes: IEC| ReturnIEC[isDecimal: false<br/>ceil: 1024<br/>actualStandard: IEC]
350+
CheckCached -->|Yes: JEDEC| ReturnJEDEC[isDecimal: false<br/>ceil: 1024<br/>actualStandard: JEDEC]
351+
CheckCached -->|No| CheckBase{Base = 2?}
344352
345-
CheckIEC -->|Yes| SetBinary[base = 2]
346-
CheckIEC -->|No| CheckBase{Base = 2?}
353+
CheckBase -->|Yes| ReturnBase2[isDecimal: false<br/>ceil: 1024<br/>actualStandard: IEC]
354+
CheckBase -->|No| ReturnDefault[isDecimal: true<br/>ceil: 1000<br/>actualStandard: JEDEC]
347355
348-
CheckBase -->|Yes| SetIEC[standard = IEC]
349-
CheckBase -->|No| SetDefault[base = 10<br/>standard = JEDEC]
350-
351-
SetDecimal --> Result[Final: base, standard]
352-
SetBinary --> Result
353-
SetIEC --> Result
354-
SetDefault --> Result
356+
ReturnSI --> Result[Final Configuration]
357+
ReturnIEC --> Result
358+
ReturnJEDEC --> Result
359+
ReturnBase2 --> Result
360+
ReturnDefault --> Result
355361
356362
style Input fill:#166534,stroke:#15803d,stroke-width:2px,color:#ffffff
357363
style Result fill:#1e40af,stroke:#1e3a8a,stroke-width:2px,color:#ffffff
364+
style CheckCached fill:#7c2d12,stroke:#92400e,stroke-width:2px,color:#ffffff
358365
```
359366

360367
## API Reference
@@ -755,23 +762,30 @@ export function SystemMetrics() {
755762
```mermaid
756763
graph TB
757764
subgraph "Locale Processing"
758-
A["Input Locale"] --> B{"Locale Type"}
759-
B -->|"true"| C["System Locale"]
760-
B -->|"string"| D["Specific Locale"]
761-
B -->|"empty"| E["No Localization"]
765+
A["Input: value, locale, localeOptions, separator, pad, round"] --> B{"Locale === true?"}
766+
B -->|"Yes"| C["toLocaleString()"]
767+
B -->|"No"| D{"Locale.length > 0?"}
768+
769+
D -->|"Yes"| E["toLocaleString(locale, localeOptions)"]
770+
D -->|"No"| F{"Separator.length > 0?"}
771+
772+
F -->|"Yes"| G["toString().replace('.', separator)"]
773+
F -->|"No"| H["Keep original value"]
762774
763-
C --> F["navigator.language"]
764-
D --> G["Custom Locale"]
765-
F --> H["toLocaleString()"]
766-
G --> H
775+
C --> I["Check Padding"]
776+
E --> I
777+
G --> I
778+
H --> I
767779
768-
H --> I["Formatted Number"]
769-
E --> J["toString()"]
770-
J --> K["Apply Custom Separator"]
780+
I --> J{"Pad enabled & round > 0?"}
781+
J -->|"Yes"| K["Calculate decimal separator<br/>Pad decimal places with zeros"]
782+
J -->|"No"| L["Return formatted value"]
783+
784+
K --> L
771785
end
772786
773787
style A fill:#166534,stroke:#15803d,stroke-width:2px,color:#ffffff
774-
style I fill:#1e40af,stroke:#1e3a8a,stroke-width:2px,color:#ffffff
788+
style L fill:#1e40af,stroke:#1e3a8a,stroke-width:2px,color:#ffffff
775789
style K fill:#d97706,stroke:#b45309,stroke-width:2px,color:#ffffff
776790
```
777791

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"module": "dist/filesize.js",
2222
"main": "dist/filesize.cjs",
2323
"exports": {
24-
"types": "./types/filesize.d.ts",
24+
"types": "./types",
2525
"import": "./dist/filesize.js",
2626
"require": "./dist/filesize.cjs"
2727
},

0 commit comments

Comments
 (0)