support for node16 and nodenext module resolution

This commit is contained in:
Juan Hernández Serrano 2023-04-11 10:43:47 +02:00
parent fc5e3c53e4
commit 1f1862692b
78 changed files with 2204 additions and 6264 deletions

View File

@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14, 16, 18]
node-version: [16, 18]
steps:
- uses: actions/checkout@v2
@ -49,7 +49,7 @@ jobs:
- uses: actions/setup-node@v1
if: steps.check.outputs.changed == 'true'
with:
node-version: 14
node-version: 18
registry-url: https://registry.npmjs.org/
- name: install

View File

@ -1,8 +1,8 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![Node.js CI](https://github.com/juanelas/bigint-mod-arith/actions/workflows/nodejs.yml/badge.svg)](https://github.com/juanelas/bigint-mod-arith/actions/workflows/nodejs.yml)
[![Coverage Status](https://coveralls.io/repos/github/juanelas/bigint-mod-arith/badge.svg?branch=master)](https://coveralls.io/github/juanelas/bigint-mod-arith?branch=master)
[![Node.js CI](https://github.com/juanelas/bigint-mod-arith/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/juanelas/bigint-mod-arith/actions/workflows/build-and-test.yml)
[![Coverage Status](https://coveralls.io/repos/github/juanelas/bigint-mod-arith/badge.svg?branch=main)](https://coveralls.io/github/juanelas/bigint-mod-arith?branch=main)
# bigint-mod-arith
@ -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/master/dist/bundles/iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/dist/bundles/esm.min.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/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/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/`.
An example of usage could be:

View File

@ -9,6 +9,28 @@ const rimraf = require('rimraf')
const rootDir = path.join(__dirname, '..')
const templateFilePath = path.join(rootDir, pkgJson.directories.src, 'docs/index.md')
let template = fs.readFileSync(templateFilePath, { encoding: 'utf-8' })
async function main () {
// Generate API doc with typedoc
await typedoc()
// Translate relaitive links to project's root
replaceRelativeLinks()
// Let us replace variables and badges
variableReplacements()
const readmeFile = path.join(rootDir, 'README.md')
fs.writeFileSync(readmeFile, template)
}
main()
/* ------------------------------------------------------------------------- |
| UTILITY FUNCTIONS |
| ------------------------------------------------------------------------- */
function camelise (str) {
return str.replace(/-([a-z])/g,
function (m, w) {
@ -16,13 +38,13 @@ function camelise (str) {
})
}
const tsConfigPath = path.join(rootDir, 'tsconfig.json')
const tempTsConfigPath = path.join(rootDir, '.tsconfig.json')
async function typedoc () {
const app = new TypeDoc.Application()
// prepare tsconfig
const tsConfigPath = path.join(rootDir, 'tsconfig.json')
const tempTsConfigPath = path.join(rootDir, '.tsconfig.json')
const tsConfig = json5.parse(fs.readFileSync(tsConfigPath, 'utf8'))
tsConfig.include = ['src/ts/**/*', 'build/typings/**/*.d.ts']
tsConfig.exclude = ['src/**/*.spec.ts']
@ -30,7 +52,7 @@ async function typedoc () {
// If you want TypeDoc to load tsconfig.json / typedoc.json files
app.options.addReader(new TypeDoc.TSConfigReader())
app.options.addReader(new TypeDoc.TypeDocReader())
// app.options.addReader(new TypeDoc.TypeDocReader())
app.bootstrap({
// typedoc options here
@ -53,81 +75,130 @@ async function typedoc () {
// Rendered docs
await app.generateDocs(project, output)
}
rimraf.sync(tempTsConfigPath)
}
function getRepositoryData () {
let ret
if (typeof pkgJson.repository === 'string') {
const repodata = pkgJson.repository.split(/[:/]/)
const repoProvider = repodata[0]
if (repoProvider === 'github' || repoProvider === 'gitlab' || repoProvider === 'bitbucket') {
return {
ret = {
repoProvider,
repoUsername: repodata[1],
repoName: repodata.slice(2).join('/')
}
} else return null
} else {
if (pkgJson.repository.url !== 'undefined') {
}
} else if (typeof pkgJson.repository === 'object' && pkgJson.repository.type === 'git' && pkgJson.repository.url !== 'undefined') {
const regex = /(?:.+?\+)?http[s]?:\/\/(?<repoProvider>[\w._-]+)\.\w{2,3}\/(?<repoUsername>[\w._-]+)\/(?<repoName>[\w._\-/]+?)\.git/
const match = pkgJson.repository.url.match(regex)
return {
ret = {
repoProvider: match[1],
repoUsername: match[2],
repoName: match[3]
repoName: match[3],
repoDirectory: pkgJson.repository.directory
}
}
if (typeof ret === 'object') {
if (typeof pkgJson.nodeBrowserSkel === 'object' && typeof pkgJson.nodeBrowserSkel.git === 'object' && typeof pkgJson.nodeBrowserSkel.git.branch === 'string') {
ret.branch = pkgJson.nodeBrowserSkel.git.branch
} else {
ret.branch = (ret.repoProvider === 'github') ? 'main' : 'master'
}
}
return ret
}
const { repoProvider, repoUsername, repoName } = getRepositoryData() || { repoProvider: null, repoUsername: null, repoName: null }
function variableReplacements () {
const { repoProvider, repoUsername, repoName, repoDirectory, branch } = getRepositoryData() || {}
const regex = /^(?:(?<scope>@.*?)\/)?(?<name>.*)/ // 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 camelCaseName = camelise(name)
const regex = /^(?:(?<scope>@.*?)\/)?(?<name>.*)/ // 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 camelCaseName = camelise(name)
const iifeBundlePath = path.relative('.', pkgJson.exports['./iife-browser-bundle'])
const esmBundlePath = path.relative('.', pkgJson.exports['./esm-browser-bundle'])
const umdBundlePath = path.relative('.', pkgJson.exports['./umd-browser-bundle'])
const iifeBundlePath = pkgJson.exports['./iife-browser-bundle'] !== undefined ? path.relative('.', pkgJson.exports['./iife-browser-bundle']) : undefined
const esmBundlePath = pkgJson.exports['./esm-browser-bundle'] !== undefined ? path.relative('.', pkgJson.exports['./esm-browser-bundle']) : undefined
const umdBundlePath = pkgJson.exports['./umd-browser-bundle'] !== undefined ? path.relative('.', pkgJson.exports['./umd-browser-bundle']) : undefined
let iifeBundle, esmBundle, umdBundle, workflowBadget, coverallsBadge
if (repoProvider) {
let useWorkflowBadge = false
let useCoverallsBadge = false
if (pkgJson.nodeBrowserSkel !== undefined && pkgJson.nodeBrowserSkel.badges !== undefined) {
if (pkgJson.nodeBrowserSkel.badges.workflow === true) {
useWorkflowBadge = true
}
if (pkgJson.nodeBrowserSkel.badges.coveralls === true) {
useCoverallsBadge = true
}
}
let iifeBundle, esmBundle, umdBundle, workflowBadge, coverallsBadge
if (repoProvider) {
switch (repoProvider) {
case 'github':
iifeBundle = `[IIFE bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/master/${iifeBundlePath})`
esmBundle = `[ESM bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/master/${esmBundlePath})`
umdBundle = `[UMD bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/master/${umdBundlePath})`
workflowBadget = `[![Node.js CI](https://github.com/${repoUsername}/${repoName}/actions/workflows/nodejs.yml/badge.svg)](https://github.com/${repoUsername}/${repoName}/actions/workflows/nodejs.yml)`
coverallsBadge = `[![Coverage Status](https://coveralls.io/repos/github/${repoUsername}/${repoName}/badge.svg?branch=master)](https://coveralls.io/github/${repoUsername}/${repoName}?branch=master)`
iifeBundle = iifeBundlePath !== undefined ? `[IIFE bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${iifeBundlePath})` : undefined
esmBundle = esmBundlePath !== undefined ? `[ESM bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${esmBundlePath})` : undefined
umdBundle = umdBundlePath !== undefined ? `[UMD bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${umdBundlePath})` : undefined
workflowBadge = useWorkflowBadge ? `[![Node.js CI](https://github.com/${repoUsername}/${repoName}/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/${repoUsername}/${repoName}/actions/workflows/build-and-test.yml)` : undefined
coverallsBadge = useCoverallsBadge ? `[![Coverage Status](https://coveralls.io/repos/github/${repoUsername}/${repoName}/badge.svg?branch=${branch})](https://coveralls.io/github/${repoUsername}/${repoName}?branch=${branch})` : undefined
break
case 'gitlab':
iifeBundle = `[IIFE bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/master/${iifeBundlePath}?inline=false)`
esmBundle = `[ESM bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/master/${esmBundlePath}?inline=false)`
umdBundle = `[UMD bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/master/${umdBundlePath}?inline=false)`
iifeBundle = iifeBundlePath !== undefined ? `[IIFE bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${iifeBundlePath}?inline=false)` : undefined
esmBundle = esmBundlePath !== undefined ? `[ESM bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${esmBundlePath}?inline=false)` : undefined
umdBundle = umdBundlePath !== undefined ? `[UMD bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${umdBundlePath}?inline=false)` : undefined
break
default:
break
}
}
}
const templateFile = path.join(rootDir, pkgJson.directories.src, 'docs/index.md')
let template = fs.readFileSync(templateFile, { encoding: 'UTF-8' })
template = template
.replace(/\{\{PKG_NAME\}\}/g, pkgJson.name)
.replace(/\{\{PKG_LICENSE\}\}/g, pkgJson.license.replace('-', '_'))
.replace(/\{\{PKG_DESCRIPTION\}\}/g, pkgJson.description)
.replace(/\{\{PKG_CAMELCASE\}\}/g, camelCaseName)
.replace(/\{\{IIFE_BUNDLE\}\}/g, iifeBundle || 'IIFE bundle')
.replace(/\{\{ESM_BUNDLE\}\}/g, esmBundle || 'ESM bundle')
.replace(/\{\{UMD_BUNDLE\}\}/g, umdBundle || 'UMD bundle')
if (repoProvider && repoProvider === 'github') {
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}/g, workflowBadget + '\n' + coverallsBadge)
} else {
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}/g, '')
if (repoProvider && repoProvider === 'github') {
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}\n/gs, (workflowBadge ? `${workflowBadge}\n` : '') + (coverallsBadge ? `${coverallsBadge}\n` : ''))
} else {
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}\n/gs, '')
}
}
const readmeFile = path.join(rootDir, 'README.md')
fs.writeFileSync(readmeFile, template)
typedoc()
rimraf.sync(tempTsConfigPath)
function replaceRelativeLinks () {
const replacements = []
const relativePathRegex = /(\[[\w\s\d]+\]\()(?!(?:http:\/\/)|(?:https:\/\/))([\w\d;,/?:@&=+$-_.!~*'()\\#]+)\)/g
const matches = template.matchAll(relativePathRegex)
if (matches) {
for (const match of matches) {
const index = (match.index ?? 0) + match[1].length
const filepath = match[2]
if (!path.isAbsolute(filepath)) {
const absoluteFilePath = path.join(path.dirname(templateFilePath), filepath)
if (!fs.existsSync(absoluteFilePath)) {
console.warn(`File ${absoluteFilePath} is linked in your index.md but it does not exist. Ignoring`)
} else {
const replacement = path.relative(rootDir, absoluteFilePath)
replacements.push({ index, length: filepath.length, replacement })
}
}
}
const sortedReplacements = replacements.sort((a, b) => a.index - b.index)
let ret = ''
let index = 0
for (const replacement of sortedReplacements) {
ret += template.slice(index, replacement.index)
ret += replacement.replacement
index = replacement.index + replacement.length
}
ret += template.slice(index)
template = ret
}
}

View File

@ -1,7 +1,9 @@
import { mkdirSync, readFileSync, writeFileSync } from 'fs'
import ts from 'typescript'
import { join, dirname } from 'path'
import { join, dirname, extname } from 'path'
import { sync } from 'rimraf'
import * as url from 'url'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const { readJsonConfigFile, sys, parseJsonSourceFileConfigFileContent, createCompilerHost, createProgram } = ts
@ -31,6 +33,15 @@ 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)
}
export const compile = () => {

View File

@ -1,19 +1,25 @@
'use strict'
import inject from '@rollup/plugin-inject'
import { nodeResolve as resolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import { terser } from 'rollup-plugin-terser'
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 { join } from 'path'
import { existsSync } from 'fs'
import { directories, name as _name, exports } from '../package.json'
import { dirname, join } from 'path'
import { existsSync, readFileSync } from 'fs'
// import { browser, name as _name, exports } from '../package.json' assert { type: 'json' }
import { compile } from './rollup-plugin-dts.js'
import * as url from 'url'
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const rootDir = join(__dirname, '..')
const dstDir = join(rootDir, directories.dist)
const pkgJson = JSON.parse(readFileSync(join(rootDir, 'package.json')))
// const dstDir = join(rootDir, directories.dist)
const srcDir = join(rootDir, 'src', 'ts')
function camelise (str) {
@ -24,7 +30,7 @@ function camelise (str) {
}
const regex = /^(?:(?<scope>@.*?)\/)?(?<name>.*)/ // We are going to take only the package name part if there is a scope, e.g. @my-org/package-name
const { name } = _name.match(regex).groups
const { name } = pkgJson.name.match(regex).groups
const pkgCamelisedName = camelise(name)
const input = join(srcDir, 'index.ts')
@ -52,119 +58,61 @@ function compileDts () {
}
export default [
{ // Node ESM with declarations
input: input,
{ // Browser ESM bundle
input,
output: [
{
file: join(rootDir, exports['.'].node.import),
file: join(rootDir, pkgJson.browser),
...sourcemapOutputOptions,
format: 'es'
}
],
plugins: [
replace({
IS_BROWSER: false,
preventAssignment: true
}),
typescriptPlugin(tsBundleOptions),
compileDts(),
// resolve({
// browser: false,
// exportConditions: ['node']
// }),
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
json()
]
},
{ // Node CJS
input: input,
output: [
{
file: join(rootDir, exports['.'].node.require),
...sourcemapOutputOptions,
format: 'cjs',
exports: 'auto'
}
],
plugins: [
// replace({
// 'await import(': 'require(',
// delimiters: ['', ''],
// preventAssignment: true
// }),
replace({
IS_BROWSER: false,
preventAssignment: true
}),
typescriptPlugin(tsBundleOptions),
// resolve({
// browser: false,
// exportConditions: ['node']
// }),
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
json()
]
},
{ // ESM for browsers
input: input,
output: [
{
file: join(rootDir, exports['.'].default),
...sourcemapOutputOptions,
format: 'es'
},
{
file: join(dstDir, 'bundles/esm.js'),
...sourcemapOutputOptions,
format: 'es'
},
{
file: join(dstDir, 'bundles/esm.min.js'),
format: 'es',
plugins: [terser()]
}
],
plugins: [
replace({
IS_BROWSER: true,
_MODULE_TYPE: "'ESM'",
preventAssignment: true
}),
typescriptPlugin(tsBundleOptions),
resolve({
browser: true,
exportConditions: ['browser', 'default']
}),
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
json()
]
},
{ // Browser bundles
input: input,
input,
output: [
{
file: join(dstDir, 'bundles/iife.js'),
file: join(rootDir, pkgJson.exports['./esm-browser-bundle-nomin']),
format: 'es'
},
{
file: join(rootDir, pkgJson.exports['./esm-browser-bundle']),
format: 'es',
plugins: [terser()]
},
{
file: join(rootDir, pkgJson.exports['./iife-browser-bundle']),
format: 'iife',
name: pkgCamelisedName,
plugins: [terser()]
},
{
file: join(dstDir, 'bundles/umd.js'),
file: join(rootDir, pkgJson.exports['./umd-browser-bundle']),
format: 'umd',
name: pkgCamelisedName,
plugins: [terser()]
}
],
plugins: [
// replace({
// 'await import(': 'require(',
// delimiters: ['', ''],
// preventAssignment: true
// }),
replace({
IS_BROWSER: true,
_MODULE_TYPE: "'BUNDLE'",
preventAssignment: true
}),
typescriptPlugin(tsBundleOptions),
typescriptPlugin({
...tsBundleOptions,
sourceMap: false
}),
resolve({
browser: true,
exportConditions: ['browser', 'default'],
@ -173,5 +121,69 @@ export default [
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
json()
]
},
{ // Node CJS
input,
output: [
{
file: join(rootDir, pkgJson.exports['.'].node.require.default),
...sourcemapOutputOptions,
format: 'cjs',
exports: 'auto',
plugins: [
terser()
]
}
],
plugins: [
replace({
IS_BROWSER: false,
_MODULE_TYPE: "'CJS'",
preventAssignment: true
}),
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()
]
},
{ // Node ESM and type declarations
input,
output: [
{
file: join(rootDir, pkgJson.exports['.'].node.import.default),
...sourcemapOutputOptions,
format: 'es',
plugins: [
terser()
]
}
],
plugins: [
replace({
IS_BROWSER: false,
_MODULE_TYPE: "'ESM'",
__filename: `'${pkgJson.exports['.'].node.import.default}'`,
__dirname: `'${dirname(pkgJson.exports['.'].node.import.default)}'`,
preventAssignment: true
}),
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()
]
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

View File

@ -4,6 +4,7 @@ const puppeteer = require('puppeteer')
const minimatch = require('minimatch')
const glob = require('glob')
const rootDir = path.join(__dirname, '../../..')
const pkgJson = require(path.join(rootDir, 'package.json'))
const browserTests = async (
{
@ -21,12 +22,7 @@ const browserTests = async (
const browser = await puppeteer.launch(puppeteerOptions)
const page = (await browser.pages())[0]
page.on('console', function (message) {
let ignore = message.type() === 'warning' && !logWarnings
if (message.type() === 'error' && message.location()) {
if (message.location().url.includes('favicon.ico')) {
ignore = true
}
}
const ignore = message.type() === 'warning' && !logWarnings
if (ignore) return
let text = (message.args().length > 0) ? message.args()[0].remoteObject().value : message.text()
@ -83,12 +79,15 @@ const browserTests = async (
function processedTestFiles (testFilesStr) {
if (testFilesStr === undefined) {
return undefined
}
testFilesStr = [pkgJson.directories.test + '/**/*.ts', pkgJson.directories.src + '/**/*.spec.ts']
} else {
// Let us first remove surrounding quotes in string (it gives issues in windows)
testFilesStr = testFilesStr.replace(/^['"]/, '').replace(/['"]$/, '')
}
const filenames = glob.sync(testFilesStr, { cwd: rootDir, matchBase: true })
if (filenames.length > 0) {
if (filenames.length === 0) {
throw new Error('no test files found for ' + testFilesStr)
} else {
filenames.forEach(file => {
const isTsTestFile = minimatch(file, '{test/**/*.ts,src/**/*.spec.ts}', { matchBase: true })
if (!isTsTestFile) {

View File

@ -9,10 +9,10 @@ require('dotenv').config()
const rollup = require('rollup')
const resolve = require('@rollup/plugin-node-resolve').nodeResolve
const replace = require('@rollup/plugin-replace')
const multi = require('@rollup/plugin-multi-entry')
const typescriptPlugin = require('@rollup/plugin-typescript')
const commonjs = require('@rollup/plugin-commonjs')
const json = require('@rollup/plugin-json')
const multi = require('@rollup/plugin-multi-entry')
const runScript = require('../../run-script.cjs')
const rootDir = path.join(__dirname, '..', '..', '..')
@ -49,16 +49,17 @@ const indexHtml = `<!DOCTYPE html>
const tsBundleOptions = {
tsconfig: path.join(rootDir, 'tsconfig.json'),
outDir: undefined // ignore outDir in tsconfig.json
outDir: undefined, // ignore outDir in tsconfig.json
sourceMap: false
// include: ['build/typings/is-browser.d.ts']
}
async function buildTests (testFiles) {
// create a bundle
const input = testFiles ?? [path.join(rootDir, pkgJson.directories.test, '**/*.ts'), path.join(rootDir, pkgJson.directories.src, '**/*.spec.ts')]
const inputOptions = {
input,
input: testFiles,
plugins: [
multi({ exports: true }),
multi(),
replace({
'#pkg': `/${name}.esm.js`,
delimiters: ['', ''],
@ -66,12 +67,14 @@ async function buildTests (testFiles) {
}),
replace({
IS_BROWSER: true,
_MODULE_TYPE: "'ESM'",
preventAssignment: true
}),
typescriptPlugin(tsBundleOptions),
resolve({
browser: true,
exportConditions: ['browser', 'default']
exportConditions: ['browser', 'default'],
mainFields: ['browser', 'module', 'main']
}),
commonjs(),
json()
@ -79,7 +82,7 @@ async function buildTests (testFiles) {
external: [`/${name}.esm.js`]
}
const bundle = await rollup.rollup(inputOptions)
const { output } = await bundle.generate({ format: 'esm' })
const { output } = await bundle.generate({ format: 'es' })
await bundle.close()
let bundledCode = output[0].code
const replacements = _getEnvVarsReplacements(bundledCode)
@ -97,14 +100,14 @@ class TestServer {
async init (testFiles) {
/** Let us first check if the necessary files are built, and if not, build */
if (!fs.existsSync(pkgJson.exports['./esm-browser-bundle'])) {
if (!fs.existsSync(pkgJson.exports['./esm-browser-bundle-nomin'])) {
await runScript(path.join(rootDir, 'node_modules', '.bin', 'rollup'), ['-c', 'build/rollup.config.js'])
}
const tests = await buildTests(testFiles)
this.server.on('request', function (req, res) {
if (req.url === `/${name}.esm.js`) {
fs.readFile(path.join(rootDir, pkgJson.exports['./esm-browser-bundle']), function (err, data) {
fs.readFile(path.join(rootDir, pkgJson.exports['./esm-browser-bundle-nomin']), function (err, data) {
if (err) {
res.writeHead(404)
res.end(JSON.stringify(err))
@ -129,6 +132,16 @@ class TestServer {
res.writeHead(200, { 'Content-Type': 'text/javascript' })
res.end(data)
})
} else if (req.url === '/mocha.js.map') {
fs.readFile(path.join(rootDir, 'node_modules/mocha/mocha.js.map'), function (err, data) {
if (err) {
res.writeHead(404)
res.end(JSON.stringify(err))
return
}
res.writeHead(200, { 'Content-Type': 'text/javascript' })
res.end(data)
})
} else if (req.url === '/chai.js' || req.url === '/chai') {
fs.readFile(path.join(rootDir, 'node_modules/chai/chai.js'), function (err, data) {
if (err) {
@ -139,6 +152,16 @@ class TestServer {
res.writeHead(200, { 'Content-Type': 'text/javascript' })
res.end(data)
})
} else if (req.url === '/favicon.ico') {
fs.readFile(path.join(__dirname, 'favicon.ico'), function (err, data) {
if (err) {
res.writeHead(404)
res.end(JSON.stringify(err))
return
}
res.writeHead(200, { 'Content-Type': 'application/ico' })
res.end(data)
})
} else {
res.writeHead(404)
res.end()
@ -171,7 +194,7 @@ function _getEnvVarsReplacements (testsCode) {
if (process.env[envVar] !== undefined) {
replacements[match[0]] = '`' + process.env[envVar] + '`'
} else {
missingEnvVars.push(envVar)
replacements[match[0]] = undefined
}
}
for (const match of testsCode.matchAll(/process\.env\[['"](\w+)['"]\]/g)) {
@ -179,11 +202,11 @@ function _getEnvVarsReplacements (testsCode) {
if (process.env[envVar] !== undefined) {
replacements[match[0]] = '`' + process.env[envVar] + '`'
} else {
missingEnvVars.push(envVar)
replacements[match[0]] = undefined
}
}
if (missingEnvVars.length > 0) {
throw EvalError('The folloinwg environment variables are missing in your .env file: ' + missingEnvVars)
console.warn('The folloinwg environment variables are missing in your .env file and will be replaced with "undefined": ' + [...(new Set(missingEnvVars)).values()].join(', '))
}
return replacements
}

View File

@ -3,7 +3,7 @@ const fs = require('fs')
const path = require('path')
const rollup = require('rollup')
const loadAndParseConfigFile = require('rollup/dist/loadConfigFile')
const loadAndParseConfigFile = require('rollup/loadConfigFile').loadConfigFile
const Builder = require('./Builder.cjs')
@ -27,7 +27,7 @@ class RollupBuilder extends Builder {
this.watch = watch
this.commonjs = commonjs
this.watchedModule = commonjs ? pkgJson.exports['.'].node.require : pkgJson.exports['.'].node.import
this.watchedModule = commonjs ? pkgJson.exports['.'].node.require.default : pkgJson.exports['.'].node.import.default
const { options } = await loadAndParseConfigFile(this.configPath)

View File

@ -30,13 +30,36 @@ function renameJsToCjs (dir, fileList = []) {
const files = fs.readdirSync(dir)
files.forEach(file => {
if (fs.statSync(path.join(dir, file)).isDirectory()) {
fileList = renameJsToCjs(path.join(dir, file), fileList)
const srcFile = path.join(dir, file)
if (fs.statSync(srcFile).isDirectory()) {
fileList = renameJsToCjs(srcFile, fileList)
} else {
const match = file.match(/(.*)\.js$/)
if (match !== null) {
const filename = match[1]
fs.renameSync(path.join(dir, file), path.join(dir, `${filename}.cjs`))
const dstFile = path.join(dir, `${filename}.cjs`)
fs.renameSync(srcFile, dstFile)
const fileContents = fs.readFileSync(dstFile, 'utf8')
const updatedFileContents = fileContents.replace(/(require\([`'"])(\..*[^.]{5})([`'"])/g, '$1$2.cjs$3')
fs.writeFileSync(dstFile, updatedFileContents, { encoding: 'utf8' })
}
}
})
}
function fixJsonAssertsInESMTests (dir, fileList = []) {
const files = fs.readdirSync(dir)
files.forEach(file => {
const srcFile = path.join(dir, file)
if (fs.statSync(srcFile).isDirectory()) {
fileList = fixJsonAssertsInESMTests(srcFile, fileList)
} else {
const match = file.match(/(.*)\.js$/)
if (match !== null) {
const fileContents = fs.readFileSync(srcFile, 'utf8')
const updatedFileContents = fileContents.replace(/(import\([`'"]\..*\.json[`'"])\)/g, '$1, { assert: { type: "json" } })')
fs.writeFileSync(srcFile, updatedFileContents, { encoding: 'utf8' })
}
}
})
@ -124,6 +147,8 @@ class TestsBuilder extends Builder {
}
if (this.commonjs) {
renameJsToCjs(mochaTsDir)
} else {
fixJsonAssertsInESMTests(mochaTsDir)
}
this.emit('ready', updateSemaphore)
} else {

View File

@ -27,6 +27,8 @@ let commonjs = setup.commonjs
commonjs = watch ? true : commonjs // mocha in watch mode only supports commonjs
global._MODULE_TYPE = commonjs ? 'CJS' : 'ESM'
exports.mochaGlobalSetup = async function () {
if (watch) {
await rollupBuilder.start({ commonjs, watch })

View File

@ -1 +1,2 @@
declare const IS_BROWSER: boolean
declare const _MODULE_TYPE: string

100
dist/bundles/esm.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
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,b=e-i*u;t=n,n=f,r=o,e=i,o=g,i=b}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<<i}function o(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 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,Object.defineProperty(n,"__esModule",{value:!0}),n}({});
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<<i}function o(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 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}({});

2
dist/bundles/umd.js vendored
View File

@ -1 +1 @@
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).bigintModArith={})}(this,(function(n){"use strict";function e(n){return n>=0?n:-n}function t(n,e){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),n<=0n||e<=0n)throw new RangeError("a and b MUST be > 0");let t=0n,r=1n,o=1n,i=0n;for(;0n!==n;){const f=e/n,u=e%n,g=t-o*f,b=r-i*f;e=n,n=u,t=o,r=i,o=g,i=b}return{g:e,x:t,y:r}}function r(n,t){let r="number"==typeof n?BigInt(e(n)):e(n),o="number"==typeof t?BigInt(e(t)):e(t);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<<i}function o(n,e){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof e&&(e=BigInt(e)),e<=0n)throw new RangeError("n must be > 0");const t=n%e;return t<0n?t+e:t}function i(n,e){const r=t(o(n,e),e);if(1n!==r.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${e.toString()}`);return o(r.x,e)}n.abs=e,n.bitLength=function(n){if("number"==typeof n&&(n=BigInt(n)),1n===n)return 1;let e=1;do{e++}while((n>>=1n)>1n);return e},n.eGcd=t,n.gcd=r,n.lcm=function(n,t){return"number"==typeof n&&(n=BigInt(n)),"number"==typeof t&&(t=BigInt(t)),0n===n&&0n===t?BigInt(0):e(n/r(n,t)*t)},n.max=function(n,e){return n>=e?n:e},n.min=function(n,e){return n>=e?e:n},n.modInv=i,n.modPow=function n(t,r,f){if("number"==typeof t&&(t=BigInt(t)),"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(t=o(t,f),r<0n)return i(n(t,e(r),f),f);let u=1n;for(;r>0;)r%2n===1n&&(u=u*t%f),r/=2n,t=t**2n%f;return u},n.toZn=o,Object.defineProperty(n,"__esModule",{value:!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<<i}function o(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 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}));

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

240
dist/esm/index.node.js vendored

File diff suppressed because one or more lines are too long

View File

@ -43,7 +43,7 @@ The absolute value of a
#### Defined in
[abs.ts:8](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/abs.ts#L8)
[abs.ts:8](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/abs.ts#L8)
___
@ -67,7 +67,7 @@ The bit length
#### Defined in
[bitLength.ts:7](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/bitLength.ts#L7)
[bitLength.ts:7](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/bitLength.ts#L7)
___
@ -97,7 +97,7 @@ 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/59cd071/src/ts/egcd.ts#L17)
[egcd.ts:17](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/egcd.ts#L17)
___
@ -122,7 +122,7 @@ The greatest common divisor of a and b
#### Defined in
[gcd.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/gcd.ts#L10)
[gcd.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/gcd.ts#L10)
___
@ -147,7 +147,7 @@ The least common multiple of a and b
#### Defined in
[lcm.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/lcm.ts#L10)
[lcm.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/lcm.ts#L10)
___
@ -172,7 +172,7 @@ Maximum of numbers a and b
#### Defined in
[max.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/max.ts#L9)
[max.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/max.ts#L9)
___
@ -197,7 +197,7 @@ Minimum of numbers a and b
#### Defined in
[min.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/min.ts#L9)
[min.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/min.ts#L9)
___
@ -226,7 +226,7 @@ The inverse modulo n
#### Defined in
[modInv.ts:13](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/modInv.ts#L13)
[modInv.ts:13](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/modInv.ts#L13)
___
@ -256,7 +256,7 @@ b**e mod n
#### Defined in
[modPow.ts:15](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/modPow.ts#L15)
[modPow.ts:15](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/modPow.ts#L15)
___
@ -289,4 +289,4 @@ A bigint with the smallest positive representation of a modulo n
#### Defined in
[toZn.ts:14](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/toZn.ts#L14)
[toZn.ts:14](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/toZn.ts#L14)

View File

@ -16,7 +16,7 @@
#### Defined in
[egcd.ts:2](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/egcd.ts#L2)
[egcd.ts:2](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/egcd.ts#L2)
___
@ -26,7 +26,7 @@ ___
#### Defined in
[egcd.ts:3](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/egcd.ts#L3)
[egcd.ts:3](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/egcd.ts#L3)
___
@ -36,4 +36,4 @@ ___
#### Defined in
[egcd.ts:4](https://github.com/juanelas/bigint-mod-arith/blob/59cd071/src/ts/egcd.ts#L4)
[egcd.ts:4](https://github.com/juanelas/bigint-mod-arith/blob/fc5e3c5/src/ts/egcd.ts#L4)

6900
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -24,28 +24,47 @@
"node": ">=10.4.0"
},
"type": "module",
"types": "./types/index.d.ts",
"main": "./dist/cjs/index.node.cjs",
"types": "./types/index.d.cts",
"browser": "./dist/esm/index.browser.js",
"module": "./dist/esm/index.node.js",
"exports": {
".": {
"node": {
"require": "./dist/cjs/index.node.cjs",
"import": "./dist/esm/index.node.js",
"module": "./dist/esm/index.node.js"
"require": {
"default": "./dist/cjs/index.node.cjs",
"types": "./types/index.d.cts"
},
"default": "./dist/esm/index.browser.js"
"import": {
"default": "./dist/esm/index.node.js",
"types": "./types/index.d.ts"
}
},
"default": {
"default": "./dist/esm/index.browser.js",
"types": "./types/index.d.ts"
}
},
"./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.ts"
"./types": "./types/index.d.cts"
},
"imports": {
"#pkg": {
"import": "./dist/esm/index.node.js",
"require": "./dist/cjs/index.node.cjs"
"require": {
"default": "./dist/cjs/index.node.cjs",
"types": "./types/index.d.cts"
},
"import": {
"default": "./dist/esm/index.node.js",
"types": "./types/index.d.ts"
},
"default": {
"default": "./dist/esm/index.browser.js",
"types": "./types/index.d.ts"
}
}
},
"directories": {
@ -58,19 +77,21 @@
"mocha-ts": "./.mocha-ts"
},
"scripts": {
"build": "run-s lint build:js docs",
"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",
"coverage": "c8 --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 ",
"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",
"lint": "ts-standard --fix",
"mocha-ts": "node --experimental-modules --es-module-specifier-resolution=node ./build/bin/mocha-ts.cjs ",
"lint:src": "ts-standard --fix \"src/**/!(*.spec).ts\"",
"lint:test": "ts-standard --fix \"{test/**/*.ts,src/**/*.spec.ts}\"",
"mocha-ts": "node --experimental-modules --experimental-json-modules --es-module-specifier-resolution=node ./build/bin/mocha-ts.cjs ",
"mocha-ts:cjs": "node ./build/bin/mocha-ts.cjs --commonjs ",
"mocha-ts:watch": "npm run mocha-ts:cjs -- --watch ",
"mocha-ts:browser": "node build/testing/browser/index.cjs ",
"mocha-ts:browser-headless": "node build/testing/browser/index.cjs headless ",
"preversion": "run-s clean lint build:js coverage test:browser-headless",
"preversion": "run-s clean lint:src build:js lint:test coverage test:browser-headless",
"version": "run-s docs git:add",
"postversion": "git push --follow-tags",
"test": "run-s test:node test:browser-headless",
@ -82,6 +103,7 @@
"watch": "npm run mocha-ts:watch "
},
"ts-standard": {
"project": "tsconfig.json",
"env": [
"mocha"
],
@ -91,40 +113,49 @@
"page",
"chai"
],
"project": "tsconfig.json",
"ignore": [
"dist/**/*",
"examples/**/*",
"types/**/*",
"build/testing/mocha/mocha-init.js"
"benchmark/**/*"
]
},
"nodeBrowserSkel": {
"badges": {
"workflow": true,
"coveralls": true
},
"git": {
"branch": "main"
}
},
"devDependencies": {
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-multi-entry": "^4.0.0",
"@rollup/plugin-node-resolve": "^14.1.0",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-typescript": "^8.2.0",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-inject": "^5.0.3",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-multi-entry": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^11.1.0",
"@types/chai": "^4.2.22",
"@types/mocha": "^10.0.0",
"c8": "^7.12.0",
"chai": "^4.3.3",
"dotenv": "^16.0.3",
"glob": "^8.0.1",
"glob": "^9.3.4",
"json5": "^2.2.0",
"minimatch": "^5.0.1",
"minimatch": "^8.0.3",
"mocha": "^10.0.0",
"npm-run-all": "^4.1.5",
"pirates": "^4.0.1",
"puppeteer": "^18.0.5",
"rimraf": "^3.0.2",
"rollup": "^2.57.0",
"rollup-plugin-terser": "^7.0.2",
"ts-standard": "^11.0.0",
"puppeteer": "^19.1.2",
"rimraf": "^4.4.1",
"rollup": "^3.20.2",
"ts-standard": "^12.0.2",
"tslib": "^2.3.1",
"typedoc": "^0.23.0",
"typedoc-plugin-markdown": "^3.11.0",
"typescript": "^4.4.3"
"typedoc": "~0.23.0",
"typedoc-plugin-markdown": "~3.14.0",
"typescript": "^5.0.3"
}
}

View File

@ -5,6 +5,6 @@
*
* @returns The absolute value of a
*/
export function abs (a: number|bigint): number|bigint {
export function abs (a: number | bigint): number | bigint {
return (a >= 0) ? a : -a
}

View File

@ -4,7 +4,7 @@
* @param a
* @returns The bit length
*/
export function bitLength (a: number|bigint): number {
export function bitLength (a: number | bigint): number {
if (typeof a === 'number') a = BigInt(a)
if (a === 1n) { return 1 }

View File

@ -14,7 +14,7 @@ export interface Egcd {
*
* @returns A triple (g, x, y), such that ax + by = g = gcd(a, b).
*/
export function eGcd (a: number|bigint, b: number|bigint): Egcd {
export function eGcd (a: number | bigint, b: number | bigint): Egcd {
if (typeof a === 'number') a = BigInt(a)
if (typeof b === 'number') b = BigInt(b)
@ -39,7 +39,7 @@ export function eGcd (a: number|bigint, b: number|bigint): Egcd {
}
return {
g: b,
x: x,
y: y
x,
y
}
}

View File

@ -1,4 +1,4 @@
import { abs } from './abs'
import { abs } from './abs.js'
/**
* Greatest common divisor of two integers based on the iterative binary algorithm.
*
@ -7,7 +7,7 @@ import { abs } from './abs'
*
* @returns The greatest common divisor of a and b
*/
export function gcd (a: number|bigint, b: number|bigint): bigint {
export function gcd (a: number | bigint, b: number | bigint): bigint {
let aAbs = (typeof a === 'number') ? BigInt(abs(a)) : abs(a) as bigint
let bAbs = (typeof b === 'number') ? BigInt(abs(b)) : abs(b) as bigint

View File

@ -4,13 +4,13 @@
* @packageDocumentation
*/
export { abs } from './abs'
export { bitLength } from './bitLength'
export { Egcd, eGcd } from './egcd'
export { gcd } from './gcd'
export { lcm } from './lcm'
export { max } from './max'
export { min } from './min'
export { modInv } from './modInv'
export { modPow } from './modPow'
export { toZn } from './toZn'
export { abs } from './abs.js'
export { bitLength } from './bitLength.js'
export { Egcd, eGcd } from './egcd.js'
export { gcd } from './gcd.js'
export { lcm } from './lcm.js'
export { max } from './max.js'
export { min } from './min.js'
export { modInv } from './modInv.js'
export { modPow } from './modPow.js'
export { toZn } from './toZn.js'

View File

@ -1,5 +1,5 @@
import { abs } from './abs'
import { gcd } from './gcd'
import { abs } from './abs.js'
import { gcd } from './gcd.js'
/**
* The least common multiple computed as abs(a*b)/gcd(a,b)
* @param a
@ -7,7 +7,7 @@ import { gcd } from './gcd'
*
* @returns The least common multiple of a and b
*/
export function lcm (a: number|bigint, b: number|bigint): bigint {
export function lcm (a: number | bigint, b: number | bigint): bigint {
if (typeof a === 'number') a = BigInt(a)
if (typeof b === 'number') b = BigInt(b)

View File

@ -6,6 +6,6 @@
*
* @returns Maximum of numbers a and b
*/
export function max (a: number|bigint, b: number|bigint): number|bigint {
export function max (a: number | bigint, b: number | bigint): number | bigint {
return (a >= b) ? a : b
}

View File

@ -6,6 +6,6 @@
*
* @returns Minimum of numbers a and b
*/
export function min (a: number|bigint, b: number|bigint): number|bigint {
export function min (a: number | bigint, b: number | bigint): number | bigint {
return (a >= b) ? b : a
}

View File

@ -1,5 +1,5 @@
import { eGcd } from './egcd'
import { toZn } from './toZn'
import { eGcd } from './egcd.js'
import { toZn } from './toZn.js'
/**
* Modular inverse.
*
@ -10,7 +10,7 @@ import { toZn } from './toZn'
*
* @returns The inverse modulo n
*/
export function modInv (a: number|bigint, n: number|bigint): bigint {
export function modInv (a: number | bigint, n: number | bigint): bigint {
const egcd = eGcd(toZn(a, n), n)
if (egcd.g !== 1n) {
throw new RangeError(`${a.toString()} does not have inverse modulo ${n.toString()}`) // modular inverse does not exist

View File

@ -1,6 +1,6 @@
import { abs } from './abs'
import { modInv } from './modInv'
import { toZn } from './toZn'
import { abs } from './abs.js'
import { modInv } from './modInv.js'
import { toZn } from './toZn.js'
/**
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method
*
@ -12,7 +12,7 @@ import { toZn } from './toZn'
*
* @returns b**e mod n
*/
export function modPow (b: number|bigint, e: number|bigint, n: number|bigint): bigint {
export function modPow (b: number | bigint, e: number | bigint, n: number | bigint): bigint {
if (typeof b === 'number') b = BigInt(b)
if (typeof e === 'number') e = BigInt(e)
if (typeof n === 'number') n = BigInt(n)

View File

@ -11,7 +11,7 @@
*
* @returns A bigint with the smallest positive representation of a modulo n
*/
export function toZn (a: number|bigint, n: number|bigint): bigint {
export function toZn (a: number | bigint, n: number | bigint): bigint {
if (typeof a === 'number') a = BigInt(a)
if (typeof n === 'number') n = BigInt(n)

View File

@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', 'ES2023', 'ES2023' or 'ESNEXT'. */
"module": "ESNext",
// "lib": [ "es2020" ], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
@ -9,6 +9,7 @@
"checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'react', 'react-jsx', 'react-jsxdev', 'preserve' or 'react-native'. */
"strict": true, /* Enable all strict type-checking options. */
"removeComments": true,
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
@ -21,13 +22,14 @@
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDir": ".",
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
"typeRoots": [ "node_modules/@types", "build/typings" ], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
"allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
@ -38,7 +40,7 @@
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
"resolveJsonModule": true,
"paths": {
"#pkg": ["."]
"#pkg": ["./src/ts/index.ts"]
}
},
"include": ["src/ts/**/*", "build/typings/**/*.d.ts", "test/**/*", "test-vectors/**/*.ts", "benchmark/**/*.ts"]

2
types/abs.d.cts Normal file
View File

@ -0,0 +1,2 @@
export declare function abs(a: number | bigint): number | bigint;
//# sourceMappingURL=abs.d.ts.map

1
types/abs.d.cts.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"abs.d.ts","sourceRoot":"","sources":["../src/ts/abs.ts"],"names":[],"mappings":"AAOA,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAExD"}

7
types/abs.d.ts vendored
View File

@ -1,9 +1,2 @@
/**
* Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
*
* @param a
*
* @returns The absolute value of a
*/
export declare function abs(a: number | bigint): number | bigint;
//# sourceMappingURL=abs.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"abs.d.ts","sourceRoot":"","sources":["../src/ts/abs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,GAAC,MAAM,CAEpD"}
{"version":3,"file":"abs.d.ts","sourceRoot":"","sources":["../src/ts/abs.ts"],"names":[],"mappings":"AAOA,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAExD"}

2
types/bitLength.d.cts Normal file
View File

@ -0,0 +1,2 @@
export declare function bitLength(a: number | bigint): number;
//# sourceMappingURL=bitLength.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"bitLength.d.ts","sourceRoot":"","sources":["../src/ts/bitLength.ts"],"names":[],"mappings":"AAMA,wBAAgB,SAAS,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CASrD"}

View File

@ -1,8 +1,2 @@
/**
* Returns the (minimum) length of a number expressed in bits.
*
* @param a
* @returns The bit length
*/
export declare function bitLength(a: number | bigint): number;
//# sourceMappingURL=bitLength.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"bitLength.d.ts","sourceRoot":"","sources":["../src/ts/bitLength.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,SAAS,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,CASnD"}
{"version":3,"file":"bitLength.d.ts","sourceRoot":"","sources":["../src/ts/bitLength.ts"],"names":[],"mappings":"AAMA,wBAAgB,SAAS,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CASrD"}

7
types/egcd.d.cts Normal file
View File

@ -0,0 +1,7 @@
export interface Egcd {
g: bigint;
x: bigint;
y: bigint;
}
export declare function eGcd(a: number | bigint, b: number | bigint): Egcd;
//# sourceMappingURL=egcd.d.ts.map

1
types/egcd.d.cts.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"egcd.d.ts","sourceRoot":"","sources":["../src/ts/egcd.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAYD,wBAAgB,IAAI,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA4BlE"}

11
types/egcd.d.ts vendored
View File

@ -3,16 +3,5 @@ export interface Egcd {
x: bigint;
y: bigint;
}
/**
* 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).
*
* @param a
* @param b
*
* @throws {@link RangeError} if a or b are <= 0
*
* @returns A triple (g, x, y), such that ax + by = g = gcd(a, b).
*/
export declare function eGcd(a: number | bigint, b: number | bigint): Egcd;
//# sourceMappingURL=egcd.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"egcd.d.ts","sourceRoot":"","sources":["../src/ts/egcd.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AACD;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,IAAI,CA4B9D"}
{"version":3,"file":"egcd.d.ts","sourceRoot":"","sources":["../src/ts/egcd.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAYD,wBAAgB,IAAI,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA4BlE"}

2
types/gcd.d.cts Normal file
View File

@ -0,0 +1,2 @@
export declare function gcd(a: number | bigint, b: number | bigint): bigint;
//# sourceMappingURL=gcd.d.ts.map

1
types/gcd.d.cts.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"gcd.d.ts","sourceRoot":"","sources":["../src/ts/gcd.ts"],"names":[],"mappings":"AASA,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CA6BnE"}

8
types/gcd.d.ts vendored
View File

@ -1,10 +1,2 @@
/**
* Greatest common divisor of two integers based on the iterative binary algorithm.
*
* @param a
* @param b
*
* @returns The greatest common divisor of a and b
*/
export declare function gcd(a: number | bigint, b: number | bigint): bigint;
//# sourceMappingURL=gcd.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"gcd.d.ts","sourceRoot":"","sources":["../src/ts/gcd.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,CA6B/D"}
{"version":3,"file":"gcd.d.ts","sourceRoot":"","sources":["../src/ts/gcd.ts"],"names":[],"mappings":"AASA,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CA6BnE"}

11
types/index.d.cts Normal file
View File

@ -0,0 +1,11 @@
export { abs } from './abs.js';
export { bitLength } from './bitLength.js';
export { Egcd, eGcd } from './egcd.js';
export { gcd } from './gcd.js';
export { lcm } from './lcm.js';
export { max } from './max.js';
export { min } from './min.js';
export { modInv } from './modInv.js';
export { modPow } from './modPow.js';
export { toZn } from './toZn.js';
//# sourceMappingURL=index.d.ts.map

1
types/index.d.cts.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/ts/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA"}

25
types/index.d.ts vendored
View File

@ -1,16 +1,11 @@
/**
* Some common functions for modular arithmetic using native JS implementation of BigInt
*
* @packageDocumentation
*/
export { abs } from './abs';
export { bitLength } from './bitLength';
export { Egcd, eGcd } from './egcd';
export { gcd } from './gcd';
export { lcm } from './lcm';
export { max } from './max';
export { min } from './min';
export { modInv } from './modInv';
export { modPow } from './modPow';
export { toZn } from './toZn';
export { abs } from './abs.js';
export { bitLength } from './bitLength.js';
export { Egcd, eGcd } from './egcd.js';
export { gcd } from './gcd.js';
export { lcm } from './lcm.js';
export { max } from './max.js';
export { min } from './min.js';
export { modInv } from './modInv.js';
export { modPow } from './modPow.js';
export { toZn } from './toZn.js';
//# sourceMappingURL=index.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/ts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3B,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3B,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3B,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/ts/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA"}

2
types/lcm.d.cts Normal file
View File

@ -0,0 +1,2 @@
export declare function lcm(a: number | bigint, b: number | bigint): bigint;
//# sourceMappingURL=lcm.d.ts.map

1
types/lcm.d.cts.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"lcm.d.ts","sourceRoot":"","sources":["../src/ts/lcm.ts"],"names":[],"mappings":"AASA,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAOnE"}

7
types/lcm.d.ts vendored
View File

@ -1,9 +1,2 @@
/**
* The least common multiple computed as abs(a*b)/gcd(a,b)
* @param a
* @param b
*
* @returns The least common multiple of a and b
*/
export declare function lcm(a: number | bigint, b: number | bigint): bigint;
//# sourceMappingURL=lcm.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"lcm.d.ts","sourceRoot":"","sources":["../src/ts/lcm.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,CAO/D"}
{"version":3,"file":"lcm.d.ts","sourceRoot":"","sources":["../src/ts/lcm.ts"],"names":[],"mappings":"AASA,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAOnE"}

2
types/max.d.cts Normal file
View File

@ -0,0 +1,2 @@
export declare function max(a: number | bigint, b: number | bigint): number | bigint;
//# sourceMappingURL=max.d.ts.map

1
types/max.d.cts.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"max.d.ts","sourceRoot":"","sources":["../src/ts/max.ts"],"names":[],"mappings":"AAQA,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAE5E"}

8
types/max.d.ts vendored
View File

@ -1,10 +1,2 @@
/**
* Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<b
*
* @param a
* @param b
*
* @returns Maximum of numbers a and b
*/
export declare function max(a: number | bigint, b: number | bigint): number | bigint;
//# sourceMappingURL=max.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"max.d.ts","sourceRoot":"","sources":["../src/ts/max.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,GAAC,MAAM,CAEtE"}
{"version":3,"file":"max.d.ts","sourceRoot":"","sources":["../src/ts/max.ts"],"names":[],"mappings":"AAQA,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAE5E"}

2
types/min.d.cts Normal file
View File

@ -0,0 +1,2 @@
export declare function min(a: number | bigint, b: number | bigint): number | bigint;
//# sourceMappingURL=min.d.ts.map

1
types/min.d.cts.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"min.d.ts","sourceRoot":"","sources":["../src/ts/min.ts"],"names":[],"mappings":"AAQA,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAE5E"}

8
types/min.d.ts vendored
View File

@ -1,10 +1,2 @@
/**
* Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<b
*
* @param a
* @param b
*
* @returns Minimum of numbers a and b
*/
export declare function min(a: number | bigint, b: number | bigint): number | bigint;
//# sourceMappingURL=min.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"min.d.ts","sourceRoot":"","sources":["../src/ts/min.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,GAAC,MAAM,CAEtE"}
{"version":3,"file":"min.d.ts","sourceRoot":"","sources":["../src/ts/min.ts"],"names":[],"mappings":"AAQA,wBAAgB,GAAG,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAE5E"}

2
types/modInv.d.cts Normal file
View File

@ -0,0 +1,2 @@
export declare function modInv(a: number | bigint, n: number | bigint): bigint;
//# sourceMappingURL=modInv.d.ts.map

1
types/modInv.d.cts.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"modInv.d.ts","sourceRoot":"","sources":["../src/ts/modInv.ts"],"names":[],"mappings":"AAYA,wBAAgB,MAAM,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAOtE"}

10
types/modInv.d.ts vendored
View File

@ -1,12 +1,2 @@
/**
* Modular inverse.
*
* @param a The number to find an inverse for
* @param n The modulo
*
* @throws {@link RangeError} if a does not have inverse modulo n
*
* @returns The inverse modulo n
*/
export declare function modInv(a: number | bigint, n: number | bigint): bigint;
//# sourceMappingURL=modInv.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"modInv.d.ts","sourceRoot":"","sources":["../src/ts/modInv.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,CAOlE"}
{"version":3,"file":"modInv.d.ts","sourceRoot":"","sources":["../src/ts/modInv.ts"],"names":[],"mappings":"AAYA,wBAAgB,MAAM,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAOtE"}

2
types/modPow.d.cts Normal file
View File

@ -0,0 +1,2 @@
export declare function modPow(b: number | bigint, e: number | bigint, n: number | bigint): bigint;
//# sourceMappingURL=modPow.d.ts.map

1
types/modPow.d.cts.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"modPow.d.ts","sourceRoot":"","sources":["../src/ts/modPow.ts"],"names":[],"mappings":"AAcA,wBAAgB,MAAM,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CA0B1F"}

11
types/modPow.d.ts vendored
View File

@ -1,13 +1,2 @@
/**
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method
*
* @param b base
* @param e exponent
* @param n modulo
*
* @throws {@link RangeError} if n <= 0
*
* @returns b**e mod n
*/
export declare function modPow(b: number | bigint, e: number | bigint, n: number | bigint): bigint;
//# sourceMappingURL=modPow.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"modPow.d.ts","sourceRoot":"","sources":["../src/ts/modPow.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,CA0BpF"}
{"version":3,"file":"modPow.d.ts","sourceRoot":"","sources":["../src/ts/modPow.ts"],"names":[],"mappings":"AAcA,wBAAgB,MAAM,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CA0B1F"}

2
types/toZn.d.cts Normal file
View File

@ -0,0 +1,2 @@
export declare function toZn(a: number | bigint, n: number | bigint): bigint;
//# sourceMappingURL=toZn.d.ts.map

1
types/toZn.d.cts.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"toZn.d.ts","sourceRoot":"","sources":["../src/ts/toZn.ts"],"names":[],"mappings":"AAaA,wBAAgB,IAAI,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAUpE"}

13
types/toZn.d.ts vendored
View File

@ -1,15 +1,2 @@
/**
* Finds the smallest positive element that is congruent to a in modulo n
*
* @remarks
* a and b must be the same type, either number or bigint
*
* @param a - An integer
* @param n - The modulo
*
* @throws {@link RangeError} if n <= 0
*
* @returns A bigint with the smallest positive representation of a modulo n
*/
export declare function toZn(a: number | bigint, n: number | bigint): bigint;
//# sourceMappingURL=toZn.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"toZn.d.ts","sourceRoot":"","sources":["../src/ts/toZn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,IAAI,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,CAAC,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,CAUhE"}
{"version":3,"file":"toZn.d.ts","sourceRoot":"","sources":["../src/ts/toZn.ts"],"names":[],"mappings":"AAaA,wBAAgB,IAAI,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAUpE"}