@obinexusmk2/hypernum 0.1.0 → 0.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.
Files changed (140) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +355 -256
  3. package/dist/index.cjs +4 -8
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +4 -7
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.umd.js +2 -2
  9. package/dist/index.umd.js.map +1 -1
  10. package/dist/types/{config → src/config}/config-loader.d.ts +0 -0
  11. package/dist/types/src/config/config-loader.d.ts.map +1 -0
  12. package/dist/types/{config → src/config}/config-parser.d.ts +0 -0
  13. package/dist/types/src/config/config-parser.d.ts.map +1 -0
  14. package/dist/types/{config → src/config}/config-resolver.d.ts +0 -0
  15. package/dist/types/src/config/config-resolver.d.ts.map +1 -0
  16. package/dist/types/{config → src/config}/config-source.d.ts +0 -0
  17. package/dist/types/src/config/config-source.d.ts.map +1 -0
  18. package/dist/types/{config → src/config}/index.d.ts +0 -0
  19. package/dist/types/src/config/index.d.ts.map +1 -0
  20. package/dist/types/{core → src/core}/common.d.ts +0 -0
  21. package/dist/types/src/core/common.d.ts.map +1 -0
  22. package/dist/types/{core → src/core}/config.d.ts +0 -0
  23. package/dist/types/src/core/config.d.ts.map +1 -0
  24. package/dist/types/{core → src/core}/constants.d.ts +0 -0
  25. package/dist/types/src/core/constants.d.ts.map +1 -0
  26. package/dist/types/{core → src/core}/errors.d.ts +0 -0
  27. package/dist/types/src/core/errors.d.ts.map +1 -0
  28. package/dist/types/{core → src/core}/hypernum.d.ts +0 -0
  29. package/dist/types/src/core/hypernum.d.ts.map +1 -0
  30. package/dist/types/{core → src/core}/index.d.ts +0 -0
  31. package/dist/types/src/core/index.d.ts.map +1 -0
  32. package/dist/types/{index.d.ts → src/index.d.ts} +1 -1
  33. package/dist/types/src/index.d.ts.map +1 -0
  34. package/dist/types/{operations → src/operations}/arithmetic.d.ts +0 -0
  35. package/dist/types/src/operations/arithmetic.d.ts.map +1 -0
  36. package/dist/types/{operations → src/operations}/bitwise.d.ts +0 -0
  37. package/dist/types/src/operations/bitwise.d.ts.map +1 -0
  38. package/dist/types/{operations → src/operations}/comparison.d.ts +0 -0
  39. package/dist/types/src/operations/comparison.d.ts.map +1 -0
  40. package/dist/types/{operations → src/operations}/conversion.d.ts +0 -0
  41. package/dist/types/src/operations/conversion.d.ts.map +1 -0
  42. package/dist/types/{operations → src/operations}/factorial.d.ts +0 -0
  43. package/dist/types/src/operations/factorial.d.ts.map +1 -0
  44. package/dist/types/{operations → src/operations}/index.d.ts +0 -0
  45. package/dist/types/src/operations/index.d.ts.map +1 -0
  46. package/dist/types/{operations → src/operations}/power.d.ts +0 -0
  47. package/dist/types/src/operations/power.d.ts.map +1 -0
  48. package/dist/types/{storage → src/storage}/Heap.d.ts +0 -0
  49. package/dist/types/src/storage/Heap.d.ts.map +1 -0
  50. package/dist/types/{storage → src/storage}/index.d.ts +0 -0
  51. package/dist/types/src/storage/index.d.ts.map +1 -0
  52. package/dist/types/{structures → src/structures}/ackermann.d.ts +0 -0
  53. package/dist/types/src/structures/ackermann.d.ts.map +1 -0
  54. package/dist/types/{structures → src/structures}/big-array.d.ts +0 -0
  55. package/dist/types/src/structures/big-array.d.ts.map +1 -0
  56. package/dist/types/{structures → src/structures}/index.d.ts +0 -0
  57. package/dist/types/src/structures/index.d.ts.map +1 -0
  58. package/dist/types/{structures → src/structures}/number-tree.d.ts +0 -0
  59. package/dist/types/src/structures/number-tree.d.ts.map +1 -0
  60. package/dist/types/{structures → src/structures}/power-tower.d.ts +0 -0
  61. package/dist/types/src/structures/power-tower.d.ts.map +1 -0
  62. package/dist/types/{utils → src/utils}/formatting.d.ts +0 -0
  63. package/dist/types/src/utils/formatting.d.ts.map +1 -0
  64. package/dist/types/{utils → src/utils}/index.d.ts +0 -0
  65. package/dist/types/src/utils/index.d.ts.map +1 -0
  66. package/dist/types/{utils → src/utils}/parser.d.ts +0 -0
  67. package/dist/types/src/utils/parser.d.ts.map +1 -0
  68. package/dist/types/{utils → src/utils}/precision.d.ts +0 -0
  69. package/dist/types/src/utils/precision.d.ts.map +1 -0
  70. package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
  71. package/dist/types/src/utils/validation.d.ts.map +1 -0
  72. package/package.json +169 -164
  73. package/rollup.config.js +163 -161
  74. package/src/cli/hypernum.js +272 -0
  75. package/src/config/config-loader.ts +0 -0
  76. package/src/config/config-parser.ts +160 -160
  77. package/src/config/config-resolver.ts +0 -0
  78. package/src/config/config-source.ts +0 -0
  79. package/src/config/index.ts +0 -0
  80. package/src/core/common.ts +184 -184
  81. package/src/core/config.ts +392 -392
  82. package/src/core/constants.ts +101 -101
  83. package/src/core/errors.ts +202 -202
  84. package/src/core/hypernum.ts +240 -240
  85. package/src/core/index.ts +4 -4
  86. package/src/index.ts +179 -182
  87. package/src/operations/arithmetic.ts +332 -332
  88. package/src/operations/bitwise.ts +366 -366
  89. package/src/operations/comparison.ts +271 -271
  90. package/src/operations/conversion.ts +399 -399
  91. package/src/operations/factorial.ts +278 -278
  92. package/src/operations/index.ts +4 -4
  93. package/src/operations/power.ts +315 -315
  94. package/src/storage/Heap.ts +237 -237
  95. package/src/storage/index.ts +0 -0
  96. package/src/structures/ackermann.ts +232 -232
  97. package/src/structures/big-array.ts +305 -305
  98. package/src/structures/index.ts +3 -3
  99. package/src/structures/number-tree.ts +403 -403
  100. package/src/structures/power-tower.ts +277 -277
  101. package/src/types/common.d.ts +356 -356
  102. package/src/types/core.d.ts +160 -160
  103. package/src/types/index.d.ts +1 -1
  104. package/src/utils/formatting.ts +245 -245
  105. package/src/utils/index.ts +4 -4
  106. package/src/utils/parser.ts +244 -244
  107. package/src/utils/precision.ts +216 -216
  108. package/src/utils/validation.ts +182 -182
  109. package/tsconfig.json +83 -83
  110. package/dist/types/config/config-loader.d.ts.map +0 -1
  111. package/dist/types/config/config-parser.d.ts.map +0 -1
  112. package/dist/types/config/config-resolver.d.ts.map +0 -1
  113. package/dist/types/config/config-source.d.ts.map +0 -1
  114. package/dist/types/config/index.d.ts.map +0 -1
  115. package/dist/types/core/common.d.ts.map +0 -1
  116. package/dist/types/core/config.d.ts.map +0 -1
  117. package/dist/types/core/constants.d.ts.map +0 -1
  118. package/dist/types/core/errors.d.ts.map +0 -1
  119. package/dist/types/core/hypernum.d.ts.map +0 -1
  120. package/dist/types/core/index.d.ts.map +0 -1
  121. package/dist/types/index.d.ts.map +0 -1
  122. package/dist/types/operations/arithmetic.d.ts.map +0 -1
  123. package/dist/types/operations/bitwise.d.ts.map +0 -1
  124. package/dist/types/operations/comparison.d.ts.map +0 -1
  125. package/dist/types/operations/conversion.d.ts.map +0 -1
  126. package/dist/types/operations/factorial.d.ts.map +0 -1
  127. package/dist/types/operations/index.d.ts.map +0 -1
  128. package/dist/types/operations/power.d.ts.map +0 -1
  129. package/dist/types/storage/Heap.d.ts.map +0 -1
  130. package/dist/types/storage/index.d.ts.map +0 -1
  131. package/dist/types/structures/ackermann.d.ts.map +0 -1
  132. package/dist/types/structures/big-array.d.ts.map +0 -1
  133. package/dist/types/structures/index.d.ts.map +0 -1
  134. package/dist/types/structures/number-tree.d.ts.map +0 -1
  135. package/dist/types/structures/power-tower.d.ts.map +0 -1
  136. package/dist/types/utils/formatting.d.ts.map +0 -1
  137. package/dist/types/utils/index.d.ts.map +0 -1
  138. package/dist/types/utils/parser.d.ts.map +0 -1
  139. package/dist/types/utils/precision.d.ts.map +0 -1
  140. package/dist/types/utils/validation.d.ts.map +0 -1
@@ -1,161 +1,161 @@
1
-
2
-
3
- /**
4
- * src/config/config-parser.ts
5
- * Parses configuration files in different formats
6
- */
7
-
8
- import { HypernumConfig } from "@/core";
9
- import path from "path";
10
- import fs from 'fs';
11
-
12
-
13
- export class ConfigParser {
14
- /**
15
- * Parses a JSON configuration file
16
- */
17
- public parseJsonConfig(filePath: string): Partial<HypernumConfig> {
18
- try {
19
- const content = fs.readFileSync(filePath, 'utf-8');
20
- return JSON.parse(content) as Partial<HypernumConfig>;
21
- } catch (error) {
22
- console.error(`Error parsing JSON config file ${filePath}:`, error);
23
- return {};
24
- }
25
- }
26
-
27
- /**
28
- * Parses a JavaScript configuration file
29
- */
30
- public parseJsConfig(filePath: string): Partial<HypernumConfig> {
31
- try {
32
- // Use dynamic import for ESM compatibility
33
- if (path.isAbsolute(filePath)) {
34
- // For Node.js environments
35
- const config = require(filePath);
36
- return config.default || config;
37
- } else {
38
- // For browser environments or when relative path is used
39
- const absolutePath = path.resolve(process.cwd(), filePath);
40
- const config = require(absolutePath);
41
- return config.default || config;
42
- }
43
- } catch (error) {
44
- console.error(`Error parsing JS config file ${filePath}:`, error);
45
- return {};
46
- }
47
- }
48
-
49
- /**
50
- * Parses an RC configuration file
51
- */
52
- public parseRcConfig(filePath: string): Partial<HypernumConfig> {
53
- try {
54
- const content = fs.readFileSync(filePath, 'utf-8');
55
-
56
- // Try to parse as JSON first
57
- try {
58
- return JSON.parse(content) as Partial<HypernumConfig>;
59
- } catch {
60
- // Not valid JSON, try to parse as JS if it has JS-like syntax
61
- if (content.includes('module.exports') || content.includes('export default')) {
62
- // Create a temporary JS file to require
63
- const tempFilePath = `${filePath}.temp.js`;
64
- fs.writeFileSync(tempFilePath, content);
65
-
66
- try {
67
- const config = require(tempFilePath);
68
- fs.unlinkSync(tempFilePath); // Clean up temp file
69
- return config.default || config;
70
- } catch (jsError) {
71
- fs.unlinkSync(tempFilePath); // Clean up temp file even on error
72
- throw jsError;
73
- }
74
- }
75
-
76
- // Handle INI-style RC files
77
- return this.parseIniStyleConfig(content);
78
- }
79
- } catch (error) {
80
- console.error(`Error parsing RC config file ${filePath}:`, error);
81
- return {};
82
- }
83
- }
84
-
85
- /**
86
- * Parses an INI-style configuration
87
- */
88
- private parseIniStyleConfig(content: string): Partial<HypernumConfig> {
89
- const config: Record<string, any> = {};
90
- let currentSection = '';
91
-
92
- const lines = content.split('\n');
93
-
94
- for (const line of lines) {
95
- const trimmedLine = line.trim();
96
-
97
- // Skip comments and empty lines
98
- if (trimmedLine.startsWith('#') || trimmedLine.startsWith(';') || !trimmedLine) {
99
- continue;
100
- }
101
-
102
- // Section header
103
- const sectionMatch = trimmedLine.match(/^\[([^\]]+)\]$/);
104
- if (sectionMatch) {
105
- if (sectionMatch[1]) {
106
- currentSection = sectionMatch[1];
107
- if (!config[currentSection]) {
108
- config[currentSection] = {};
109
- }
110
- continue;
111
- }
112
- }
113
-
114
- // Key-value pair
115
- const keyValueMatch = trimmedLine.match(/^([^=]+)=(.*)$/);
116
- if (keyValueMatch) {
117
- const key = keyValueMatch[1]?.trim() || '';
118
- let value: any = keyValueMatch[2] ? keyValueMatch[2].trim() : '';
119
-
120
- // Try to parse the value
121
- if (value === 'true' || value === 'false') {
122
- value = value === 'true';
123
- } else if (!isNaN(Number(value))) {
124
- value = Number(value);
125
- } else if (value.startsWith('"') && value.endsWith('"')) {
126
- value = value.slice(1, -1);
127
- } else if (value.startsWith("'") && value.endsWith("'")) {
128
- value = value.slice(1, -1);
129
- }
130
-
131
- if (currentSection) {
132
- config[currentSection][key] = value;
133
- } else {
134
- config[key] = value;
135
- }
136
- }
137
- }
138
-
139
- return config as Partial<HypernumConfig>;
140
- }
141
-
142
- /**
143
- * Stringifies a configuration object for saving
144
- */
145
- public stringifyConfig(config: HypernumConfig): string {
146
- // Use a custom replacer function to handle BigInt and circular references
147
- const seen = new WeakSet();
148
- return JSON.stringify(config, (_, value) => {
149
- if (typeof value === 'bigint') {
150
- return value.toString() + 'n';
151
- }
152
- if (typeof value === 'object' && value !== null) {
153
- if (seen.has(value)) {
154
- return '[Circular]';
155
- }
156
- seen.add(value);
157
- }
158
- return value;
159
- }, 2);
160
- }
1
+
2
+
3
+ /**
4
+ * src/config/config-parser.ts
5
+ * Parses configuration files in different formats
6
+ */
7
+
8
+ import { HypernumConfig } from "@/core";
9
+ import path from "path";
10
+ import fs from 'fs';
11
+
12
+
13
+ export class ConfigParser {
14
+ /**
15
+ * Parses a JSON configuration file
16
+ */
17
+ public parseJsonConfig(filePath: string): Partial<HypernumConfig> {
18
+ try {
19
+ const content = fs.readFileSync(filePath, 'utf-8');
20
+ return JSON.parse(content) as Partial<HypernumConfig>;
21
+ } catch (error) {
22
+ console.error(`Error parsing JSON config file ${filePath}:`, error);
23
+ return {};
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Parses a JavaScript configuration file
29
+ */
30
+ public parseJsConfig(filePath: string): Partial<HypernumConfig> {
31
+ try {
32
+ // Use dynamic import for ESM compatibility
33
+ if (path.isAbsolute(filePath)) {
34
+ // For Node.js environments
35
+ const config = require(filePath);
36
+ return config.default || config;
37
+ } else {
38
+ // For browser environments or when relative path is used
39
+ const absolutePath = path.resolve(process.cwd(), filePath);
40
+ const config = require(absolutePath);
41
+ return config.default || config;
42
+ }
43
+ } catch (error) {
44
+ console.error(`Error parsing JS config file ${filePath}:`, error);
45
+ return {};
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Parses an RC configuration file
51
+ */
52
+ public parseRcConfig(filePath: string): Partial<HypernumConfig> {
53
+ try {
54
+ const content = fs.readFileSync(filePath, 'utf-8');
55
+
56
+ // Try to parse as JSON first
57
+ try {
58
+ return JSON.parse(content) as Partial<HypernumConfig>;
59
+ } catch {
60
+ // Not valid JSON, try to parse as JS if it has JS-like syntax
61
+ if (content.includes('module.exports') || content.includes('export default')) {
62
+ // Create a temporary JS file to require
63
+ const tempFilePath = `${filePath}.temp.js`;
64
+ fs.writeFileSync(tempFilePath, content);
65
+
66
+ try {
67
+ const config = require(tempFilePath);
68
+ fs.unlinkSync(tempFilePath); // Clean up temp file
69
+ return config.default || config;
70
+ } catch (jsError) {
71
+ fs.unlinkSync(tempFilePath); // Clean up temp file even on error
72
+ throw jsError;
73
+ }
74
+ }
75
+
76
+ // Handle INI-style RC files
77
+ return this.parseIniStyleConfig(content);
78
+ }
79
+ } catch (error) {
80
+ console.error(`Error parsing RC config file ${filePath}:`, error);
81
+ return {};
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Parses an INI-style configuration
87
+ */
88
+ private parseIniStyleConfig(content: string): Partial<HypernumConfig> {
89
+ const config: Record<string, any> = {};
90
+ let currentSection = '';
91
+
92
+ const lines = content.split('\n');
93
+
94
+ for (const line of lines) {
95
+ const trimmedLine = line.trim();
96
+
97
+ // Skip comments and empty lines
98
+ if (trimmedLine.startsWith('#') || trimmedLine.startsWith(';') || !trimmedLine) {
99
+ continue;
100
+ }
101
+
102
+ // Section header
103
+ const sectionMatch = trimmedLine.match(/^\[([^\]]+)\]$/);
104
+ if (sectionMatch) {
105
+ if (sectionMatch[1]) {
106
+ currentSection = sectionMatch[1];
107
+ if (!config[currentSection]) {
108
+ config[currentSection] = {};
109
+ }
110
+ continue;
111
+ }
112
+ }
113
+
114
+ // Key-value pair
115
+ const keyValueMatch = trimmedLine.match(/^([^=]+)=(.*)$/);
116
+ if (keyValueMatch) {
117
+ const key = keyValueMatch[1]?.trim() || '';
118
+ let value: any = keyValueMatch[2] ? keyValueMatch[2].trim() : '';
119
+
120
+ // Try to parse the value
121
+ if (value === 'true' || value === 'false') {
122
+ value = value === 'true';
123
+ } else if (!isNaN(Number(value))) {
124
+ value = Number(value);
125
+ } else if (value.startsWith('"') && value.endsWith('"')) {
126
+ value = value.slice(1, -1);
127
+ } else if (value.startsWith("'") && value.endsWith("'")) {
128
+ value = value.slice(1, -1);
129
+ }
130
+
131
+ if (currentSection) {
132
+ config[currentSection][key] = value;
133
+ } else {
134
+ config[key] = value;
135
+ }
136
+ }
137
+ }
138
+
139
+ return config as Partial<HypernumConfig>;
140
+ }
141
+
142
+ /**
143
+ * Stringifies a configuration object for saving
144
+ */
145
+ public stringifyConfig(config: HypernumConfig): string {
146
+ // Use a custom replacer function to handle BigInt and circular references
147
+ const seen = new WeakSet();
148
+ return JSON.stringify(config, (_, value) => {
149
+ if (typeof value === 'bigint') {
150
+ return value.toString() + 'n';
151
+ }
152
+ if (typeof value === 'object' && value !== null) {
153
+ if (seen.has(value)) {
154
+ return '[Circular]';
155
+ }
156
+ seen.add(value);
157
+ }
158
+ return value;
159
+ }, 2);
160
+ }
161
161
  }
File without changes
File without changes
File without changes