quantible 0.1.4-alpha → 0.1.5

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.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +146 -57
  3. package/dist/index.cjs +1090 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +183 -0
  6. package/dist/index.d.ts +183 -0
  7. package/dist/index.iife.min.js +2 -0
  8. package/dist/index.iife.min.js.map +1 -0
  9. package/dist/index.js +1086 -0
  10. package/dist/index.js.map +1 -0
  11. package/package.json +16 -12
  12. package/dist/cjs/config/default.js +0 -395
  13. package/dist/cjs/config/default.js.map +0 -1
  14. package/dist/cjs/converters/convertCurrencyToSpokenWord.js +0 -28
  15. package/dist/cjs/converters/convertCurrencyToSpokenWord.js.map +0 -1
  16. package/dist/cjs/converters/convertNumberToSpokenWord.js +0 -32
  17. package/dist/cjs/converters/convertNumberToSpokenWord.js.map +0 -1
  18. package/dist/cjs/converters/convertNumericUnitToSpokenWord.js +0 -48
  19. package/dist/cjs/converters/convertNumericUnitToSpokenWord.js.map +0 -1
  20. package/dist/cjs/converters/convertOperatorToSpokenWord.js +0 -17
  21. package/dist/cjs/converters/convertOperatorToSpokenWord.js.map +0 -1
  22. package/dist/cjs/converters/convertScientificExpressionToSpokenWord.js +0 -35
  23. package/dist/cjs/converters/convertScientificExpressionToSpokenWord.js.map +0 -1
  24. package/dist/cjs/converters/convertUnitOnlyToSpokenWord.js +0 -27
  25. package/dist/cjs/converters/convertUnitOnlyToSpokenWord.js.map +0 -1
  26. package/dist/cjs/index.js +0 -116
  27. package/dist/cjs/index.js.map +0 -1
  28. package/dist/cjs/interfaces/configurations/default.js +0 -3
  29. package/dist/cjs/interfaces/configurations/default.js.map +0 -1
  30. package/dist/cjs/interfaces/definitions.js +0 -3
  31. package/dist/cjs/interfaces/definitions.js.map +0 -1
  32. package/dist/cjs/utils/extraction/patternExtractor.js +0 -96
  33. package/dist/cjs/utils/extraction/patternExtractor.js.map +0 -1
  34. package/dist/cjs/utils/extraction/regexPatterns.js +0 -65
  35. package/dist/cjs/utils/extraction/regexPatterns.js.map +0 -1
  36. package/dist/cjs/utils/parseSuperscript.js +0 -33
  37. package/dist/cjs/utils/parseSuperscript.js.map +0 -1
  38. package/dist/cjs/utils/stringBuilding/exponent.js +0 -21
  39. package/dist/cjs/utils/stringBuilding/exponent.js.map +0 -1
  40. package/dist/cjs/utils/stringBuilding/negative.js +0 -8
  41. package/dist/cjs/utils/stringBuilding/negative.js.map +0 -1
  42. package/dist/cjs/utils/stringBuilding/perDigit.js +0 -18
  43. package/dist/cjs/utils/stringBuilding/perDigit.js.map +0 -1
  44. package/dist/cjs/utils/stringBuilding/positiveInteger.js +0 -31
  45. package/dist/cjs/utils/stringBuilding/positiveInteger.js.map +0 -1
  46. package/dist/cjs/utils/stringBuilding/twoDigits.js +0 -18
  47. package/dist/cjs/utils/stringBuilding/twoDigits.js.map +0 -1
  48. package/dist/cjs/utils/stringBuilding/zeroTo999.js +0 -37
  49. package/dist/cjs/utils/stringBuilding/zeroTo999.js.map +0 -1
  50. package/dist/cjs/utils/validateExtractionResultObject.js +0 -206
  51. package/dist/cjs/utils/validateExtractionResultObject.js.map +0 -1
  52. package/dist/esm/config/default.js +0 -392
  53. package/dist/esm/config/default.js.map +0 -1
  54. package/dist/esm/converters/convertCurrencyToSpokenWord.js +0 -25
  55. package/dist/esm/converters/convertCurrencyToSpokenWord.js.map +0 -1
  56. package/dist/esm/converters/convertNumberToSpokenWord.js +0 -29
  57. package/dist/esm/converters/convertNumberToSpokenWord.js.map +0 -1
  58. package/dist/esm/converters/convertNumericUnitToSpokenWord.js +0 -45
  59. package/dist/esm/converters/convertNumericUnitToSpokenWord.js.map +0 -1
  60. package/dist/esm/converters/convertOperatorToSpokenWord.js +0 -14
  61. package/dist/esm/converters/convertOperatorToSpokenWord.js.map +0 -1
  62. package/dist/esm/converters/convertScientificExpressionToSpokenWord.js +0 -32
  63. package/dist/esm/converters/convertScientificExpressionToSpokenWord.js.map +0 -1
  64. package/dist/esm/converters/convertUnitOnlyToSpokenWord.js +0 -24
  65. package/dist/esm/converters/convertUnitOnlyToSpokenWord.js.map +0 -1
  66. package/dist/esm/index.js +0 -111
  67. package/dist/esm/index.js.map +0 -1
  68. package/dist/esm/interfaces/configurations/default.js +0 -2
  69. package/dist/esm/interfaces/configurations/default.js.map +0 -1
  70. package/dist/esm/interfaces/definitions.js +0 -2
  71. package/dist/esm/interfaces/definitions.js.map +0 -1
  72. package/dist/esm/utils/extraction/patternExtractor.js +0 -92
  73. package/dist/esm/utils/extraction/patternExtractor.js.map +0 -1
  74. package/dist/esm/utils/extraction/regexPatterns.js +0 -62
  75. package/dist/esm/utils/extraction/regexPatterns.js.map +0 -1
  76. package/dist/esm/utils/parseSuperscript.js +0 -30
  77. package/dist/esm/utils/parseSuperscript.js.map +0 -1
  78. package/dist/esm/utils/stringBuilding/exponent.js +0 -18
  79. package/dist/esm/utils/stringBuilding/exponent.js.map +0 -1
  80. package/dist/esm/utils/stringBuilding/negative.js +0 -4
  81. package/dist/esm/utils/stringBuilding/negative.js.map +0 -1
  82. package/dist/esm/utils/stringBuilding/perDigit.js +0 -15
  83. package/dist/esm/utils/stringBuilding/perDigit.js.map +0 -1
  84. package/dist/esm/utils/stringBuilding/positiveInteger.js +0 -28
  85. package/dist/esm/utils/stringBuilding/positiveInteger.js.map +0 -1
  86. package/dist/esm/utils/stringBuilding/twoDigits.js +0 -15
  87. package/dist/esm/utils/stringBuilding/twoDigits.js.map +0 -1
  88. package/dist/esm/utils/stringBuilding/zeroTo999.js +0 -34
  89. package/dist/esm/utils/stringBuilding/zeroTo999.js.map +0 -1
  90. package/dist/esm/utils/validateExtractionResultObject.js +0 -203
  91. package/dist/esm/utils/validateExtractionResultObject.js.map +0 -1
  92. package/dist/types/config/default.d.ts +0 -39
  93. package/dist/types/converters/convertCurrencyToSpokenWord.d.ts +0 -7
  94. package/dist/types/converters/convertNumberToSpokenWord.d.ts +0 -7
  95. package/dist/types/converters/convertNumericUnitToSpokenWord.d.ts +0 -7
  96. package/dist/types/converters/convertOperatorToSpokenWord.d.ts +0 -7
  97. package/dist/types/converters/convertScientificExpressionToSpokenWord.d.ts +0 -7
  98. package/dist/types/converters/convertUnitOnlyToSpokenWord.d.ts +0 -7
  99. package/dist/types/index.d.ts +0 -58
  100. package/dist/types/interfaces/configurations/default.d.ts +0 -22
  101. package/dist/types/interfaces/definitions.d.ts +0 -100
  102. package/dist/types/utils/extraction/patternExtractor.d.ts +0 -21
  103. package/dist/types/utils/extraction/regexPatterns.d.ts +0 -2
  104. package/dist/types/utils/parseSuperscript.d.ts +0 -6
  105. package/dist/types/utils/stringBuilding/exponent.d.ts +0 -2
  106. package/dist/types/utils/stringBuilding/negative.d.ts +0 -1
  107. package/dist/types/utils/stringBuilding/perDigit.d.ts +0 -7
  108. package/dist/types/utils/stringBuilding/positiveInteger.d.ts +0 -6
  109. package/dist/types/utils/stringBuilding/twoDigits.d.ts +0 -6
  110. package/dist/types/utils/stringBuilding/zeroTo999.d.ts +0 -6
  111. package/dist/types/utils/validateExtractionResultObject.d.ts +0 -12
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 rinaldowouterson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,97 +1,186 @@
1
- # quantible
1
+ # Quantible - Convert Numbers and Quantities to Spoken Words
2
2
 
3
- A library for converting quantities, numbers, and simple expressions to spoken words.
3
+ [![NPM Version](https://img.shields.io/npm/v/quantible)](https://www.npmjs.com/package/quantible)
4
+ [![Version](https://img.shields.io/badge/version-0.1.5-blue)](https://www.npmjs.com/package/quantible)
5
+ [![License](https://img.shields.io/npm/l/quantible)](https://github.com/rinaldowouterson/quantible/blob/main/LICENSE)
6
+ [![bundlephobia](https://badgen.net/bundlephobia/minzip/quantible)](https://bundlephobia.com/package/quantible)
4
7
 
5
- ## Examples:
8
+ **Quantible** is a versatile JavaScript library designed to convert numbers, quantities, and simple mathematical expressions into easily understandable spoken words. Whether you're building applications that require text-to-speech functionality, accessibility enhancements, or simply need to present numerical data in a more human-readable format, Quantible provides a robust and flexible solution.
6
9
 
7
- - 5 - 10 = five minus ten
8
- - -5 + 10 = negative five plus ten
9
- - 10m/s = ten meters per second
10
- - 15m/s² = fifteen meters per second squared
11
- - 15² || 15^2 = fifteen to the power of two
12
- - 2^2m^2 = two to the power of two meters squared
13
- - 2^2m² = two to the power of two square meters
14
- - 5E-10 = five times ten to the power of negative ten
15
- - -5E10 = negative five times ten to the power of ten
16
- - 5E10 = five times ten to the power of ten
17
- - 5 USD = five dollars
18
- - $5 = five dollars
19
- - 5.25 USD = five dollars and twenty five cents
20
- - $5.25 = five dollars and twenty five cents
10
+ ## Key Features
21
11
 
22
- When using the autoReplaceAllMatches function, it will convert all quantities in a string to spoken words. For example, it transformed this sentence:
12
+ * **Comprehensive Quantity Conversion:** Handles a wide range of numerical formats, including integers, decimals, negative numbers, currencies, units (e.g., meters, seconds), scientific expressions, and simple mathematical operations.
13
+ * **Flexible Usage:** Supports multiple consumption methods including:
14
+ * **CDN:** Directly include in HTML for quick and easy use in web browsers.
15
+ * **CommonJS (CJS):** Integrate into Node.js projects and older JavaScript module systems.
16
+ * **ECMAScript Modules (ESM):** Utilize modern JavaScript module imports for optimized bundling and performance.
17
+ * **String Auto-Replacement:** Effortlessly convert all or the first detected quantities within a string, simplifying text manipulation and dynamic content generation.
18
+ * **Extensive Examples:** Clear and concise examples to quickly grasp the library's capabilities and integration methods.
19
+ * **Well-Documented and Tested:** Thorough documentation and comprehensive test suite ensure reliability and ease of maintenance.
20
+ * **Lightweight and Performant:** Optimized for minimal bundle size and efficient execution, ensuring a smooth user experience.
23
21
 
24
- ###### "We made $500 more this year than last years projections of 25%"
22
+ ## Examples
25
23
 
26
- into this sentence:
24
+ Quantible excels at transforming various numerical expressions into their spoken word equivalents:
27
25
 
28
- ###### We made five hundred dollars more this year than last years projections of twenty five percent
26
+ - `5 - 10` -> "five minus ten"
27
+ - `-5 + 10` -> "negative five plus ten"
28
+ - `10m/s` -> "ten meters per second"
29
+ - `15m/s²` -> "fifteen meters per second squared"
30
+ - `15²` or `15^2` -> "fifteen to the power of two"
31
+ - `2^2m^2` -> "two to the power of two meters squared"
32
+ - `2^2m²` -> "two to the power of two square meters"
33
+ - `5E-10` -> "five times ten to the power of negative ten"
34
+ - `-5E10` -> "negative five times ten to the power of ten"
35
+ - `5E10` -> "five times ten to the power of ten"
36
+ - `5 USD` -> "five dollars"
37
+ - `$5` -> "five dollars"
38
+ - `5.25 USD` -> "five dollars and twenty-five cents"
39
+ - `$5.25` -> "five dollars and twenty-five cents"
40
+
41
+ The `autoReplaceAllMatches` function demonstrates the power of Quantible by converting all quantities within a text:
42
+
43
+ **Input Sentence:**
44
+
45
+ > "We made $500 more this year than last years projections of 25%"
46
+
47
+ **Output Sentence (after `autoReplaceAllMatches`):**
48
+
49
+ > "We made five hundred dollars more this year than last years projections of twenty-five percent"
29
50
 
30
51
  ## Installation
31
52
 
53
+ ### npm
54
+
55
+ For projects using npm or yarn:
56
+
32
57
  ```bash
33
58
  npm install quantible
34
59
  ```
35
60
 
36
- ## Example Usage
61
+ ## How to Consume Quantible
62
+
63
+ Quantible is designed to be versatile and easily integrated into various JavaScript environments. You can consume it in three primary ways: directly in HTML via CDN, using CommonJS `require`, or with modern ECMAScript `import` statements.
64
+
65
+ ### 1. Directly in HTML via CDN
66
+
67
+ For the quickest integration into web pages, you can use a Content Delivery Network (CDN) to include Quantible directly in your HTML file. This method is ideal for simple projects or when you want to avoid complex build processes.
68
+
69
+ ```html
70
+ <!DOCTYPE html>
71
+ <html>
72
+ <head>
73
+ <title>Quantible Example</title>
74
+ </head>
75
+ <body>
76
+ <div id="output"></div>
77
+ <script src="https://unpkg.com/quantible/dist/index.umd.js"></script>
78
+ <script>
79
+ const inputString = "The price is $12.50 USD.";
80
+ const spokenText = quantible.convertQuantities.autoReplaceAllMatches(inputString);
81
+ document.getElementById('output').textContent = spokenText;
82
+ </script>
83
+ </body>
84
+ </html>
85
+ ```
86
+
87
+ In this example:
37
88
 
38
- ### Extracting and translating a quantity
89
+ * We include Quantible by referencing the UMD build from unpkg CDN: `https://unpkg.com/quantible/dist/index.umd.js`.
90
+ * The library is then globally accessible as `quantible`.
91
+ * We use `quantible.convertQuantities.autoReplaceAllMatches` to process a string and display the spoken word output in the `div#output` element.
92
+
93
+ ### 2. CommonJS (CJS) - `require`
94
+
95
+ For Node.js environments or projects using CommonJS modules, you can import Quantible using `require`.
39
96
 
40
97
  ```javascript
41
- import { convertQuantities, extractQuantities } from "quantible";
98
+ const { convertQuantities, extractQuantities } = require('quantible');
42
99
 
43
- const input = "123.45 USD";
100
+ const input = "25 EUR";
44
101
  const extractedData = extractQuantities.firstMatch(input);
102
+ const spokenWord = convertQuantities.translateMatch(extractedData);
103
+
104
+ console.log(spokenWord); // Output: twenty-five euros
105
+ ```
106
+
107
+ ### 3. ECMAScript Modules (ESM) - `import`
45
108
 
46
- console.log(extractedData);
47
- // Output: {
48
- // integer: '123',
49
- // decimal: '45',
50
- // negativeInt: false,
51
- // currency: 'USD',
52
- // matchType: 'codeCurrency',
53
- // input: '123.45 USD',
54
- // index: 0
55
- // }
109
+ For modern JavaScript projects and applications using ECMAScript modules, you can import Quantible using the `import` statement. This is the recommended approach for most modern JavaScript development.
56
110
 
111
+ ```javascript
112
+ import { convertQuantities, extractQuantities } from 'quantible';
113
+
114
+ const input = "100 km/h";
115
+ const extractedData = extractQuantities.firstMatch(input);
57
116
  const spokenWord = convertQuantities.translateMatch(extractedData);
58
117
 
59
- console.log(spokenWord);
60
- // Output:
61
- // one hundred twenty-three dollars and forty-five cents
118
+ console.log(spokenWord); // Output: one hundred kilometers per hour
62
119
  ```
63
120
 
64
- ### Extracting all quanities and do something with them
121
+ Choose the consumption method that best fits your project's environment and build process. Quantible is designed to be flexible and adaptable to your needs.
122
+
123
+ ## Example Usage
124
+
125
+ The following examples demonstrate key functions of Quantible.
126
+
127
+ ### Extracting and Translating a Quantity
65
128
 
66
129
  ```javascript
67
- import { convertQuantities, extractQuantities } from "quantible";
68
-
69
- const input = "The price is $5.25 and the quantity is 10.";
70
- const extractedData2 = extractQuantities.allMatches(input);
71
- extractedData2.forEach((match) => {
72
- console.log(convertQuantities.translateMatch(match));
73
- });
74
- // Output: The price is five dollars and twenty five cents and the quantity is ten.
130
+ import { convertQuantities, extractQuantities } from 'quantible';
131
+
132
+ const input = "123.45 USD";
133
+ const extractedData = extractQuantities.firstMatch(input);
134
+ const spokenWord = convertQuantities.translateMatch(extractedData);
135
+
136
+ console.log(spokenWord);
137
+ // Output: one hundred twenty-three dollars and forty-five cents
75
138
  ```
76
139
 
77
- ### Auto-replacing quantities in a string
140
+ This example shows how to extract and translate the first quantity found in a string.
141
+
142
+ ### Auto-replacing all quantities in a string
78
143
 
79
144
  ```javascript
80
- // Auto-replacing the first match
81
- const inputFirstMatch = "I have 5 USD and 10 EUR.";
82
- const replacedString1 = convertQuantities.autoReplaceFirstMatch(inputFirstMatch);
83
- console.log(replacedString1); // Output: I have five dollars and 10 EUR.
145
+ import { convertQuantities } from 'quantible';
84
146
 
85
- // Auto-replacing all matches
86
147
  const inputReplaceAllMatches = "I have 5 USD and 10 EUR.";
87
- const replacedString2 = convertQuantities.autoReplaceAllMatches(inputReplaceAllMatches);
88
- console.log(replacedString2); // Output: I have five dollars and ten euros.
148
+ const replacedString = convertQuantities.autoReplaceAllMatches(inputReplaceAllMatches);
149
+ console.log(replacedString); // Output: I have five dollars and ten euros.
89
150
  ```
90
151
 
152
+ This example demonstrates automatically replacing all quantities within a string.
153
+
91
154
  ## Contributing
92
155
 
93
- We welcome contributions to quantible! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute.
156
+ We welcome contributions to Quantible! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute.
94
157
 
95
158
  ## License
96
159
 
97
- ISC
160
+ MIT
161
+
162
+ ## License File
163
+
164
+ ```plaintext
165
+ MIT License
166
+
167
+ Copyright (c) 2025 rinaldowouterson
168
+
169
+ Permission is hereby granted, free of charge, to any person obtaining a copy
170
+ of this software and associated documentation files (the "Software"), to deal
171
+ in the Software without restriction, including without limitation the rights
172
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
173
+ copies of the Software, and to permit persons to whom the Software is
174
+ furnished to do so, subject to the following conditions:
175
+
176
+ The above copyright notice and this permission notice shall be included in all
177
+ copies or substantial portions of the Software.
178
+
179
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
180
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
181
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
182
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
183
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
184
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
185
+ SOFTWARE.
186
+ ```