@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.
- package/LICENSE +21 -21
- package/README.md +355 -256
- package/dist/index.cjs +4 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/types/{config → src/config}/config-loader.d.ts +0 -0
- package/dist/types/src/config/config-loader.d.ts.map +1 -0
- package/dist/types/{config → src/config}/config-parser.d.ts +0 -0
- package/dist/types/src/config/config-parser.d.ts.map +1 -0
- package/dist/types/{config → src/config}/config-resolver.d.ts +0 -0
- package/dist/types/src/config/config-resolver.d.ts.map +1 -0
- package/dist/types/{config → src/config}/config-source.d.ts +0 -0
- package/dist/types/src/config/config-source.d.ts.map +1 -0
- package/dist/types/{config → src/config}/index.d.ts +0 -0
- package/dist/types/src/config/index.d.ts.map +1 -0
- package/dist/types/{core → src/core}/common.d.ts +0 -0
- package/dist/types/src/core/common.d.ts.map +1 -0
- package/dist/types/{core → src/core}/config.d.ts +0 -0
- package/dist/types/src/core/config.d.ts.map +1 -0
- package/dist/types/{core → src/core}/constants.d.ts +0 -0
- package/dist/types/src/core/constants.d.ts.map +1 -0
- package/dist/types/{core → src/core}/errors.d.ts +0 -0
- package/dist/types/src/core/errors.d.ts.map +1 -0
- package/dist/types/{core → src/core}/hypernum.d.ts +0 -0
- package/dist/types/src/core/hypernum.d.ts.map +1 -0
- package/dist/types/{core → src/core}/index.d.ts +0 -0
- package/dist/types/src/core/index.d.ts.map +1 -0
- package/dist/types/{index.d.ts → src/index.d.ts} +1 -1
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/arithmetic.d.ts +0 -0
- package/dist/types/src/operations/arithmetic.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/bitwise.d.ts +0 -0
- package/dist/types/src/operations/bitwise.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/comparison.d.ts +0 -0
- package/dist/types/src/operations/comparison.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/conversion.d.ts +0 -0
- package/dist/types/src/operations/conversion.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/factorial.d.ts +0 -0
- package/dist/types/src/operations/factorial.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/index.d.ts +0 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/power.d.ts +0 -0
- package/dist/types/src/operations/power.d.ts.map +1 -0
- package/dist/types/{storage → src/storage}/Heap.d.ts +0 -0
- package/dist/types/src/storage/Heap.d.ts.map +1 -0
- package/dist/types/{storage → src/storage}/index.d.ts +0 -0
- package/dist/types/src/storage/index.d.ts.map +1 -0
- package/dist/types/{structures → src/structures}/ackermann.d.ts +0 -0
- package/dist/types/src/structures/ackermann.d.ts.map +1 -0
- package/dist/types/{structures → src/structures}/big-array.d.ts +0 -0
- package/dist/types/src/structures/big-array.d.ts.map +1 -0
- package/dist/types/{structures → src/structures}/index.d.ts +0 -0
- package/dist/types/src/structures/index.d.ts.map +1 -0
- package/dist/types/{structures → src/structures}/number-tree.d.ts +0 -0
- package/dist/types/src/structures/number-tree.d.ts.map +1 -0
- package/dist/types/{structures → src/structures}/power-tower.d.ts +0 -0
- package/dist/types/src/structures/power-tower.d.ts.map +1 -0
- package/dist/types/{utils → src/utils}/formatting.d.ts +0 -0
- package/dist/types/src/utils/formatting.d.ts.map +1 -0
- package/dist/types/{utils → src/utils}/index.d.ts +0 -0
- package/dist/types/src/utils/index.d.ts.map +1 -0
- package/dist/types/{utils → src/utils}/parser.d.ts +0 -0
- package/dist/types/src/utils/parser.d.ts.map +1 -0
- package/dist/types/{utils → src/utils}/precision.d.ts +0 -0
- package/dist/types/src/utils/precision.d.ts.map +1 -0
- package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
- package/dist/types/src/utils/validation.d.ts.map +1 -0
- package/package.json +169 -164
- package/rollup.config.js +163 -161
- package/src/cli/hypernum.js +272 -0
- package/src/config/config-loader.ts +0 -0
- package/src/config/config-parser.ts +160 -160
- package/src/config/config-resolver.ts +0 -0
- package/src/config/config-source.ts +0 -0
- package/src/config/index.ts +0 -0
- package/src/core/common.ts +184 -184
- package/src/core/config.ts +392 -392
- package/src/core/constants.ts +101 -101
- package/src/core/errors.ts +202 -202
- package/src/core/hypernum.ts +240 -240
- package/src/core/index.ts +4 -4
- package/src/index.ts +179 -182
- package/src/operations/arithmetic.ts +332 -332
- package/src/operations/bitwise.ts +366 -366
- package/src/operations/comparison.ts +271 -271
- package/src/operations/conversion.ts +399 -399
- package/src/operations/factorial.ts +278 -278
- package/src/operations/index.ts +4 -4
- package/src/operations/power.ts +315 -315
- package/src/storage/Heap.ts +237 -237
- package/src/storage/index.ts +0 -0
- package/src/structures/ackermann.ts +232 -232
- package/src/structures/big-array.ts +305 -305
- package/src/structures/index.ts +3 -3
- package/src/structures/number-tree.ts +403 -403
- package/src/structures/power-tower.ts +277 -277
- package/src/types/common.d.ts +356 -356
- package/src/types/core.d.ts +160 -160
- package/src/types/index.d.ts +1 -1
- package/src/utils/formatting.ts +245 -245
- package/src/utils/index.ts +4 -4
- package/src/utils/parser.ts +244 -244
- package/src/utils/precision.ts +216 -216
- package/src/utils/validation.ts +182 -182
- package/tsconfig.json +83 -83
- package/dist/types/config/config-loader.d.ts.map +0 -1
- package/dist/types/config/config-parser.d.ts.map +0 -1
- package/dist/types/config/config-resolver.d.ts.map +0 -1
- package/dist/types/config/config-source.d.ts.map +0 -1
- package/dist/types/config/index.d.ts.map +0 -1
- package/dist/types/core/common.d.ts.map +0 -1
- package/dist/types/core/config.d.ts.map +0 -1
- package/dist/types/core/constants.d.ts.map +0 -1
- package/dist/types/core/errors.d.ts.map +0 -1
- package/dist/types/core/hypernum.d.ts.map +0 -1
- package/dist/types/core/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/operations/arithmetic.d.ts.map +0 -1
- package/dist/types/operations/bitwise.d.ts.map +0 -1
- package/dist/types/operations/comparison.d.ts.map +0 -1
- package/dist/types/operations/conversion.d.ts.map +0 -1
- package/dist/types/operations/factorial.d.ts.map +0 -1
- package/dist/types/operations/index.d.ts.map +0 -1
- package/dist/types/operations/power.d.ts.map +0 -1
- package/dist/types/storage/Heap.d.ts.map +0 -1
- package/dist/types/storage/index.d.ts.map +0 -1
- package/dist/types/structures/ackermann.d.ts.map +0 -1
- package/dist/types/structures/big-array.d.ts.map +0 -1
- package/dist/types/structures/index.d.ts.map +0 -1
- package/dist/types/structures/number-tree.d.ts.map +0 -1
- package/dist/types/structures/power-tower.d.ts.map +0 -1
- package/dist/types/utils/formatting.d.ts.map +0 -1
- package/dist/types/utils/index.d.ts.map +0 -1
- package/dist/types/utils/parser.d.ts.map +0 -1
- package/dist/types/utils/precision.d.ts.map +0 -1
- 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
|
package/src/config/index.ts
CHANGED
|
File without changes
|