{"_id":"n-base-integer","_rev":"5-d60cf9561428e9ce5bfa7431c047d0df","name":"n-base-integer","dist-tags":{"latest":"1.1.3"},"versions":{"1.0.0":{"name":"n-base-integer","version":"1.0.0","keywords":["arbitrary base","base conversion","integer","arithmetic","addition","subtraction","multiplication","comparison","utility","typescript","javascript"],"author":{"name":"KasukabeTsumugi","email":"futami16237@gmail.com"},"license":"MIT","_id":"n-base-integer@1.0.0","maintainers":[{"name":"baendlorel","email":"futami16237@gmail.com"}],"homepage":"https://github.com/baendlorel/n-base-integer#readme","bugs":{"url":"https://github.com/baendlorel/n-base-integer/issues"},"dist":{"shasum":"c674cdae8c71efdb5fde7c48de72adf0eb64e833","tarball":"https://registry.npmjs.org/n-base-integer/-/n-base-integer-1.0.0.tgz","fileCount":6,"integrity":"sha512-B6PPCBxnuBFT+SLIyjoWazbr6QV5yhcOHahGDir75+tJyiokjVEE7IIUFuRMif1PIKo81oi6JYtAfbikk1XlZw==","signatures":[{"sig":"MEUCIQDRXHe44o8xbpCk32v5lU4tnytVNYgeYgpSTpNKvDDZYAIgb4PtJQ8hzjz7WeLdGt4NzAMzS8024yhxtZOFgbf8Nzk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":103085},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"e4c9d08de893411348a2e198d46ec5fae6160727","scripts":{"lint":"eslint .","test":"clear & jest","build":"rimraf dist && pnpm plugin && rollup -c","plugin":"tsc -p tsconfig.plugin.json"},"_npmUser":{"name":"baendlorel","actor":{"name":"baendlorel","type":"user","email":"futami16237@gmail.com"},"email":"futami16237@gmail.com"},"repository":{"url":"git+https://github.com/baendlorel/n-base-integer.git","type":"git"},"_npmVersion":"11.4.2","description":"Arbitrary-base integer with custom charset, supporting addition, subtraction, multiplication, comparison, and common base conversion utilities.","directories":{},"_nodeVersion":"22.14.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.0.3","tslib":"^2.8.1","eslint":"^9.30.0","rimraf":"^6.0.1","rollup":"^4.44.1","tsc-alias":"^1.8.16","@babel/cli":"^7.27.2","@eslint/js":"^9.30.0","typescript":"^5.8.3","@babel/core":"^7.27.7","@jest/types":"^30.0.1","@types/node":"^24.0.4","@jest/globals":"^30.0.3","@babel/preset-env":"^7.27.2","@jest/test-result":"^30.0.2","rollup-plugin-dts":"^6.2.1","typescript-eslint":"^8.35.1","@rollup/plugin-alias":"^5.1.1","@rollup/plugin-babel":"^6.0.4","@rollup/plugin-terser":"^0.4.4","@rollup/plugin-commonjs":"^28.0.6","@babel/preset-typescript":"^7.27.1","@rollup/plugin-typescript":"^12.1.3","@rollup/plugin-node-resolve":"^16.0.1","@babel/plugin-transform-classes":"^7.27.7","@babel/plugin-proposal-decorators":"^7.27.1","@babel/plugin-syntax-class-properties":"^7.12.13"},"peerDependencies":{"jest":"^30.0.0"},"_npmOperationalInternal":{"tmp":"tmp/n-base-integer_1.0.0_1752135790825_0.06198675584182323","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"n-base-integer","version":"1.0.1","keywords":["arbitrary base","base conversion","integer","arithmetic","addition","subtraction","multiplication","comparison","utility","typescript","javascript"],"author":{"name":"KasukabeTsumugi","email":"futami16237@gmail.com"},"license":"MIT","_id":"n-base-integer@1.0.1","maintainers":[{"name":"baendlorel","email":"futami16237@gmail.com"}],"homepage":"https://github.com/baendlorel/n-base-integer#readme","bugs":{"url":"https://github.com/baendlorel/n-base-integer/issues"},"dist":{"shasum":"5e1723a5ab2ae7d4dd482e1d5c27aab8997f7f4e","tarball":"https://registry.npmjs.org/n-base-integer/-/n-base-integer-1.0.1.tgz","fileCount":6,"integrity":"sha512-tPojWsSPI3fqst3nOFoywLWYCd6nkEYVr3zloAGj8JFzqOlv7KZMAIOfNYb+axP60SAHkof6EV6N5BV9PWZBQw==","signatures":[{"sig":"MEUCIE9e/b+cOABj/Vh6YnXG7Xx1b0G+jSBG+mjAGwJJzwFdAiEAw8AGOfcHHyRuXvCdyK9tAN89sfqjNKY6NyZFrYzyxw0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":103272},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"4c38eb196a371c8b182a6d59f64abafcd6463ecf","scripts":{"lint":"eslint .","test":"clear & jest","build":"rimraf dist && pnpm plugin && rollup -c","plugin":"tsc -p tsconfig.plugin.json"},"_npmUser":{"name":"baendlorel","email":"futami16237@gmail.com"},"repository":{"url":"git+https://github.com/baendlorel/n-base-integer.git","type":"git"},"_npmVersion":"10.9.3","description":"Arbitrary-base integer with custom charset, supporting addition, subtraction, multiplication, comparison, and common base conversion utilities.","directories":{},"_nodeVersion":"22.18.0","_hasShrinkwrap":false,"description_zh":"N进制数类，支持加减乘除、比较大小、进制转换","devDependencies":{"jest":"^30.0.3","tslib":"^2.8.1","eslint":"^9.30.0","rimraf":"^6.0.1","rollup":"^4.44.1","tsc-alias":"^1.8.16","@babel/cli":"^7.27.2","@eslint/js":"^9.30.0","typescript":"^5.8.3","@babel/core":"^7.27.7","@jest/types":"^30.0.1","@types/node":"^24.0.4","@jest/globals":"^30.0.3","@babel/preset-env":"^7.27.2","@jest/test-result":"^30.0.2","rollup-plugin-dts":"^6.2.1","typescript-eslint":"^8.35.1","@rollup/plugin-alias":"^5.1.1","@rollup/plugin-babel":"^6.0.4","@rollup/plugin-terser":"^0.4.4","@rollup/plugin-commonjs":"^28.0.6","@babel/preset-typescript":"^7.27.1","@rollup/plugin-typescript":"^12.1.3","@rollup/plugin-node-resolve":"^16.0.1","@babel/plugin-transform-classes":"^7.27.7","@babel/plugin-proposal-decorators":"^7.27.1","@babel/plugin-syntax-class-properties":"^7.12.13"},"peerDependencies":{"jest":"^30.0.0"},"_npmOperationalInternal":{"tmp":"tmp/n-base-integer_1.0.1_1755742084990_0.8361825337947568","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"n-base-integer","version":"1.1.0","keywords":["arbitrary base","base conversion","integer","arithmetic","addition","subtraction","multiplication","comparison","utility","typescript","javascript"],"author":{"name":"KasukabeTsumugi","email":"futami16237@gmail.com"},"license":"MIT","_id":"n-base-integer@1.1.0","maintainers":[{"name":"baendlorel","email":"futami16237@gmail.com"}],"homepage":"https://github.com/baendlorel/n-base-integer#readme","bugs":{"url":"https://github.com/baendlorel/n-base-integer/issues"},"dist":{"shasum":"6c962fb256ba74d84b2b777e2b1d9a85d75459d6","tarball":"https://registry.npmjs.org/n-base-integer/-/n-base-integer-1.1.0.tgz","fileCount":5,"integrity":"sha512-FLL4XkYt5RN5D8f6jEm4SD1E67KG6gZVNywyngroX/rmIzptzxOEgWDAaKLJKf1Ci3JV+F2kyKQpBe4Y0eZyng==","signatures":[{"sig":"MEUCIQCkmLUgGj5ls6FJAv1uWKXtUn/a6oONGv5HGWUGWNG70gIgfQe9cXBG7xaBS/JYR92t6B9i0/uCVfuWKNV0tO9NlwI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":32514},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"6f9637f66d578a2bd0dd2c38fa090aebbaa86509","_npmUser":{"name":"baendlorel","email":"futami16237@gmail.com"},"repository":{"url":"git+https://github.com/baendlorel/n-base-integer.git","type":"git"},"_npmVersion":"11.5.1","description":"Arbitrary-base integer with custom charset, supporting addition, subtraction, multiplication, comparison, and common base conversion utilities.","directories":{},"_nodeVersion":"24.5.0","_hasShrinkwrap":false,"description_zh":"N进制数类，支持加减乘除、比较大小、进制转换","devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/n-base-integer_1.1.0_1770968509971_0.3734020271909855","host":"s3://npm-registry-packages-npm-production"}},"1.1.2":{"name":"n-base-integer","version":"1.1.2","keywords":["arbitrary base","base conversion","integer","arithmetic","addition","subtraction","multiplication","comparison","utility","typescript","javascript"],"author":{"name":"KasukabeTsumugi","email":"futami16237@gmail.com"},"license":"MIT","_id":"n-base-integer@1.1.2","maintainers":[{"name":"baendlorel","email":"futami16237@gmail.com"}],"homepage":"https://github.com/baendlorel/kt-packages/tree/main/packages/n-base-integer#readme","bugs":{"url":"https://github.com/baendlorel/kt-packages/issues"},"dist":{"shasum":"2aee61bd13c4281cd1bc0bb73855e536e23b1be6","tarball":"https://registry.npmjs.org/n-base-integer/-/n-base-integer-1.1.2.tgz","fileCount":5,"integrity":"sha512-GBLif6WqMxDBPvmWCq1hnBxwM2giAVOP+/NRI8TJH3bXN0gRY/8lLsvn1CRGNcWmt0y+vYIDQCVtQxviK4OcWA==","signatures":[{"sig":"MEYCIQCeBsHu2cR/4dkdEKuM2ih1cGOH3wYIUXWw+uua4r/CEwIhAIwdha/XGtuGIIVpdg6Mo/JyXwYR18aIw0T//ALgzxup","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":37454},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"2a617c9a97c89a9d6b0ca0412a3d9d6adf91bfde","_npmUser":{"name":"baendlorel","email":"futami16237@gmail.com"},"repository":{"url":"git+https://github.com/baendlorel/kt-packages.git","type":"git","directory":"packages/n-base-integer"},"_npmVersion":"11.5.1","description":"Arbitrary-base integer with custom charset, supporting addition, subtraction, multiplication, comparison, and common base conversion utilities.","directories":{},"_nodeVersion":"24.5.0","_hasShrinkwrap":false,"description_zh":"N进制数类，支持加减乘除、比较大小、进制转换","devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/n-base-integer_1.1.2_1771325468820_0.30651695976119675","host":"s3://npm-registry-packages-npm-production"}},"1.1.3":{"_id":"n-base-integer@1.1.3","bugs":{"url":"https://github.com/baendlorel/tsumugi-lib/issues"},"dist":{"shasum":"ea5db9ff7da0b1837db74f048d461ce8a694fb3d","tarball":"https://registry.npmjs.org/n-base-integer/-/n-base-integer-1.1.3.tgz","fileCount":9,"integrity":"sha512-dlX3JO7ymlRMI+d23PsWDSkPVUyvsoeCxLFFK1yc8xt4MG82Xl5pC4iENM7AHAzKjcaimj6Cs/KIoPuzC+jLtg==","signatures":[{"sig":"MEYCIQDx4TdakZO1fPFiOI5f19nNfzEOaIGJoDUcdJM7Xq6T7gIhAO5CsYUmbyfEAv7CVk5duqCq9eD2WtBx845WVSUJ0dUh","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD+gnsRXtgMw0g+wHbZUF8dqGKnbTicS+YgAAWP6OvhcAIhAMQHGEesQZ/XapUAb30zNOwFwd0CmplyEHl0se3Q//Ho"}],"unpackedSize":186826},"main":"dist/index.js","name":"n-base-integer","type":"module","types":"dist/index.d.ts","author":{"name":"KasukabeTsumugi","email":"futami16237@gmail.com"},"gitHead":"290ada4e19a0c279c46a81376627cd2f6e7382b4","license":"MIT","version":"1.1.3","_npmUser":{"name":"baendlorel","email":"futami16237@gmail.com"},"homepage":"https://github.com/baendlorel/tsumugi-lib/tree/main/packages/n-base-integer#readme","keywords":["arbitrary base","base conversion","integer","arithmetic","addition","subtraction","multiplication","comparison","utility","typescript","javascript"],"repository":{"url":"git+https://github.com/baendlorel/tsumugi-lib.git","type":"git","directory":"packages/n-base-integer"},"_npmVersion":"11.18.0","description":"Arbitrary-base integer with custom charset, supporting addition, subtraction, multiplication, comparison, and common base conversion utilities.","directories":{},"maintainers":[{"name":"baendlorel","email":"futami16237@gmail.com"}],"_nodeVersion":"24.5.0","_hasShrinkwrap":false,"description_zh":"N进制数类，支持加减乘除、比较大小、进制转换","devDependencies":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/n-base-integer_1.1.3_1791770958858_0.7011106714676909"}}},"time":{"created":"2025-07-10T08:23:10.824Z","modified":"2026-10-12T02:09:19.110Z","1.0.0":"2025-07-10T08:23:11.001Z","1.0.1":"2025-08-21T02:08:05.186Z","1.1.0":"2026-02-13T07:41:50.111Z","1.1.2":"2026-02-17T10:51:08.957Z","1.1.3":"2026-10-12T02:09:18.938Z"},"bugs":{"url":"https://github.com/baendlorel/tsumugi-lib/issues"},"author":{"name":"KasukabeTsumugi","email":"futami16237@gmail.com"},"license":"MIT","homepage":"https://github.com/baendlorel/tsumugi-lib/tree/main/packages/n-base-integer#readme","keywords":["arbitrary base","base conversion","integer","arithmetic","addition","subtraction","multiplication","comparison","utility","typescript","javascript"],"repository":{"url":"git+https://github.com/baendlorel/tsumugi-lib.git","type":"git","directory":"packages/n-base-integer"},"description":"Arbitrary-base integer with custom charset, supporting addition, subtraction, multiplication, comparison, and common base conversion utilities.","maintainers":[{"name":"baendlorel","email":"futami16237@gmail.com"}],"readme":"# n-base-integer\n\nA TypeScript library for creating, converting, and performing arithmetic with integers in arbitrary bases (n-base), supporting custom charsets and large numbers.\n\nFor more awesome packages, check out [my homepage💛](https://baendlorel.github.io/?repoType=npm)\n\n## Features\n\n- **Arbitrary base support**: Create integers in any base from 2 to 1,000,000\n- **Custom charsets**: Support any character set, including emojis\n- **Large number handling**: Beyond JavaScript's native number limits\n- **Complete arithmetic operations**: Addition, subtraction, multiplication, division, modulo, and power\n- **Immutable and mutable operations**: Choose between creating new instances or modifying in-place\n- **Base conversion**: Convert between different bases efficiently\n- **Type-safe**: Full TypeScript support with comprehensive type definitions\n\n## Installation\n\n```bash\nnpm install n-base-integer\n```\n\n## Quick Start\n\n```typescript\nimport { NBaseInteger } from 'n-base-integer';\n\n// Create from string (default base 10)\nconst a = NBaseInteger('12345');\n\n// Create with specific base\nconst binary = NBaseInteger('1010', 2); // Binary\nconst hex = NBaseInteger('1A3F', 16); // Hexadecimal\n\n// Create with custom charset\nconst custom = NBaseInteger('🔥💧🌍', 3, '🔥💧🌍');\n// Since '🔥💧🌍' -> '012'\ncustom.toString(); // '💧🌍'\n\n// Create from regular number\nconst fromNum = NBaseInteger.from(255, 16); // 255 in base 16\n\n// Create from digit array [1,2,3] -> 123\nconst fromDigits = NBaseInteger.fromDigits([1, 2, 3], 10);\n```\n\n---\n\n## API Reference\n\n### Factory Methods\n\n- `NBaseInteger(str, base?, charset?)` - Create from string\n- `NBaseInteger.from(number, base)` - Create from regular number\n- `NBaseInteger.fromDigits(digits[], base, negative?)` - Create from digit array\n- `NBaseInteger.defaultCharset` - Get default charset ('0-9A-Za-z')\n- `NBaseInteger.setDefaultCharset(charset)` - Set default charset\n\n### Properties\n\n- `.base` - The base of this number (readonly)\n- `.isZero` - True if the number is zero\n- `.isOdd` / `.isEven` - Check parity\n- `.sgn` - Sign of the number (-1, 0, or 1), same as `sgn(x)` in math\n\n### Arithmetic Operations\n\n**Immutable operations** (return new instance):\n\n- `add(n: NBaseInteger | number)` - Addition\n- `sub(n: NBaseInteger | number)` - Subtraction\n- `mul(n: NBaseInteger | number)` - Multiplication\n- `div(n: NBaseInteger | number)` - Division (quotient only)\n- `mod(n: NBaseInteger | number)` - Modulo (remainder only)\n- `divmod(n: NBaseInteger | number)` - Division with remainder `{ quotient, remainder }`\n- `pow(exponent: NBaseInteger | number)` - Exponentiation\n\n**Mutable operations** (modify in place):\n\n- `addAssign(n: NBaseInteger | number)` - Addition\n- `subAssign(n: NBaseInteger | number)` - Subtraction\n- `mulAssign(n: NBaseInteger | number)` - Multiplication\n- `divAssign(n: NBaseInteger | number)` - Division\n- `modAssign(n: NBaseInteger | number)` - Modulo\n- `inc()` - Increment by 1\n- `dec()` - Decrement by 1\n\n```typescript\nconst a = NBaseInteger('100');\nconst b = NBaseInteger('7');\n\n// Immutable operations\nconst sum = a.add(b); // 107\nconst product = a.mul(3); // 300\nconst { quotient, remainder } = a.divmod(b); // 14 remainder 2\n\n// Mutable operations\na.addAssign(b); // a becomes 107\na.inc(); // a becomes 108\n```\n\n### Comparison Operations\n\n- `cmp(n)` - Compare `this` to `n`, return (-1, 0, 1)\n- `eq(n)` / `ne(n)` - Equal / not equal\n- `gt(n)` / `gte(n)` - Greater than / greater than or equal\n- `lt(n)` / `lte(n)` - Less than / less than or equal\n- Absolute comparisons: `cmpAbs(n)`, `eqAbs(n)`, `gtAbs(n)`, etc.\n\n```typescript\nif (a.gt(b)) {\n  console.log('a is greater than b');\n}\n\nconsole.log(a.cmp(b)); // -1, 0, or 1\n```\n\n### Sign Operations\n\n- `negate()` - Get `-this` (immutable)\n- `negateAssign()` - Set `this` to `-this`\n- `abs()` - Get absolute value (immutable)\n- `absAssign()` - Absolute value in place\n- `setSign(sgn: -1 | 0 | 1)` - Set sign to -1, 0, or 1\n- `zero()` - Set to zero\n\n```typescript\nconst n = NBaseInteger('-42');\nconst positive = n.abs(); // 42\nn.negateAssign(); // n becomes 42\nn.setSign(-1); // n becomes -42\n```\n\n### Base Conversion\n\n- `convertTo(base)` - Convert to another base\n- `toBinary()` - Convert to binary (base 2)\n- `toOctal()` - Convert to octal (base 8)\n- `toDecimal()` - Convert to decimal (base 10)\n- `toHex()` - Convert to hexadecimal (base 16)\n\n```typescript\nconst decimal = NBaseInteger('255');\nconst binary = decimal.toBinary(); // '11111111' in base 2\nconst hex = decimal.toHex(); // 'FF' in base 16\nconst base36 = decimal.convertTo(36); // '73' in base 36\n```\n\n### Other Methods\n\n- `toString(charset?: string | null)` - Convert to string representation.\n\n  - `charset` default value is '0...9A...Za...z'(can be set via `NBaseInteger.setDefaultCharset()`).\n    - note that `charset` can be omitted but **not explicitly be `undefined`**\n  - When `charset` is `null`, just return the digits separated with comma.\n  - When `charset` is `string`, use it to stringify every digit after check.\n\n- `toNumber()` - Convert to JavaScript number (throws if > `Number.MAX_SAFE_INTEGER`)\n- `toBigInt()` - Convert to JavaScript BigInt\n- `clone()` - Create a copy\n\n```typescript\nconst n = NBaseInteger('1010', 2);\n\nconsole.log(n.toString()); // '1010'\nconsole.log(n.toString(null)); // '0,1,0,1' (digit array)\nconsole.log(n.toNumber()); // 10\nconsole.log(n.toBigInt()); // 10n\n\n// Custom charset for output\nconst custom = NBaseInteger('255').convertTo(3);\nconsole.log(custom.toString('ABC')); // Uses A=0, B=1, C=2\n```\n\n### Advanced Usage\n\n**Custom Character Sets:**\n\n```typescript\n// Emoji base-3 number system\nconst emojiNum = NBaseInteger('🔥💧🌍', 3, '🔥💧🌍');\nconsole.log(emojiNum.toDecimal().toString()); // Converts to decimal\n\n// Base-64 with custom charset\nconst base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\nconst b64num = NBaseInteger('Hello', 64, base64);\n```\n\n**Large Number Support:**\n\n```typescript\n// Numbers beyond JavaScript's safe integer limit\nconst huge = NBaseInteger('999999999999999999999999999999');\nconst result = huge.mul(huge); // Still works perfectly\nconsole.log(result.toString()); // Exact result, no precision loss\n```\n\n**Base Conversion Chain:**\n\n```typescript\nconst original = NBaseInteger('777', 8); // Octal\nconst decimal = original.toDecimal(); // Convert to decimal\nconst binary = decimal.toBinary(); // Then to binary\nconst hex = binary.toHex(); // Finally to hex\n```\n\n## Performance Notes\n\n- Operations are optimized for efficiency with large numbers\n- Base conversions use efficient algorithms for arbitrary precision\n- In-place operations (`*Assign` methods) create less objects when you don't need immutability\n- Caching is used internally for frequently accessed `maxInt` and `charsets`\n\n---\n\n## License\n\nMIT\n","readmeFilename":"README.md"}