diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..4e44c5c --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,116 @@ +name: build, test (node and browser), coverage, publish to NPM + +on: + push: + tags: + - "v*.*.*" + workflow_dispatch: + +jobs: + build: + name: build + runs-on: ubuntu-latest + steps: + - name: Git checkout + uses: actions/checkout@v3 + + - name: Use Node.js 18 + uses: actions/setup-node@v3 + with: + node-version: 18.x + registry-url: "https://registry.npmjs.org" + + - name: install + run: npm ci + + - name: build + run: npm run build + + nodetests: + name: tests in Node.js + needs: [build] + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + node-version: [16.x, 18.x] + # When set to true, GitHub cancels all in-progress jobs if any matrix job fails. + fail-fast: false + # The maximum number of jobs that can run simultaneously. Set to 1 if you can't run tests in parallel + # max-parallel: 1 + steps: + - name: Git checkout + uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + registry-url: "https://registry.npmjs.org" + + - name: install + run: npm i + + - name: node esm tests + run: npm run test:node-esm + # env: + # VARIABLE1: ${{ secrets.VARIABLE1 }} + # VARIABLE2: ${{ secrets.VARIABLE2 }} + + - name: node cjs tests + run: npm run test:node-cjs + # env: + # VARIABLE1: ${{ secrets.VARIABLE1 }} + # VARIABLE2: ${{ secrets.VARIABLE2 }} + + browsertests: + needs: [build] + name: tests in browser + runs-on: ubuntu-latest + steps: + - name: Git checkout + uses: actions/checkout@v3 + + - name: Use Node.js 18 + uses: actions/setup-node@v3 + with: + node-version: 18.x + registry-url: "https://registry.npmjs.org" + + - name: install + run: npm ci + + - name: browser tests + run: npm run test:browser-headless + # env: + # VARIABLE1: ${{ secrets.VARIABLE1 }} + # VARIABLE2: ${{ secrets.VARIABLE2 }} + + publish: + needs: [nodetests, browsertests] + runs-on: ubuntu-latest + steps: + - name: Git checkout + uses: actions/checkout@v3 + + - name: Install Node.js, NPM and Yarn + uses: actions/setup-node@v3 + with: + node-version: "18.x" + registry-url: "https://registry.npmjs.org" + + - name: install + run: npm ci + + - name: coverage + run: npm run coverage + + - name: send report to coveralls.io + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: NPM publish + run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml deleted file mode 100644 index 3e8f8cd..0000000 --- a/.github/workflows/nodejs.yml +++ /dev/null @@ -1,81 +0,0 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Node CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - name: build, test, check coverage - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [16, 18] - steps: - - uses: actions/checkout@v2 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: install - run: npm ci - - - name: build - run: npm run build - - - name: test - run: npm test - - publication: - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - uses: EndBug/version-check@v1 - id: check - - - name: check version changes - if: steps.check.outputs.changed == 'true' - run: 'echo "Version change found! New version: ${{ steps.check.outputs.version }} (${{ steps.check.outputs.type }})"' - - - uses: actions/setup-node@v1 - if: steps.check.outputs.changed == 'true' - with: - node-version: 18 - registry-url: https://registry.npmjs.org/ - - - name: install - if: steps.check.outputs.changed == 'true' - run: npm ci - - - name: build - if: steps.check.outputs.changed == 'true' - run: npm run build - - - name: test - if: steps.check.outputs.changed == 'true' - run: npm test - - - name: create code coverage report - if: steps.check.outputs.changed == 'true' - run: npm run coverage - - - name: send report to coveralls.io - if: steps.check.outputs.changed == 'true' - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - - - name: publish to NPM - if: steps.check.outputs.changed == 'true' - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index f901e53..7b23e6d 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ import * as bigintModArith from 'bigint-mod-arith' The appropriate version for browser or node is automatically exported. -You can also download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/main/dist/bundles/iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/main/dist/bundles/esm.min.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/main/dist/bundles/umd.js) and manually add it to your project, or, if you have already imported `bigint-mod-arith` to your project, just get the bundles from `node_modules/bigint-mod-arith/dist/bundles/`. +You can also download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/main/dist/bundle.iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/main/dist/bundle.esm.min.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/main/dist/bundle.umd.js) and manually add it to your project, or, if you have already imported `bigint-mod-arith` to your project, just get the bundles from `node_modules/bigint-mod-arith/dist/bundles/`. An example of usage could be: diff --git a/build/bin/mocha-ts.cjs b/build/bin/mocha-ts.cjs index 2a96f20..c8dbe49 100644 --- a/build/bin/mocha-ts.cjs +++ b/build/bin/mocha-ts.cjs @@ -2,7 +2,7 @@ const fs = require('fs') const path = require('path') const glob = require('glob') -const minimatch = require('minimatch') +const minimatch = require('minimatch').minimatch const rimraf = require('rimraf') const runScript = require('../run-script.cjs') @@ -58,9 +58,11 @@ function parse () { process.exit(1) } - let testsGlob = (args.pop() ?? '').replace(/^['"]/, '').replace(/['"]$/, '') // Let us remove surrounding quotes in string (it gives issues in windows) - if (testsGlob === '') { + let testsGlob = args.pop() + if (testsGlob === undefined) { testsGlob = '{src/ts/**/*.spec.ts,test/**/*.ts}' + } else { + testsGlob = testsGlob.replace(/^['"]/, '').replace(/['"]$/, '') // Let us remove surrounding quotes in string (it gives issues in windows) } const mochaArgs = [] diff --git a/build/rollup-plugin-dts.js b/build/rollup-plugin-dts.js index 547c668..b5151a3 100644 --- a/build/rollup-plugin-dts.js +++ b/build/rollup-plugin-dts.js @@ -1,4 +1,4 @@ -import { mkdirSync, readFileSync, writeFileSync } from 'fs' +import { mkdirSync, writeFileSync } from 'fs' import ts from 'typescript' import { join, dirname, extname } from 'path' import { sync } from 'rimraf' @@ -8,9 +8,7 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) const { readJsonConfigFile, sys, parseJsonSourceFileConfigFileContent, createCompilerHost, createProgram } = ts const rootDir = join(__dirname, '..') -const pkgJson = JSON.parse(readFileSync(join(rootDir, 'package.json'))) const srcFile = join(rootDir, 'src/ts/index.ts') -const outDir = dirname(join(rootDir, pkgJson.types)) const tsConfigPath = join(rootDir, 'tsconfig.json') @@ -20,31 +18,31 @@ const configFile = readJsonConfigFile(tsConfigPath, (file) => { const tsConfig = parseJsonSourceFileConfigFileContent(configFile, sys, dirname(tsConfigPath)) -const compilerOptions = { - ...tsConfig.options, - declaration: true, - declarationMap: true, - emitDeclarationOnly: true, - outDir -} - -const host = createCompilerHost(compilerOptions) - -host.writeFile = (fileName, contents) => { - mkdirSync(dirname(fileName), { recursive: true }) - writeFileSync(fileName, contents) - - // we also write the .d.cts types - let fileName2 = '' - if (extname(fileName) === '.ts') { - fileName2 = fileName.slice(0, -2) + 'cts' - } else { // ext is .d.ts.map - fileName2 = fileName.slice(0, -6) + 'cts.map' +export const compile = (outDir) => { + const compilerOptions = { + ...tsConfig.options, + declaration: true, + declarationMap: true, + emitDeclarationOnly: true, + outDir + } + + const host = createCompilerHost(compilerOptions) + + host.writeFile = (fileName, contents) => { + mkdirSync(dirname(fileName), { recursive: true }) + writeFileSync(fileName, contents) + + // we also write the .d.cts types + let fileName2 = '' + if (extname(fileName) === '.ts') { + fileName2 = fileName.slice(0, -2) + 'cts' + } else { // ext is .d.ts.map + fileName2 = fileName.slice(0, -6) + 'cts.map' + } + writeFileSync(fileName2, contents) } - writeFileSync(fileName2, contents) -} -export const compile = () => { // Clear the types dir sync(outDir) // Prepare and emit the d.ts files diff --git a/build/rollup.config.js b/build/rollup.config.js index 91bb391..c556e73 100644 --- a/build/rollup.config.js +++ b/build/rollup.config.js @@ -1,27 +1,28 @@ 'use strict' +import commonjs from '@rollup/plugin-commonjs' import inject from '@rollup/plugin-inject' +import json from '@rollup/plugin-json' import { nodeResolve as resolve } from '@rollup/plugin-node-resolve' import replace from '@rollup/plugin-replace' import terser from '@rollup/plugin-terser' -import typescriptPlugin from '@rollup/plugin-typescript' -import commonjs from '@rollup/plugin-commonjs' -import json from '@rollup/plugin-json' - -import { dirname, join } from 'path' +import rollupPluginTs from '@rollup/plugin-typescript' import { existsSync, readFileSync } from 'fs' - -// import { browser, name as _name, exports } from '../package.json' assert { type: 'json' } +import { dirname, join } from 'path' +import dts from 'rollup-plugin-dts' import { compile } from './rollup-plugin-dts.js' +import { builtinModules } from 'module' import * as url from 'url' const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) const rootDir = join(__dirname, '..') const pkgJson = JSON.parse(readFileSync(join(rootDir, 'package.json'))) -// const dstDir = join(rootDir, directories.dist) +const pkgJsonLock = JSON.parse(readFileSync(join(rootDir, 'package-lock.json'))) const srcDir = join(rootDir, 'src', 'ts') +const tsConfigPath = join(rootDir, 'tsconfig.json') + function camelise (str) { return str.replace(/-([a-z])/g, function (m, w) { @@ -29,6 +30,11 @@ function camelise (str) { }) } +function isDevDependency (moduleName) { + const packageEntry = pkgJsonLock.packages['node_modules/' + moduleName] + return (packageEntry ?? {}).dev === true +} + const regex = /^(?:(?@.*?)\/)?(?.*)/ // We are going to take only the package name part if there is a scope, e.g. @my-org/package-name const { name } = pkgJson.name.match(regex).groups const pkgCamelisedName = camelise(name) @@ -36,9 +42,9 @@ const pkgCamelisedName = camelise(name) const input = join(srcDir, 'index.ts') if (existsSync(input) !== true) throw new Error('The entry point should be index.ts') -const tsBundleOptions = { - tsconfig: join(rootDir, 'tsconfig.json'), - outDir: undefined, // ignore outDir in tsconfig.json +const tsPluginOptions = { + tsconfig: tsConfigPath, + outDir: undefined, include: ['src/ts/**/*', 'build/typings/is-browser.d.ts'], exclude: ['src/**/*.spec.ts'] } @@ -48,23 +54,47 @@ const sourcemapOutputOptions = { sourcemapExcludeSources: true } -function compileDts () { +function compileDts (outDir) { return { name: 'compile-dts', closeBundle () { - compile() + compile(outDir) } } } +function resolveOnly (module) { // if a dev dependency is imported we will resolve it so that the dist modules always work + const moduleNameMatch = module.match(/^(?:@[a-z0-9_-]+\/)?(?:node:)?[a-z0-9_-]+/) + if (moduleNameMatch === null || moduleNameMatch.length !== 1) { + return false + } + const moduleName = moduleNameMatch[0].replace(/^node:/, '') + // don't resolve if it is a native module + if (builtinModules.includes(moduleName)) { + return false + } + + if (isDevDependency(moduleName)) { + console.warn(`\x1b[33m⚠ WARM: dev dependency \x1b[0m${module}\x1b[33m being bundled. Should it be a dependency instead?\x1b[0m`) + return true + } + + return false +} + +const tmpDeclarationsDir = join(rootDir, '.types') + export default [ - { // Browser ESM bundle + { // Browser ESM input, output: [ { - file: join(rootDir, pkgJson.browser), + file: join(rootDir, pkgJson.exports['.'].default.default), ...sourcemapOutputOptions, - format: 'es' + format: 'es', + plugins: [ + terser() + ] } ], plugins: [ @@ -73,9 +103,15 @@ export default [ _MODULE_TYPE: "'ESM'", preventAssignment: true }), - typescriptPlugin(tsBundleOptions), - commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required - json() + rollupPluginTs(tsPluginOptions), + commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }), + json(), + resolve({ + browser: true, + exportConditions: ['browser', 'default'], + mainFields: ['browser', 'module', 'main'], + resolveOnly + }) ] }, { // Browser bundles @@ -109,17 +145,13 @@ export default [ _MODULE_TYPE: "'BUNDLE'", preventAssignment: true }), - typescriptPlugin({ - ...tsBundleOptions, + rollupPluginTs({ + ...tsPluginOptions, sourceMap: false }), - resolve({ - browser: true, - exportConditions: ['browser', 'default'], - mainFields: ['browser', 'module', 'main'] - }), - commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required - json() + commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }), + json(), + resolve({ browser: true }) ] }, { // Node CJS @@ -136,21 +168,26 @@ export default [ } ], plugins: [ + replace({ + 'await import(': 'require(', + delimiters: ['', ''], + preventAssignment: true + }), replace({ IS_BROWSER: false, _MODULE_TYPE: "'CJS'", preventAssignment: true }), + rollupPluginTs(tsPluginOptions), inject({ crypto: ['crypto', 'webcrypto'] }), - typescriptPlugin(tsBundleOptions), - // resolve({ - // browser: false, - // exportConditions: ['require', 'node', 'module', 'import'] - // }), - commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required - json() + commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }), + json(), + resolve({ + exportConditions: ['node'], + resolveOnly + }) ] }, { // Node ESM and type declarations @@ -173,17 +210,32 @@ export default [ __dirname: `'${dirname(pkgJson.exports['.'].node.import.default)}'`, preventAssignment: true }), + rollupPluginTs(tsPluginOptions), + compileDts(tmpDeclarationsDir), inject({ crypto: ['crypto', 'webcrypto'] }), - typescriptPlugin(tsBundleOptions), - // resolve({ - // browser: false, - // exportConditions: ['node'] - // }), - compileDts(), - commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required - json() + commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }), + json(), + resolve({ + exportConditions: ['node'], + resolveOnly + }) ] + }, + { + input: join(tmpDeclarationsDir, 'index.d.ts'), + output: [{ file: 'dist/index.d.ts', format: 'es' }], + plugins: [ + dts({ + respectExternal: true + }) + ], + external: (module) => { + if (/^[./]/.test(module)) { + return false + } + return !resolveOnly(module) + } } ] diff --git a/build/testing/browser/index.cjs b/build/testing/browser/index.cjs index f455aa8..32ab5f4 100644 --- a/build/testing/browser/index.cjs +++ b/build/testing/browser/index.cjs @@ -1,7 +1,7 @@ const path = require('path') const puppeteer = require('puppeteer') -const minimatch = require('minimatch') +const minimatch = require('minimatch').minimatch const glob = require('glob') const rootDir = path.join(__dirname, '../../..') const pkgJson = require(path.join(rootDir, 'package.json')) diff --git a/build/testing/browser/server.cjs b/build/testing/browser/server.cjs index b9b8917..ea1ebb6 100644 --- a/build/testing/browser/server.cjs +++ b/build/testing/browser/server.cjs @@ -60,24 +60,20 @@ async function buildTests (testFiles) { input: testFiles, plugins: [ multi(), - replace({ - '#pkg': `/${name}.esm.js`, - delimiters: ['', ''], - preventAssignment: true - }), replace({ IS_BROWSER: true, _MODULE_TYPE: "'ESM'", preventAssignment: true }), typescriptPlugin(tsBundleOptions), - resolve({ - browser: true, - exportConditions: ['browser', 'default'], - mainFields: ['browser', 'module', 'main'] - }), - commonjs(), - json() + commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }), + json(), + resolve({ browser: true }), + replace({ + '#pkg': `/${name}.esm.js`, + delimiters: ['', ''], + preventAssignment: true + }) ], external: [`/${name}.esm.js`] } diff --git a/dist/bundles/esm.js b/dist/bundles/esm.js deleted file mode 100644 index 14d0a19..0000000 --- a/dist/bundles/esm.js +++ /dev/null @@ -1,146 +0,0 @@ -function abs(a) { - return (a >= 0) ? a : -a; -} - -function bitLength(a) { - if (typeof a === 'number') - a = BigInt(a); - if (a === 1n) { - return 1; - } - let bits = 1; - do { - bits++; - } while ((a >>= 1n) > 1n); - return bits; -} - -function eGcd(a, b) { - if (typeof a === 'number') - a = BigInt(a); - if (typeof b === 'number') - b = BigInt(b); - if (a <= 0n || b <= 0n) - throw new RangeError('a and b MUST be > 0'); - let x = 0n; - let y = 1n; - let u = 1n; - let v = 0n; - while (a !== 0n) { - const q = b / a; - const r = b % a; - const m = x - (u * q); - const n = y - (v * q); - b = a; - a = r; - x = u; - y = v; - u = m; - v = n; - } - return { - g: b, - x, - y - }; -} - -function gcd(a, b) { - let aAbs = (typeof a === 'number') ? BigInt(abs(a)) : abs(a); - let bAbs = (typeof b === 'number') ? BigInt(abs(b)) : abs(b); - if (aAbs === 0n) { - return bAbs; - } - else if (bAbs === 0n) { - return aAbs; - } - let shift = 0n; - while (((aAbs | bAbs) & 1n) === 0n) { - aAbs >>= 1n; - bAbs >>= 1n; - shift++; - } - while ((aAbs & 1n) === 0n) - aAbs >>= 1n; - do { - while ((bAbs & 1n) === 0n) - bAbs >>= 1n; - if (aAbs > bAbs) { - const x = aAbs; - aAbs = bAbs; - bAbs = x; - } - bAbs -= aAbs; - } while (bAbs !== 0n); - return aAbs << shift; -} - -function lcm(a, b) { - if (typeof a === 'number') - a = BigInt(a); - if (typeof b === 'number') - b = BigInt(b); - if (a === 0n && b === 0n) - return BigInt(0); - return abs((a / gcd(a, b)) * b); -} - -function max(a, b) { - return (a >= b) ? a : b; -} - -function min(a, b) { - return (a >= b) ? b : a; -} - -function toZn(a, n) { - if (typeof a === 'number') - a = BigInt(a); - if (typeof n === 'number') - n = BigInt(n); - if (n <= 0n) { - throw new RangeError('n must be > 0'); - } - const aZn = a % n; - return (aZn < 0n) ? aZn + n : aZn; -} - -function modInv(a, n) { - const egcd = eGcd(toZn(a, n), n); - if (egcd.g !== 1n) { - throw new RangeError(`${a.toString()} does not have inverse modulo ${n.toString()}`); - } - else { - return toZn(egcd.x, n); - } -} - -function modPow(b, e, n) { - if (typeof b === 'number') - b = BigInt(b); - if (typeof e === 'number') - e = BigInt(e); - if (typeof n === 'number') - n = BigInt(n); - if (n <= 0n) { - throw new RangeError('n must be > 0'); - } - else if (n === 1n) { - return 0n; - } - b = toZn(b, n); - if (e < 0n) { - return modInv(modPow(b, abs(e), n), n); - } - let r = 1n; - while (e > 0) { - if ((e % 2n) === 1n) { - r = r * b % n; - } - e = e / 2n; - b = b ** 2n % n; - } - return r; -} - -export { abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn }; diff --git a/dist/bundles/esm.min.js b/dist/bundles/esm.min.js deleted file mode 100644 index 1e96a87..0000000 --- a/dist/bundles/esm.min.js +++ /dev/null @@ -1 +0,0 @@ -function n(n){return n>=0?n:-n}function t(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let r=0n,e=1n,o=1n,u=0n;for(;0n!==n;){const i=t/n,f=t%n,g=r-o*i,b=e-u*i;t=n,n=f,r=o,e=u,o=g,u=b}return{g:t,x:r,y:e}}function e(t,r){let e="number"==typeof t?BigInt(n(t)):n(t),o="number"==typeof r?BigInt(n(r)):n(r);if(0n===e)return o;if(0n===o)return e;let u=0n;for(;0n===(1n&(e|o));)e>>=1n,o>>=1n,u++;for(;0n===(1n&e);)e>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(e>o){const n=e;e=o,o=n}o-=e}while(0n!==o);return e<=t?n:t}function i(n,t){return n>=t?t:n}function f(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const r=n%t;return r<0n?r+t:r}function g(n,t){const e=r(f(n,t),t);if(1n!==e.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return f(e.x,t)}function b(t,r,e){if("number"==typeof t&&(t=BigInt(t)),"number"==typeof r&&(r=BigInt(r)),"number"==typeof e&&(e=BigInt(e)),e<=0n)throw new RangeError("n must be > 0");if(1n===e)return 0n;if(t=f(t,e),r<0n)return g(b(t,n(r),e),e);let o=1n;for(;r>0;)r%2n===1n&&(o=o*t%e),r/=2n,t=t**2n%e;return o}export{n as abs,t as bitLength,r as eGcd,e as gcd,o as lcm,u as max,i as min,g as modInv,b as modPow,f as toZn}; diff --git a/dist/bundles/iife.js b/dist/bundles/iife.js deleted file mode 100644 index 8d3d12c..0000000 --- a/dist/bundles/iife.js +++ /dev/null @@ -1 +0,0 @@ -var bigintModArith=function(n){"use strict";function t(n){return n>=0?n:-n}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let r=0n,e=1n,o=1n,i=0n;for(;0n!==n;){const u=t/n,f=t%n,g=r-o*u,m=e-i*u;t=n,n=f,r=o,e=i,o=g,i=m}return{g:t,x:r,y:e}}function e(n,r){let e="number"==typeof n?BigInt(t(n)):t(n),o="number"==typeof r?BigInt(t(r)):t(r);if(0n===e)return o;if(0n===o)return e;let i=0n;for(;0n===(1n&(e|o));)e>>=1n,o>>=1n,i++;for(;0n===(1n&e);)e>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(e>o){const n=e;e=o,o=n}o-=e}while(0n!==o);return e< 0");const r=n%t;return r<0n?r+t:r}function i(n,t){const e=r(o(n,t),t);if(1n!==e.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return o(e.x,t)}return n.abs=t,n.bitLength=function(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},n.eGcd=r,n.gcd=e,n.lcm=function(n,r){return"number"==typeof n&&(n=BigInt(n)),"number"==typeof r&&(r=BigInt(r)),0n===n&&0n===r?BigInt(0):t(n/e(n,r)*r)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modInv=i,n.modPow=function n(r,e,u){if("number"==typeof r&&(r=BigInt(r)),"number"==typeof e&&(e=BigInt(e)),"number"==typeof u&&(u=BigInt(u)),u<=0n)throw new RangeError("n must be > 0");if(1n===u)return 0n;if(r=o(r,u),e<0n)return i(n(r,t(e),u),u);let f=1n;for(;e>0;)e%2n===1n&&(f=f*r%u),e/=2n,r=r**2n%u;return f},n.toZn=o,n}({}); diff --git a/dist/bundles/umd.js b/dist/bundles/umd.js deleted file mode 100644 index 8973ac7..0000000 --- a/dist/bundles/umd.js +++ /dev/null @@ -1 +0,0 @@ -!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).bigintModArith={})}(this,(function(n){"use strict";function t(n){return n>=0?n:-n}function e(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let e=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const f=t/n,u=t%n,g=e-o*f,b=r-i*f;t=n,n=u,e=o,r=i,o=g,i=b}return{g:t,x:e,y:r}}function r(n,e){let r="number"==typeof n?BigInt(t(n)):t(n),o="number"==typeof e?BigInt(t(e)):t(e);if(0n===r)return o;if(0n===o)return r;let i=0n;for(;0n===(1n&(r|o));)r>>=1n,o>>=1n,i++;for(;0n===(1n&r);)r>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(r>o){const n=r;r=o,o=n}o-=r}while(0n!==o);return r< 0");const e=n%t;return e<0n?e+t:e}function i(n,t){const r=e(o(n,t),t);if(1n!==r.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return o(r.x,t)}n.abs=t,n.bitLength=function(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},n.eGcd=e,n.gcd=r,n.lcm=function(n,e){return"number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),0n===n&&0n===e?BigInt(0):t(n/r(n,e)*e)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modInv=i,n.modPow=function n(e,r,f){if("number"==typeof e&&(e=BigInt(e)),"number"==typeof r&&(r=BigInt(r)),"number"==typeof f&&(f=BigInt(f)),f<=0n)throw new RangeError("n must be > 0");if(1n===f)return 0n;if(e=o(e,f),r<0n)return i(n(e,t(r),f),f);let u=1n;for(;r>0;)r%2n===1n&&(u=u*e%f),r/=2n,e=e**2n%f;return u},n.toZn=o})); diff --git a/dist/cjs/index.node.cjs b/dist/cjs/index.node.cjs deleted file mode 100644 index e6eebe6..0000000 --- a/dist/cjs/index.node.cjs +++ /dev/null @@ -1,2 +0,0 @@ -"use strict";function n(n){return n>=0?n:-n}function t(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let r=0n,e=1n,o=1n,i=0n;for(;0n!==n;){const u=t/n,f=t%n,g=r-o*u,p=e-i*u;t=n,n=f,r=o,e=i,o=g,i=p}return{g:t,x:r,y:e}}function r(t,r){let e="number"==typeof t?BigInt(n(t)):n(t),o="number"==typeof r?BigInt(n(r)):n(r);if(0n===e)return o;if(0n===o)return e;let i=0n;for(;0n===(1n&(e|o));)e>>=1n,o>>=1n,i++;for(;0n===(1n&e);)e>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(e>o){const n=e;e=o,o=n}o-=e}while(0n!==o);return e< 0");const r=n%t;return r<0n?r+t:r}function o(n,r){const o=t(e(n,r),r);if(1n!==o.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${r.toString()}`);return e(o.x,r)}exports.abs=n,exports.bitLength=function(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t},exports.eGcd=t,exports.gcd=r,exports.lcm=function(t,e){return"number"==typeof t&&(t=BigInt(t)),"number"==typeof e&&(e=BigInt(e)),0n===t&&0n===e?BigInt(0):n(t/r(t,e)*e)},exports.max=function(n,t){return n>=t?n:t},exports.min=function(n,t){return n>=t?t:n},exports.modInv=o,exports.modPow=function t(r,i,u){if("number"==typeof r&&(r=BigInt(r)),"number"==typeof i&&(i=BigInt(i)),"number"==typeof u&&(u=BigInt(u)),u<=0n)throw new RangeError("n must be > 0");if(1n===u)return 0n;if(r=e(r,u),i<0n)return o(t(r,n(i),u),u);let f=1n;for(;i>0;)i%2n===1n&&(f=f*r%u),i/=2n,r=r**2n%u;return f},exports.toZn=e; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXgubm9kZS5janMiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90cy9hYnMudHMiLCIuLi8uLi9zcmMvdHMvZWdjZC50cyIsIi4uLy4uL3NyYy90cy9nY2QudHMiLCIuLi8uLi9zcmMvdHMvdG9abi50cyIsIi4uLy4uL3NyYy90cy9tb2RJbnYudHMiLCIuLi8uLi9zcmMvdHMvYml0TGVuZ3RoLnRzIiwiLi4vLi4vc3JjL3RzL2xjbS50cyIsIi4uLy4uL3NyYy90cy9tYXgudHMiLCIuLi8uLi9zcmMvdHMvbWluLnRzIiwiLi4vLi4vc3JjL3RzL21vZFBvdy50cyJdLCJzb3VyY2VzQ29udGVudCI6bnVsbCwibmFtZXMiOlsiYWJzIiwiYSIsImVHY2QiLCJiIiwiQmlnSW50IiwiUmFuZ2VFcnJvciIsIngiLCJ5IiwidSIsInYiLCJxIiwiciIsIm0iLCJuIiwiZyIsImdjZCIsImFBYnMiLCJiQWJzIiwic2hpZnQiLCJ0b1puIiwiYVpuIiwibW9kSW52IiwiZWdjZCIsInRvU3RyaW5nIiwiYml0cyIsIm1vZFBvdyIsImUiXSwibWFwcGluZ3MiOiJhQU9NLFNBQVVBLEVBQUtDLEdBQ25CLE9BQVFBLEdBQUssRUFBS0EsR0FBS0EsQ0FDekIsQ0NPZ0IsU0FBQUMsRUFBTUQsRUFBb0JFLEdBSXhDLEdBSGlCLGlCQUFORixJQUFnQkEsRUFBSUcsT0FBT0gsSUFDckIsaUJBQU5FLElBQWdCQSxFQUFJQyxPQUFPRCxJQUVsQ0YsR0FBSyxJQUFNRSxHQUFLLEdB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BQVF0QixFQUFvQnVCLEVBQW9CYixHQUs5RCxHQUppQixpQkFBTlYsSUFBZ0JBLEVBQUlDLE9BQU9ELElBQ3JCLGlCQUFOdUIsSUFBZ0JBLEVBQUl0QixPQUFPc0IsSUFDckIsaUJBQU5iLElBQWdCQSxFQUFJVCxPQUFPUyxJQUVsQ0EsR0FBSyxHQUNQLE1BQU0sSUFBSVIsV0FBVyxpQkFDaEIsR0FBVSxLQUFOUSxFQUNULE9BQU8sR0FLVCxHQUZBVixFQUFJZ0IsRUFBS2hCLEVBQUdVLEdBRVJhLEVBQUksR0FDTixPQUFPTCxFQUFPSSxFQUFPdEIsRUFBR0gsRUFBSTBCLEdBQUliLEdBQUlBLEdBR3RDLElBQUlGLEVBQUksR0FDUixLQUFPZSxFQUFJLEdBQ0pBLEVBQUksS0FBUSxLQUNmZixFQUFJQSxFQUFJUixFQUFJVSxHQUVkYSxHQUFRLEdBQ1J2QixFQUFJQSxHQUFLLEdBQUtVLEVBRWhCLE9BQU9GLENBQ1QifQ== diff --git a/dist/esm/index.browser.js b/dist/esm/index.browser.js deleted file mode 100644 index b763fba..0000000 --- a/dist/esm/index.browser.js +++ /dev/null @@ -1,147 +0,0 @@ -function abs(a) { - return (a >= 0) ? a : -a; -} - -function bitLength(a) { - if (typeof a === 'number') - a = BigInt(a); - if (a === 1n) { - return 1; - } - let bits = 1; - do { - bits++; - } while ((a >>= 1n) > 1n); - return bits; -} - -function eGcd(a, b) { - if (typeof a === 'number') - a = BigInt(a); - if (typeof b === 'number') - b = BigInt(b); - if (a <= 0n || b <= 0n) - throw new RangeError('a and b MUST be > 0'); - let x = 0n; - let y = 1n; - let u = 1n; - let v = 0n; - while (a !== 0n) { - const q = b / a; - const r = b % a; - const m = x - (u * q); - const n = y - (v * q); - b = a; - a = r; - x = u; - y = v; - u = m; - v = n; - } - return { - g: b, - x, - y - }; -} - -function gcd(a, b) { - let aAbs = (typeof a === 'number') ? BigInt(abs(a)) : abs(a); - let bAbs = (typeof b === 'number') ? BigInt(abs(b)) : abs(b); - if (aAbs === 0n) { - return bAbs; - } - else if (bAbs === 0n) { - return aAbs; - } - let shift = 0n; - while (((aAbs | bAbs) & 1n) === 0n) { - aAbs >>= 1n; - bAbs >>= 1n; - shift++; - } - while ((aAbs & 1n) === 0n) - aAbs >>= 1n; - do { - while ((bAbs & 1n) === 0n) - bAbs >>= 1n; - if (aAbs > bAbs) { - const x = aAbs; - aAbs = bAbs; - bAbs = x; - } - bAbs -= aAbs; - } while (bAbs !== 0n); - return aAbs << shift; -} - -function lcm(a, b) { - if (typeof a === 'number') - a = BigInt(a); - if (typeof b === 'number') - b = BigInt(b); - if (a === 0n && b === 0n) - return BigInt(0); - return abs((a / gcd(a, b)) * b); -} - -function max(a, b) { - return (a >= b) ? a : b; -} - -function min(a, b) { - return (a >= b) ? b : a; -} - -function toZn(a, n) { - if (typeof a === 'number') - a = BigInt(a); - if (typeof n === 'number') - n = BigInt(n); - if (n <= 0n) { - throw new RangeError('n must be > 0'); - } - const aZn = a % n; - return (aZn < 0n) ? aZn + n : aZn; -} - -function modInv(a, n) { - const egcd = eGcd(toZn(a, n), n); - if (egcd.g !== 1n) { - throw new RangeError(`${a.toString()} does not have inverse modulo ${n.toString()}`); - } - else { - return toZn(egcd.x, n); - } -} - -function modPow(b, e, n) { - if (typeof b === 'number') - b = BigInt(b); - if (typeof e === 'number') - e = BigInt(e); - if (typeof n === 'number') - n = BigInt(n); - if (n <= 0n) { - throw new RangeError('n must be > 0'); - } - else if (n === 1n) { - return 0n; - } - b = toZn(b, n); - if (e < 0n) { - return modInv(modPow(b, abs(e), n), n); - } - let r = 1n; - while (e > 0) { - if ((e % 2n) === 1n) { - r = r * b % n; - } - e = e / 2n; - b = b ** 2n % n; - } - return r; -} - -export { abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn }; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguYnJvd3Nlci5qc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7QUFDbkIsWUFBQSxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUE7QUFDZCxTQUFBO0FBQ0QsUUFBQSxDQUFDLEdBQUcsQ0FBQyxHQUFHLEVBQUUsQ0FBQTtBQUNWLFFBQUEsQ0FBQyxHQUFHLENBQUMsSUFBSSxFQUFFLEdBQUcsQ0FBQyxDQUFBO0FBQ2hCLEtBQUE7QUFDRCxJQUFBLE9BQU8sQ0FBQyxDQUFBO0FBQ1Y7Ozs7In0= diff --git a/dist/esm/index.node.js b/dist/esm/index.node.js deleted file mode 100644 index 1608e3f..0000000 --- a/dist/esm/index.node.js +++ /dev/null @@ -1,2 +0,0 @@ -function n(n){return n>=0?n:-n}function t(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let t=1;do{t++}while((n>>=1n)>1n);return t}function r(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),n<=0n||t<=0n)throw new RangeError("a and b MUST be > 0");let r=0n,e=1n,o=1n,u=0n;for(;0n!==n;){const i=t/n,f=t%n,g=r-o*i,b=e-u*i;t=n,n=f,r=o,e=u,o=g,u=b}return{g:t,x:r,y:e}}function e(t,r){let e="number"==typeof t?BigInt(n(t)):n(t),o="number"==typeof r?BigInt(n(r)):n(r);if(0n===e)return o;if(0n===o)return e;let u=0n;for(;0n===(1n&(e|o));)e>>=1n,o>>=1n,u++;for(;0n===(1n&e);)e>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(e>o){const n=e;e=o,o=n}o-=e}while(0n!==o);return e<=t?n:t}function i(n,t){return n>=t?t:n}function f(n,t){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),t<=0n)throw new RangeError("n must be > 0");const r=n%t;return r<0n?r+t:r}function g(n,t){const e=r(f(n,t),t);if(1n!==e.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return f(e.x,t)}function b(t,r,e){if("number"==typeof t&&(t=BigInt(t)),"number"==typeof r&&(r=BigInt(r)),"number"==typeof e&&(e=BigInt(e)),e<=0n)throw new RangeError("n must be > 0");if(1n===e)return 0n;if(t=f(t,e),r<0n)return g(b(t,n(r),e),e);let o=1n;for(;r>0;)r%2n===1n&&(o=o*t%e),r/=2n,t=t**2n%e;return o}export{n as abs,t as bitLength,r as eGcd,e as gcd,o as lcm,u as max,i as min,g as modInv,b as modPow,f as toZn}; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXgubm9kZS5qcyIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3RzL2Ficy50cyIsIi4uLy4uL3NyYy90cy9iaXRMZW5ndGgudHMiLCIuLi8uLi9zcmMvdHMvZWdjZC50cyIsIi4uLy4uL3NyYy90cy9nY2QudHMiLCIuLi8uLi9zcmMvdHMvbGNtLnRzIiwiLi4vLi4vc3JjL3RzL21heC50cyIsIi4uLy4uL3NyYy90cy9taW4udHMiLCIuLi8uLi9zcmMvdHMvdG9abi50cyIsIi4uLy4uL3NyYy90cy9tb2RJbnYudHMiLCIuLi8uLi9zcmMvdHMvbW9kUG93LnRzIl0sInNvdXJjZXNDb250ZW50IjpudWxsLCJuYW1lcyI6WyJhYnMiLCJhIiwiYml0TGVuZ3RoIiwiQmlnSW50IiwiYml0cyIsImVHY2QiLCJiIiwiUmFuZ2VFcnJvciIsIngiLCJ5IiwidSIsInYiLCJxIiwiciIsIm0iLCJuIiwiZyIsImdjZCIsImFBYnMiLCJiQWJzIiwic2hpZnQiLCJsY20iLCJtYXgiLCJtaW4iLCJ0b1puIiwiYVpuIiwibW9kSW52IiwiZWdjZCIsInRvU3RyaW5nIiwibW9kUG93IiwiZSJdLCJtYXBwaW5ncyI6IkFBT00sU0FBVUEsRUFBS0MsR0FDbkIsT0FBUUEsR0FBSyxFQUFLQSxHQUFLQSxDQUN6QixDQ0hNLFNBQVVDLEVBQVdELEdBR3pCLEdBRmlCLGlCQ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FBWFksRUFBS1gsRUFDUCxNQUFNLElBQUlULFdBQVcsR0FBR04sRUFBRTJCLDJDQUEyQ2IsRUFBRWEsY0FFdkUsT0FBT0osRUFBS0csRUFBS25CLEVBQUdPLEVBRXhCLFVDTGdCYyxFQUFRdkIsRUFBb0J3QixFQUFvQmYsR0FLOUQsR0FKaUIsaUJBQU5ULElBQWdCQSxFQUFJSCxPQUFPRyxJQUNyQixpQkFBTndCLElBQWdCQSxFQUFJM0IsT0FBTzJCLElBQ3JCLGlCQUFOZixJQUFnQkEsRUFBSVosT0FBT1ksSUFFbENBLEdBQUssR0FDUCxNQUFNLElBQUlSLFdBQVcsaUJBQ2hCLEdBQVUsS0FBTlEsRUFDVCxPQUFPLEdBS1QsR0FGQVQsRUFBSWtCLEVBQUtsQixFQUFHUyxHQUVSZSxFQUFJLEdBQ04sT0FBT0osRUFBT0csRUFBT3ZCLEVBQUdOLEVBQUk4QixHQUFJZixHQUFJQSxHQUd0QyxJQUFJRixFQUFJLEdBQ1IsS0FBT2lCLEVBQUksR0FDSkEsRUFBSSxLQUFRLEtBQ2ZqQixFQUFJQSxFQUFJUCxFQUFJUyxHQUVkZSxHQUFRLEdBQ1J4QixFQUFJQSxHQUFLLEdBQUtTLEVBRWhCLE9BQU9GLENBQ1QifQ== diff --git a/docs/.nojekyll b/docs/.nojekyll deleted file mode 100644 index e2ac661..0000000 --- a/docs/.nojekyll +++ /dev/null @@ -1 +0,0 @@ -TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. \ No newline at end of file diff --git a/docs/API.md b/docs/API.md deleted file mode 100644 index 4ef27f1..0000000 --- a/docs/API.md +++ /dev/null @@ -1,292 +0,0 @@ -# bigint-mod-arith - v3.2.0 - -Some common functions for modular arithmetic using native JS implementation of BigInt - -## Table of contents - -### Interfaces - -- [Egcd](interfaces/Egcd.md) - -### Functions - -- [abs](API.md#abs) -- [bitLength](API.md#bitlength) -- [eGcd](API.md#egcd) -- [gcd](API.md#gcd) -- [lcm](API.md#lcm) -- [max](API.md#max) -- [min](API.md#min) -- [modInv](API.md#modinv) -- [modPow](API.md#modpow) -- [toZn](API.md#tozn) - -## Functions - -### abs - -▸ **abs**(`a`): `number` \| `bigint` - -Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0 - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `a` | `number` \| `bigint` | - -#### Returns - -`number` \| `bigint` - -The absolute value of a - -#### Defined in - -[abs.ts:8](https://github.com/juanelas/bigint-mod-arith/blob/1f18626/src/ts/abs.ts#L8) - -___ - -### bitLength - -▸ **bitLength**(`a`): `number` - -Returns the (minimum) length of a number expressed in bits. - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `a` | `number` \| `bigint` | - -#### Returns - -`number` - -The bit length - -#### Defined in - -[bitLength.ts:7](https://github.com/juanelas/bigint-mod-arith/blob/1f18626/src/ts/bitLength.ts#L7) - -___ - -### eGcd - -▸ **eGcd**(`a`, `b`): [`Egcd`](interfaces/Egcd.md) - -An iterative implementation of the extended euclidean algorithm or extended greatest common divisor algorithm. -Take positive integers a, b as input, and return a triple (g, x, y), such that ax + by = g = gcd(a, b). - -**`Throws`** - -RangeError if a or b are <= 0 - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `a` | `number` \| `bigint` | -| `b` | `number` \| `bigint` | - -#### Returns - -[`Egcd`](interfaces/Egcd.md) - -A triple (g, x, y), such that ax + by = g = gcd(a, b). - -#### Defined in - -[egcd.ts:17](https://github.com/juanelas/bigint-mod-arith/blob/1f18626/src/ts/egcd.ts#L17) - -___ - -### gcd - -▸ **gcd**(`a`, `b`): `bigint` - -Greatest common divisor of two integers based on the iterative binary algorithm. - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `a` | `number` \| `bigint` | -| `b` | `number` \| `bigint` | - -#### Returns - -`bigint` - -The greatest common divisor of a and b - -#### Defined in - -[gcd.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/1f18626/src/ts/gcd.ts#L10) - -___ - -### lcm - -▸ **lcm**(`a`, `b`): `bigint` - -The least common multiple computed as abs(a*b)/gcd(a,b) - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `a` | `number` \| `bigint` | -| `b` | `number` \| `bigint` | - -#### Returns - -`bigint` - -The least common multiple of a and b - -#### Defined in - -[lcm.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/1f18626/src/ts/lcm.ts#L10) - -___ - -### max - -▸ **max**(`a`, `b`): `number` \| `bigint` - -Maximum. max(a,b)==a if a>=b. max(a,b)==b if a=b. min(a,b)==a if a=16 || 14 >=14.17" @@ -3977,9 +3978,9 @@ } }, "node_modules/minimatch": { - "version": "8.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-8.0.4.tgz", - "integrity": "sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.0.tgz", + "integrity": "sha512-0jJj8AvgKqWN05mrwuqi8QYKx1WmYSUoKSxu5Qhs9prezTz10sxAHGNZe9J9cqIJzta8DWsleh2KaVaLl6Ru2w==", "dev": true, "dependencies": { "brace-expansion": "^2.0.1" @@ -4001,9 +4002,9 @@ } }, "node_modules/minipass": { - "version": "4.2.7", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.7.tgz", - "integrity": "sha512-ScVIgqHcXRMyfflqHmEW0bm8z8rb5McHyOY3ewX9JBgZaR77G7nxq9L/mtV96/QbAAwtbCAHVVLzD1kkyfFQEw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", + "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==", "dev": true, "engines": { "node": ">=8" @@ -4675,15 +4676,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/path-scurry/node_modules/minipass": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", - "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", @@ -4915,27 +4907,27 @@ } }, "node_modules/puppeteer": { - "version": "19.8.5", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.8.5.tgz", - "integrity": "sha512-WSjouU7eux6cwBMEz4A7mDRVZWTQQTDXrb1R6AhKDdeEgpiBBkAzcAusPhILxiJOKj60rULZpWuCZ7HZIO6GTA==", + "version": "19.9.0", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.9.0.tgz", + "integrity": "sha512-JDx8WwGlkdQYTaa3OMYDF+uFWimiwNnacg5FGEC5J6+VxDsLK30wHKU/Db2LqEhtAoIu4RwS+BRH4zRPlCsFpA==", "dev": true, "hasInstallScript": true, "dependencies": { - "@puppeteer/browsers": "0.4.0", + "@puppeteer/browsers": "0.4.1", "cosmiconfig": "8.1.3", "https-proxy-agent": "5.0.1", "progress": "2.0.3", "proxy-from-env": "1.1.0", - "puppeteer-core": "19.8.5" + "puppeteer-core": "19.9.0" } }, "node_modules/puppeteer-core": { - "version": "19.8.5", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.8.5.tgz", - "integrity": "sha512-zoGhim/oBQbkND6h4Xz4X7l5DkWVH9wH7z0mVty5qa/c0P1Yad47t/npVtt2xS10BiQwzztWKx7Pa2nJ5yykdw==", + "version": "19.9.0", + "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.9.0.tgz", + "integrity": "sha512-IJYfCE0oFpi5dTvNFqOwo8Dey6zzx7hANy7z6K2bjpCux9oPOSOIubq40awNhaHlfi8soYtgU4qabnzMXB7xBQ==", "dev": true, "dependencies": { - "@puppeteer/browsers": "0.4.0", + "@puppeteer/browsers": "0.4.1", "chromium-bidi": "0.4.6", "cross-fetch": "3.1.5", "debug": "4.3.4", @@ -5121,12 +5113,12 @@ } }, "node_modules/rimraf": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.4.1.tgz", - "integrity": "sha512-Gk8NlF062+T9CqNGn6h4tls3k6T1+/nXdOcSZVikNVtlRdYpA7wRJJMoXmuvOnLW844rPjdQ7JgXCYM6PPC/og==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.0.tgz", + "integrity": "sha512-Jf9llaP+RvaEVS5nPShYFhtXIrb3LRKP281ib3So0KkeZKo2wIKyq0Re7TOSwanasA423PSr6CCIL4bP6T040g==", "dev": true, "dependencies": { - "glob": "^9.2.0" + "glob": "^10.0.0" }, "bin": { "rimraf": "dist/cjs/src/bin.js" @@ -5154,6 +5146,40 @@ "fsevents": "~2.3.2" } }, + "node_modules/rollup-plugin-dts": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-5.3.0.tgz", + "integrity": "sha512-8FXp0ZkyZj1iU5klkIJYLjIq/YZSwBoERu33QBDxm/1yw5UU4txrEtcmMkrq+ZiKu3Q4qvPCNqc3ovX6rjqzbQ==", + "dev": true, + "dependencies": { + "magic-string": "^0.30.0" + }, + "engines": { + "node": ">=v14" + }, + "funding": { + "url": "https://github.com/sponsors/Swatinem" + }, + "optionalDependencies": { + "@babel/code-frame": "^7.18.6" + }, + "peerDependencies": { + "rollup": "^3.0.0", + "typescript": "^4.1 || ^5.0" + } + }, + "node_modules/rollup-plugin-dts/node_modules/magic-string": { + "version": "0.30.0", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.0.tgz", + "integrity": "sha512-LA+31JYDJLs82r2ScLrlz1GjSgu66ZV518eyWT+S8VhyQn/JL0u9MeBOvQMGYiPk1DBiSN9DDMOcXvigJZaViQ==", + "dev": true, + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.4.13" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", diff --git a/package.json b/package.json index 4c8726b..0054b6e 100644 --- a/package.json +++ b/package.json @@ -24,46 +24,50 @@ "node": ">=10.4.0" }, "type": "module", - "main": "./dist/cjs/index.node.cjs", - "types": "./types/index.d.cts", - "browser": "./dist/esm/index.browser.js", - "module": "./dist/esm/index.node.js", + "main": "./dist/index.node.cjs", + "browser": "./dist/index.browser.esm.js", + "types": "./dist/index.d.ts", "exports": { ".": { "node": { - "require": { - "default": "./dist/cjs/index.node.cjs", - "types": "./types/index.d.cts" + "module": { + "types": "./dist/index.d.ts", + "default": "./dist/index.node.esm.js" }, "import": { - "default": "./dist/esm/index.node.js", - "types": "./types/index.d.ts" + "types": "./dist/index.d.ts", + "default": "./dist/index.node.esm.js" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.node.cjs" } }, + "script": "./dist/bundle.iife.js", "default": { - "default": "./dist/esm/index.browser.js", - "types": "./types/index.d.ts" + "types": "./dist/index.d.ts", + "default": "./dist/index.browser.esm.js" } }, - "./esm-browser-bundle": "./dist/bundles/esm.min.js", - "./esm-browser-bundle-nomin": "./dist/bundles/esm.js", - "./iife-browser-bundle": "./dist/bundles/iife.js", - "./umd-browser-bundle": "./dist/bundles/umd.js", - "./types": "./types/index.d.cts" + "./esm-browser-bundle": "./dist/bundle.esm.min.js", + "./esm-browser-bundle-nomin": "./dist/bundle.esm.js", + "./iife-browser-bundle": "./dist/bundle.iife.js", + "./umd-browser-bundle": "./dist/bundle.umd.js", + "./types": "./dist/index.d.ts" }, "imports": { "#pkg": { "require": { - "default": "./dist/cjs/index.node.cjs", - "types": "./types/index.d.cts" + "types": "./dist/index.d.ts", + "default": "./dist/index.node.cjs" }, "import": { - "default": "./dist/esm/index.node.js", - "types": "./types/index.d.ts" + "types": "./dist/index.d.ts", + "default": "./dist/index.node.esm.js" }, "default": { - "default": "./dist/esm/index.browser.js", - "types": "./types/index.d.ts" + "types": "./dist/esm/index.d.ts", + "default": "./dist/index.browser.esm.js" } } }, @@ -79,7 +83,8 @@ "scripts": { "build": "run-s lint:src build:js lint:test docs", "build:js": "rollup -c build/rollup.config.js", - "clean": "rimraf .mocha-ts coverage dist types docs", + "postbuild:js": "rimraf .types", + "clean": "rimraf .mocha-ts coverage dist .types docs", "coverage": "c8 --clean --check-coverage --exclude \"{src/ts/**/*.spec.ts,test,test-vectors,build}\" --exclude-after-remap --reporter=text --reporter=lcov node ./build/bin/mocha-ts.cjs --commonjs ", "docs": "node build/build.docs.cjs", "git:add": "git add -A", @@ -143,15 +148,16 @@ "c8": "^7.12.0", "chai": "^4.3.3", "dotenv": "^16.0.3", - "glob": "^9.3.4", + "glob": "^10.0.0", "json5": "^2.2.0", - "minimatch": "^8.0.3", + "minimatch": "^9.0.0", "mocha": "^10.0.0", "npm-run-all": "^4.1.5", "pirates": "^4.0.1", "puppeteer": "^19.1.2", - "rimraf": "^4.4.1", + "rimraf": "^5.0.0", "rollup": "^3.20.2", + "rollup-plugin-dts": "^5.3.0", "ts-standard": "^12.0.2", "tslib": "^2.3.1", "typedoc": "~0.23.0",