refactor: move build system and don't bundle code

This commit is contained in:
Derrick Hammer 2023-07-11 18:37:07 -04:00
parent 8f97d626a5
commit 655dfe72b0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
106 changed files with 19367 additions and 10827 deletions

View File

@ -1,116 +0,0 @@
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, 20.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 }}

13
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Build/Publish
on:
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

5
.presetterrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"preset": [
"@lumeweb/node-library-preset"
]
}

View File

@ -1,134 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[INSERT CONTACT METHOD].
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of
actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the
community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
[https://www.contributor-covenant.org/translations][translations].
[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations

View File

@ -1,168 +0,0 @@
#! /usr/bin/env node
const fs = require('fs')
const path = require('path')
const glob = require('glob')
const minimatch = require('minimatch').minimatch
const rimraf = require('rimraf')
const runScript = require('../run-script.cjs')
const rootDir = path.join(__dirname, '../..')
const pkgJson = require(path.join(rootDir, 'package.json'))
const mochaTsRelativeDir = pkgJson.directories['mocha-ts']
const mochaTsDir = path.join(rootDir, mochaTsRelativeDir)
// clean .mocha-ts directory
rimraf.sync(mochaTsDir)
const semaphorePath = `${mochaTsRelativeDir}/semaphore`
const tempDir = mochaTsDir
fs.mkdirSync(tempDir, { recursive: true })
const usage = `Usage: mocha-ts [options] [spec]
mocha against ts tests and modules
Arguments:
spec One or more files, directories, or globs to test (default:
"{src/ts/**/*.spec.ts,test/**/*.ts}")
Options:
-w, --watch run in watch mode. Since mocha only supports CJS in watch
mode. This option implies -cjs as well (default: false)
-cjs, --commonjs run tests against the CJS bundle instead of the ESM one
(default: false)
-h, --help display help for command
`
function parse () {
const args = process.argv.slice(2)
const help = getBooleanOption(args, '--help', '-h')
if (help) {
console.log(usage)
process.exit()
}
const requiredFile = getOption(args, '--require')
const watch = getBooleanOption(args, '--watch', '-w')
const commonjs = getBooleanOption(args, '--commonjs', '-cjs')
if (commonjs === false && watch === true) {
console.log('ERROR: mocha in watch mode only supports commonjs')
console.log(usage)
process.exit(1)
}
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 = []
if (requiredFile !== '') {
mochaArgs.push('--require')
mochaArgs.push(requiredFile)
}
mochaArgs.push('--require')
mochaArgs.push('build/testing/mocha/mocha-init.cjs')
if (watch) {
mochaArgs.push('-w')
mochaArgs.push('--watch-files')
mochaArgs.push(semaphorePath)
}
if (testsGlob.substring(0, 1) === '-') {
console.log(usage)
process.exit(9)
}
let filenames = []
try {
filenames = glob.sync(testsGlob, { cwd: rootDir, matchBase: true })
} catch (error) {}
if (filenames.length === 0) {
console.error('invalid or empty glob pattern: ' + testsGlob)
console.log()
console.log(usage)
process.exit(9)
}
const testFiles = []
const jsTestFiles = []
if (filenames.length > 0) {
filenames.forEach(file => {
const isTsTestFile = minimatch(file, '{test/**/*.ts,src/**/*.spec.ts}', { matchBase: true })
if (isTsTestFile) {
testFiles.push(file)
const extension = commonjs ? 'cjs' : 'js'
jsTestFiles.push(`${mochaTsRelativeDir}/${file.slice(0, -3)}.${extension}`)
}
})
}
mochaArgs.push(...jsTestFiles)
return {
mochaArgs,
testFiles,
commonjs
}
}
const processedArgs = parse()
const commonjs = processedArgs.commonjs
const testFiles = processedArgs.testFiles
const mochaArgs = processedArgs.mochaArgs
// prepare setup for mocha (it should be written to a JSON file that will be loaded by the mocha-init.cjs)
const mochaSetup = {
testFiles,
commonjs
}
fs.writeFileSync(path.join(tempDir, 'testSetup.json'), JSON.stringify(mochaSetup, undefined, 2), { encoding: 'utf-8' })
if (commonjs) {
console.log('\x1b[33m [mocha-ts] Running tests against the CommonJS module \x1b[0m\n')
} else {
console.log('\x1b[33m [mocha-ts] Running tests against the ESM module \x1b[0m\n')
}
const rollupBuilder = require('../testing/mocha/builders/RollupBuilder.cjs').rollupBuilder
rollupBuilder.start({ commonjs, watch: false }).then(() => {
rollupBuilder.close()
const testsBuilder = require('../testing/mocha/builders/TestsBuilder.cjs').testBuilder
testsBuilder.start({ commonjs, testFiles }).then(() => {
testsBuilder.close()
// Now run mocha
runScript(path.join(rootDir, 'node_modules/mocha/bin/mocha'), mochaArgs)
})
})
function getBooleanOption (args, ...optionNames) {
let found = false
optionNames.forEach((option) => {
const index = args.indexOf(option)
if (index > -1) {
found = true
args.splice(index, 1)
}
})
return found
}
function getOption (args, option) {
const index = args.indexOf(option)
if (index > -1 && index < args.length - 2) {
return args.splice(index, 2)[1]
}
return ''
}

View File

@ -1,204 +0,0 @@
'use strict'
const fs = require('fs')
const TypeDoc = require('typedoc')
const path = require('path')
const json5 = require('json5')
const pkgJson = require('../package.json')
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) {
return w.toUpperCase()
})
}
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']
fs.writeFileSync(tempTsConfigPath, JSON.stringify(tsConfig, undefined, 2))
// If you want TypeDoc to load tsconfig.json / typedoc.json files
app.options.addReader(new TypeDoc.TSConfigReader())
// app.options.addReader(new TypeDoc.TypeDocReader())
app.bootstrap({
// typedoc options here
tsconfig: tempTsConfigPath,
entryPoints: ['src/ts/index.ts'],
plugin: ['typedoc-plugin-markdown'],
includeVersion: true,
entryDocument: 'API.md',
readme: 'none',
hideBreadcrumbs: true,
excludePrivate: true
})
const project = app.convert()
if (project) {
// Project may not have converted correctly
const output = path.join(rootDir, './docs')
// 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') {
ret = {
repoProvider,
repoUsername: repodata[1],
repoName: repodata.slice(2).join('/')
}
}
} 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)
ret = {
repoProvider: match[1],
repoUsername: match[2],
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
}
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 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 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 = 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 = 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
}
}
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\}\}\n/gs, (workflowBadge ? `${workflowBadge}\n` : '') + (coverallsBadge ? `${coverallsBadge}\n` : ''))
} else {
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}\n/gs, '')
}
}
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,52 +0,0 @@
import { mkdirSync, writeFileSync } from 'fs'
import ts from 'typescript'
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
const rootDir = join(__dirname, '..')
const srcFile = join(rootDir, 'src/ts/index.ts')
const tsConfigPath = join(rootDir, 'tsconfig.json')
const configFile = readJsonConfigFile(tsConfigPath, (file) => {
return sys.readFile(file)
})
const tsConfig = parseJsonSourceFileConfigFileContent(configFile, sys, dirname(tsConfigPath))
export const compile = (outDir) => {
const compilerOptions = {
...tsConfig.options,
removeComments: false,
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)
}
// Clear the types dir
sync(outDir)
// Prepare and emit the d.ts files
const program = createProgram([srcFile], compilerOptions, host)
program.emit()
}

View File

@ -1,243 +0,0 @@
'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 rollupPluginTs from '@rollup/plugin-typescript'
import { existsSync, readFileSync } from 'fs'
import { builtinModules } from 'module'
import { join } from 'path'
import dts from 'rollup-plugin-dts'
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 pkgJson = JSON.parse(readFileSync(join(rootDir, 'package.json')))
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) {
return w.toUpperCase()
})
}
function isDevDependency (moduleName) {
const packageEntry = pkgJsonLock.packages['node_modules/' + moduleName]
return (packageEntry ?? {}).dev === true
}
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 pkgCamelisedName = camelise(name)
const input = join(srcDir, 'index.ts')
if (existsSync(input) !== true) throw new Error('The entry point should be index.ts')
const tsPluginOptions = {
tsconfig: tsConfigPath,
outDir: undefined,
include: ['src/ts/**/*', 'build/typings/**/*.d.ts'],
exclude: ['src/**/*.spec.ts']
}
const sourcemapOutputOptions = {
sourcemap: 'inline',
sourcemapExcludeSources: true
}
function compileDts (outDir) {
return {
name: 'compile-dts',
closeBundle () {
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
input,
output: [
{
file: join(rootDir, pkgJson.exports['.'].default.default),
...sourcemapOutputOptions,
format: 'es',
plugins: [
terser()
]
}
],
plugins: [
replace({
IS_BROWSER: true,
environment: 'browser',
_MODULE_TYPE: "'ESM'",
_NPM_PKG_VERSION: `'${process.env.npm_package_version}'` ?? "'0.0.1'",
preventAssignment: true
}),
rollupPluginTs(tsPluginOptions),
commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }),
json(),
resolve({
browser: true,
exportConditions: ['browser', 'default'],
mainFields: ['browser', 'module', 'main'],
resolveOnly
})
]
},
{ // Browser bundles
input,
output: [
{
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(rootDir, pkgJson.exports['./umd-browser-bundle']),
format: 'umd',
name: pkgCamelisedName,
plugins: [terser()]
}
],
plugins: [
replace({
IS_BROWSER: true,
environment: 'browser',
_MODULE_TYPE: "'BUNDLE'",
_NPM_PKG_VERSION: `'${process.env.npm_package_version}'` ?? "'0.0.1'",
preventAssignment: true
}),
rollupPluginTs({
...tsPluginOptions,
sourceMap: false
}),
commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }),
json(),
resolve({ browser: true })
]
},
{ // Node CJS
input,
output: [
{
file: join(rootDir, pkgJson.exports['.'].node.require.default),
...sourcemapOutputOptions,
format: 'cjs',
exports: 'auto',
interop: 'auto',
dynamicImportInCjs: false,
plugins: [terser()]
}
],
plugins: [
replace({
IS_BROWSER: false,
environment: 'nodejs',
_MODULE_TYPE: "'CJS'",
_NPM_PKG_VERSION: `'${process.env.npm_package_version}'` ?? "'0.0.1'",
preventAssignment: true
}),
rollupPluginTs(tsPluginOptions),
inject({
crypto: ['crypto', 'webcrypto']
}),
commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }),
json(),
resolve({
exportConditions: ['node'],
resolveOnly
})
]
},
{ // 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,
environment: 'nodejs',
_MODULE_TYPE: "'ESM'",
_NPM_PKG_VERSION: `'${process.env.npm_package_version}'` ?? "'0.0.1'",
__filename: 'fileURLToPath(import.meta.url)',
__dirname: 'fileURLToPath(new URL(\'.\', import.meta.url))',
preventAssignment: true
}),
rollupPluginTs(tsPluginOptions),
compileDts(tmpDeclarationsDir),
inject({
crypto: ['crypto', 'webcrypto'],
fileURLToPath: ['url', 'fileURLToPath']
}),
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)
}
}
]

View File

@ -1,26 +0,0 @@
const childProcess = require('child_process')
const rootDir = require('path').join(__dirname, '../')
function runScript (scriptPath, args) {
return new Promise((resolve, reject) => {
const cmd = childProcess.fork(scriptPath, args, {
cwd: rootDir
})
cmd.on('error', (error) => {
reject(error)
})
// execute the callback once the process has finished running
cmd.on('exit', function (code) {
if (code !== 0) {
const error = new Error('exit code ' + code)
reject(error)
}
resolve()
})
})
}
module.exports = runScript

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

View File

@ -1,120 +0,0 @@
const path = require('path')
const puppeteer = require('puppeteer')
const minimatch = require('minimatch').minimatch
const glob = require('glob')
const rootDir = path.join(__dirname, '../../..')
const pkgJson = require(path.join(rootDir, 'package.json'))
const browserTests = async (
{
logWarnings = false,
serverPort = 38000,
keepServerRunning = false,
puppeteerOptions = {
headless: false,
devtools: true
}
}, testFiles) => {
const server = require('./server.cjs').server
await server.init(testFiles)
await server.listen(serverPort)
const browser = await puppeteer.launch(puppeteerOptions)
const page = (await browser.pages())[0]
page.on('console', function (message) {
const ignore = message.type() === 'warning' && !logWarnings
if (ignore) return
let text = (message.args().length > 0) ? message.args()[0].remoteObject().value : message.text()
const args = []
if (message.args() !== undefined && message.args().length > 1) {
for (let i = 1; i < message.args().length; i++) {
args.push(message.args()[i].remoteObject().value)
}
}
if (message.type() === 'error' && message.location()) {
text = `${message.location().url} : ${text}`
}
let consoleType = 'log'
switch (message.type()) {
case 'error':
consoleType = 'error'
break
case 'warning':
consoleType = 'warn'
break
default:
break
}
console[consoleType](text, ...args)
})
page.on('error', function (err) { page.emit(new Error(err)) })
page.on('close', async () => {
await close()
})
page.goto('http://localhost:38000/').then(async () => {
const watchDog = page.waitForFunction('_mocha.state === \'stopped\'', { timeout: 0 })
await watchDog.catch(async (reason) => {
console.error(reason)
})
if (puppeteerOptions.headless === 'new') {
await close()
}
}).catch(async (reason) => {
console.error(reason)
})
async function close () {
console.log('Closing browser tests...')
await browser.close().catch(() => {})
if (keepServerRunning !== true) {
await server.close().catch(() => {})
}
}
}
function processedTestFiles (testFilesStr) {
if (testFilesStr === 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) {
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) {
throw new Error(`test file '${file}' not found`)
}
})
}
return filenames
}
const opts = {
// puppeteer options
puppeteerOptions: {
headless: false,
devtools: true,
// slowMo: 100,
timeout: 0
},
logWarnings: false, // log warnings in Node console (usually not needed)
keepServerRunning: false, // keep server running until manually closed with ctrl-c. In combination with puppeteerOptions.headless (or just connecting any browser to the test page) allows debugging in browser
serverPort: 38000
}
const args = process.argv.slice(2)
if (args[0] === 'headless') {
opts.puppeteerOptions.headless = 'new'
args.shift()
}
browserTests(opts, processedTestFiles(args[0]))

View File

@ -1,211 +0,0 @@
'use strict'
const fs = require('fs')
const http = require('http')
const path = require('path')
const pkgJson = require('../../../package.json')
require('dotenv').config()
const rollup = require('rollup')
const resolve = require('@rollup/plugin-node-resolve').nodeResolve
const replace = require('@rollup/plugin-replace')
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, '..', '..', '..')
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 indexHtml = `<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${name}</title>
<script src="/mocha.js"></script>
<script src="/chai.js"></script>
</head>
<body>
</body>
<div id="mocha"></div>
<script>
mocha.setup({
ui: 'bdd',
reporter: 'spec',
color: 'true',
timeout: 90000
})
</script>
<script type="module">
import './tests.js'
window._mocha = mocha.run()
</script>
</html>`
const tsBundleOptions = {
tsconfig: path.join(rootDir, 'tsconfig.json'),
outDir: undefined, // ignore outDir in tsconfig.json
sourceMap: false
// include: ['src/ts/**/*', 'build/typings/**/*.d.ts']
}
async function buildTests (testFiles) {
// create a bundle
const inputOptions = {
input: testFiles,
plugins: [
multi(),
replace({
IS_BROWSER: true,
_MODULE_TYPE: "'ESM'",
_NPM_PKG_VERSION: `'${process.env.npm_package_version}'` ?? "'0.0.1'",
preventAssignment: true
}),
typescriptPlugin(tsBundleOptions),
commonjs({ extensions: ['.js', '.cjs', '.jsx', '.cjsx'] }),
json(),
resolve({ browser: true }),
replace({
'#pkg': `/${name}.esm.js`,
delimiters: ['', ''],
preventAssignment: true
})
],
external: [`/${name}.esm.js`]
}
const bundle = await rollup.rollup(inputOptions)
const { output } = await bundle.generate({ format: 'es' })
await bundle.close()
let bundledCode = output[0].code
const replacements = _getEnvVarsReplacements(bundledCode)
for (const replacement in replacements) {
const regExp = new RegExp(replacement, 'g')
bundledCode = bundledCode.replace(regExp, replacements[replacement])
}
return bundledCode
}
class TestServer {
constructor () {
this.server = http.createServer()
}
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-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-nomin']), 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 === '/index.html' || req.url === '/') {
res.writeHead(200)
res.end(indexHtml)
} else if (req.url === '/tests.js') {
res.writeHead(200, { 'Content-Type': 'text/javascript' })
res.end(tests)
} else if (req.url === '/mocha.js') {
fs.readFile(path.join(rootDir, 'node_modules/mocha/mocha.js'), 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 === '/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) {
res.writeHead(404)
res.end(JSON.stringify(err))
return
}
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()
}
})
}
listen (port = 38080) {
return new Promise((resolve, reject) => {
this.server.listen(port, error => {
if (error) return reject(error)
console.log(`Testing server listenning at http://localhost:${port}`)
return resolve()
})
})
}
close () {
return new Promise((resolve, reject) => {
this.server.close(error => (error) ? reject(error) : resolve())
})
}
}
function _getEnvVarsReplacements (testsCode) {
const replacements = {}
const missingEnvVars = []
for (const match of testsCode.matchAll(/process\.env\.(\w+)/g)) {
const envVar = match[1]
if (process.env[envVar] !== undefined) {
replacements[match[0]] = '`' + process.env[envVar] + '`'
} else {
replacements[match[0]] = undefined
}
}
for (const match of testsCode.matchAll(/process\.env\[['"](\w+)['"]\]/g)) {
const envVar = match[1]
if (process.env[envVar] !== undefined) {
replacements[match[0]] = '`' + process.env[envVar] + '`'
} else {
replacements[match[0]] = undefined
}
}
if (missingEnvVars.length > 0) {
console.warn('The following environment variables are missing in your .env file and will be replaced with "undefined": ' + [...(new Set(missingEnvVars)).values()].join(', '))
}
return replacements
}
exports.server = new TestServer()

View File

@ -1,62 +0,0 @@
const EventEmitter = require('events')
const fs = require('fs')
const path = require('path')
module.exports = class Builder extends EventEmitter {
constructor (semaphoreFile, name = 'builder') {
super()
this.name = name
fs.mkdirSync(path.dirname(semaphoreFile), { recursive: true })
this.semaphoreFile = semaphoreFile
if (!fs.existsSync(this.semaphoreFile)) {
fs.writeFileSync(this.semaphoreFile, '', { encoding: 'utf8' })
}
this._ready = false
this.on('message', (...message) => {
if (message !== undefined) {
console.log(`\x1b[33m [${this.name}]`, ...message, '\x1b[0m')
}
})
this.on('error', (...error) => {
if (error !== undefined) {
console.error(`\x1b[31m❗ [${this.name}]`, ...error, '\x1b[0m')
}
})
this.on('ready', (updateSemaphore = true) => {
const now = Date.now()
if (updateSemaphore) {
fs.utimesSync(this.semaphoreFile, now, now)
}
this._ready = true
})
this.on('busy', () => {
this._ready = false
})
}
ready () {
return new Promise(resolve => {
if (this._ready === true) return resolve()
this.once('ready', () => {
resolve()
})
})
}
async start () {
}
async close () {}
clean () {
fs.rmSync(this.semaphoreFile, { force: true })
}
}

View File

@ -1,154 +0,0 @@
const EventEmitter = require('events')
const fs = require('fs')
const path = require('path')
const rollup = require('rollup')
const loadAndParseConfigFile = require('rollup/loadConfigFile').loadConfigFile
const Builder = require('./Builder.cjs')
const rootDir = path.join(__dirname, '../../../../')
const pkgJson = require(path.join(rootDir, 'package.json'))
const mochaTsRelativeDir = pkgJson.directories['mocha-ts']
const mochaTsDir = path.join(rootDir, mochaTsRelativeDir)
class RollupBuilder extends Builder {
constructor ({ name, configPath, tempDir }) {
super(path.join(tempDir, 'semaphore'), name)
this.tempDir = tempDir
this.configPath = configPath
this.firstBuild = true
}
async start ({ watch = false, commonjs = false }) {
await super.start()
this.watch = watch
this.commonjs = commonjs
this.watchedModule = commonjs ? pkgJson.exports['.'].node.require.default : pkgJson.exports['.'].node.import.default
const { options } = await loadAndParseConfigFile(this.configPath)
// Instead of compiling all the outputs let us just take the one we are using with mocha (either cjs or esm)
const rollupOptions = options.filter(bundle => {
const file = (bundle.output[0].dir !== undefined)
? path.join(bundle.output[0].dir, bundle.output[0].entryFileNames)
: bundle.output[0].file
return file === path.join(rootDir, this.watchedModule)
})[0]
if (rollupOptions.output.length > 1) {
rollupOptions.output = rollupOptions.output[0]
}
this.builder = new RollupBundler({ rollupOptions, watch: this.watch, watchedModule: this.watchedModule })
this.builder.on('event', event => {
let updateSemaphore = true
switch (event.code) {
case 'START':
this.emit('busy')
if (this.firstBuild === true) {
this.emit('message', 'building your module...')
} else {
this.emit('message', 'file changes detected. Rebuilding module files...')
}
break
case 'BUNDLE_END':
if (event.result) event.result.close()
break
case 'END':
if (event.result) event.result.close()
// fs.mkdirSync(path.join(this.tempDir, path.dirname(this.watchedModule)), { recursive: true })
// // console.log(path.join(this.tempDir, path.dirname(this.watchedModule)))
// fs.copyFileSync(this.watchedModule, path.join(this.tempDir, this.watchedModule))
if (this.firstBuild) {
this.firstBuild = false
updateSemaphore = false
}
this.emit('ready', updateSemaphore)
break
case 'ERROR':
if (event.result) event.result.close()
this.emit('error', event.error)
fs.writeFileSync(path.join(rootDir, this.watchedModule), '', 'utf8')
// fs.writeFileSync(path.join(this.tempDir, this.watchedModule), '', 'utf8')
this.emit('ready')
break
default:
this.emit('busy')
break
}
})
this.builder.start()
return await this.ready()
}
async close () {
await super.close()
this.builder.close()
}
}
class RollupBundler extends EventEmitter {
constructor ({ rollupOptions, watchedModule, watch = false }) {
super()
this.rollupOptions = rollupOptions
this.watch = watch
this.watchedModule = watchedModule
}
async start () {
if (this.watch === true) {
this.watcher = rollup.watch(this.rollupOptions)
this.watcher.on('event', event => {
this.emit('event', event)
})
} else {
if (!fs.existsSync(path.join(rootDir, this.watchedModule))) {
await this._bundle()
} else {
this.emit('event', { code: 'END', noBuild: true })
}
}
}
async _bundle () {
this.emit('event', { code: 'START' })
for (const optionsObj of [].concat(this.rollupOptions)) {
try {
const bundle = await rollup.rollup(optionsObj)
try {
await Promise.all(optionsObj.output.map(bundle.write))
this.emit('event', { code: 'BUNDLE_END' })
} catch (error) {
this.emit('event', { code: 'ERROR', error })
}
} catch (error) {
this.emit('event', { code: 'ERROR', error })
}
}
this.emit('event', { code: 'END' })
}
close () {
if (this.watcher !== undefined) this.watcher.close()
}
}
exports.RollupBuilder = RollupBuilder
exports.rollupBuilder = new RollupBuilder({
name: 'rollup',
configPath: path.join(rootDir, pkgJson.directories.build, 'rollup.config.js'),
tempDir: mochaTsDir
})

View File

@ -1,194 +0,0 @@
const path = require('path')
const fs = require('fs')
const ts = require('typescript')
const json5 = require('json5')
const Builder = require('./Builder.cjs')
const rootDir = path.join(__dirname, '../../../../')
const pkgJson = require(path.join(rootDir, 'package.json'))
const mochaTsRelativeDir = pkgJson.directories['mocha-ts']
const mochaTsDir = path.join(rootDir, mochaTsRelativeDir)
const formatHost = {
getCanonicalFileName: path => path,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: () => ts.sys.newLine
}
function fileChecksum (filePath) {
return require('crypto')
.createHash('md5')
.update(fs.readFileSync(filePath, { encoding: 'utf-8' }), 'utf8')
.digest('hex')
}
function renameJsToCjs (dir, fileList = []) {
const files = fs.readdirSync(dir)
files.forEach(file => {
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]
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' })
}
}
})
}
class TestsBuilder extends Builder {
constructor ({ name, configPath, tempDir }) {
super(path.join(tempDir, 'semaphore'), name)
this.tempDir = tempDir
if (fs.existsSync(configPath) !== true) throw new Error(`Couldn't find a tsconfig file at ${configPath}`)
this.tsConfigPath = configPath
this.testFilesChecksums = {}
}
async start ({ testFiles = [], commonjs = false }) {
await super.start()
this.commonjs = commonjs
const tsConfig = json5.parse(fs.readFileSync(this.tsConfigPath, 'utf8'))
if (testFiles.length > 0) {
delete tsConfig.files
tsConfig.include = ['build/typings/**/*.d.ts'].concat(testFiles)
for (let i = 0; i < testFiles.length; i++) {
this.testFilesChecksums[testFiles[i]] = fileChecksum(testFiles[i])
}
} else {
tsConfig.include = ['build/typings/**/*.d.ts', 'test/**/*', 'src/ts/**/*.spec.ts']
}
tsConfig.exclude = ['src/ts/**/!(.spec).ts']
if (this.commonjs) {
tsConfig.compilerOptions.module = 'commonjs'
}
// "noResolve": true
// tsConfig.compilerOptions.noResolve = true
// we don't need declaration files
tsConfig.compilerOptions.declaration = false
// we need to emit files
tsConfig.compilerOptions.noEmit = false
// source mapping eases debuging
tsConfig.compilerOptions.inlineSourceMap = true
tsConfig.compilerOptions.rootDir = '.'
// Removed typeroots (it causes issues)
tsConfig.compilerOptions.typeRoots = undefined
tsConfig.compilerOptions.outDir = path.isAbsolute(this.tempDir) ? path.relative(rootDir, this.tempDir) : this.tempDir
this.tempTsConfigPath = path.join(rootDir, '.tsconfig.json')
fs.writeFileSync(this.tempTsConfigPath, JSON.stringify(tsConfig, undefined, 2), { encoding: 'utf-8' })
const createProgram = ts.createSemanticDiagnosticsBuilderProgram
const reportDiagnostic = (diagnostic) => {
const filePath = path.relative(rootDir, diagnostic.file.fileName)
const tranpiledJsPath = `${path.join(this.tempDir, filePath).slice(0, -3)}.js`
const errorLine = diagnostic.file.text.slice(0, diagnostic.start).split(/\r\n|\r|\n/).length
if (fs.existsSync(tranpiledJsPath)) {
fs.writeFileSync(tranpiledJsPath, '', 'utf8')
}
this.emit('error', `[Error ${diagnostic.code}]`, `${filePath}:${errorLine}`, ':', ts.flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine()))
}
const reportWatchStatusChanged = (diagnostic, newLine, options, errorCount) => {
if (errorCount !== undefined) {
// only change semaphore if test files are modified
let updateSemaphore = false
for (let i = 0; i < testFiles.length; i++) {
const checksum = fileChecksum(testFiles[i])
if (this.testFilesChecksums[testFiles[i]] !== checksum) {
updateSemaphore = true
this.testFilesChecksums[testFiles[i]] = checksum
}
}
if (this.commonjs) {
renameJsToCjs(mochaTsDir)
} else {
fixJsonAssertsInESMTests(mochaTsDir)
}
this.emit('ready', updateSemaphore)
} else {
this.emit('busy')
if (diagnostic.code === 6031) {
this.emit('message', 'transpiling your tests...')
} else if (diagnostic.code === 6032) {
this.emit('message', 'file changes detected. Transpiling your tests...')
}
}
}
// Note that there is another overload for `createWatchCompilerHost` that takes
// a set of root files.
this.host = ts.createWatchCompilerHost(
this.tempTsConfigPath,
{},
ts.sys,
createProgram,
reportDiagnostic,
reportWatchStatusChanged
)
// `createWatchProgram` creates an initial program, watches files, and updates
// the program over time.
this.watcher = ts.createWatchProgram(this.host)
this.watcher.getProgram()
return await this.ready()
}
async close () {
await super.close()
this.watcher.close()
fs.unlinkSync(this.tempTsConfigPath)
}
}
exports.TestsBuilder = TestsBuilder
exports.testBuilder = new TestsBuilder({
name: 'tsc',
configPath: path.join(rootDir, 'tsconfig.json'),
tempDir: mochaTsDir
})

View File

@ -1,68 +0,0 @@
'use strict'
const fs = require('fs')
const path = require('path')
const chai = require('chai')
const rimraf = require('rimraf')
require('dotenv').config()
const rollupBuilder = require('./builders/RollupBuilder.cjs').rollupBuilder
const testsBuilder = require('./builders/TestsBuilder.cjs').testBuilder
const rootDir = path.join(__dirname, '../../../')
const pkgJson = require(path.join(rootDir, 'package.json'))
const mochaTsRelativeDir = pkgJson.directories['mocha-ts']
const tempDir = path.join(rootDir, mochaTsRelativeDir)
global.chai = chai
global.IS_BROWSER = false
const watch = process.argv.includes('--watch') || process.argv.includes('-w')
const setup = JSON.parse(fs.readFileSync(path.join(tempDir, 'testSetup.json'), 'utf-8'))
const testFiles = setup.testFiles
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 })
testsBuilder.start({ testFiles, commonjs })
}
}
exports.mochaHooks = {
beforeAll: [
async function () {
this.timeout('120000')
if (watch) {
await Promise.all([rollupBuilder.ready(), testsBuilder.ready()])
// reset any transpiled module (just delete the cache so it is fully reloaded)
for (const key in require.cache) {
const relativePath = path.relative(rootDir, key)
if (relativePath.startsWith(`.mocha-ts${path.sep}`) || relativePath.startsWith(`dist${path.sep}`)) {
delete require.cache[key]
}
}
}
}
]
}
exports.mochaGlobalTeardown = async function () {
if (watch) {
await testsBuilder.close()
await rollupBuilder.close()
}
// I use the sync version of rimraf precisely because it blocks the
// main thread and thus the mocha watcher, which otherwise would complain
// about files being deleted
rimraf.sync(tempDir, { disableGlob: true })
}

View File

@ -1,3 +0,0 @@
declare const IS_BROWSER: boolean
declare const _MODULE_TYPE: string
declare const _NPM_PKG_VERSION: string

210
dist/bundle.esm.js vendored
View File

@ -1,210 +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 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 crt(remainders, modulos, modulo) {
if (remainders.length !== modulos.length) {
throw new RangeError('The remainders and modulos arrays should have the same length');
}
const product = modulo ?? modulos.reduce((acc, val) => acc * val, 1n);
return modulos.reduce((sum, mod, index) => {
const partialProduct = product / mod;
const inverse = modInv(partialProduct, mod);
const toAdd = ((partialProduct * inverse) % product * remainders[index]) % product;
return toZn(sum + toAdd, product);
}, 0n);
}
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 modAdd(addends, n) {
const mod = BigInt(n);
const as = addends.map(a => BigInt(a) % mod);
return toZn(as.reduce((sum, a) => sum + a % mod, 0n), mod);
}
function modMultiply(factors, n) {
const mod = BigInt(n);
const as = factors.map(a => BigInt(a) % mod);
return toZn(as.reduce((prod, a) => prod * a % mod, 1n), mod);
}
function phi(primeFactorization) {
return primeFactorization.map(v => (v[0] ** (v[1] - 1n)) * (v[0] - 1n)).reduce((prev, curr) => {
return curr * prev;
}, 1n);
}
function modPow(b, e, n, primeFactorization) {
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, primeFactorization), n);
}
if (primeFactorization !== undefined) {
return modPowWithFactorization(b, e, n, primePowerArguments(primeFactorization));
}
let r = 1n;
while (e > 0) {
if ((e % 2n) === 1n) {
r = r * b % n;
}
e = e / 2n;
b = b ** 2n % n;
}
return r;
}
function primePowerArguments(primeFactors) {
const primePowers = {};
primeFactors.forEach((primeFactor) => {
if (typeof primeFactor === 'bigint' || typeof primeFactor === 'number') {
const key = String(primeFactor);
if (primePowers[key] === undefined) {
primePowers[key] = { p: BigInt(primeFactor), k: 1n };
}
else {
primePowers[key].k += 1n;
}
}
else {
const key = String(primeFactor[0]);
if (primePowers[key] === undefined) {
primePowers[key] = { p: BigInt(primeFactor[0]), k: BigInt(primeFactor[1]) };
}
else {
primePowers[key].k += BigInt(primeFactor[1]);
}
}
});
return Object.values(primePowers).map(val => [val.p, val.k]);
}
function modPowWithFactorization(b, e, n, primeFactorization) {
const mods = primeFactorization.map(v => v[0] ** v[1]);
const phis = primeFactorization.map(v => phi([v]));
const remainders = phis.map((phi, i) => modPow(b, e % phi, mods[i]));
return crt(remainders, mods, n);
}
export { abs, bitLength, crt, eGcd, gcd, lcm, max, min, modAdd, modInv, modMultiply, modPow, phi, toZn };

View File

@ -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,i=0n;for(;0n!==n;){const u=t/n,f=t%n,g=r-o*u,c=e-i*u;t=n,n=f,r=o,e=i,o=g,i=c}return{g:t,x:r,y:e}}function e(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 o(n,t){const o=r(e(n,t),t);if(1n!==o.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return e(o.x,t)}function i(n,t,r){if(n.length!==t.length)throw new RangeError("The remainders and modulos arrays should have the same length");const i=r??t.reduce(((n,t)=>n*t),1n);return t.reduce(((t,r,u)=>{const f=i/r;return e(t+f*o(f,r)%i*n[u]%i,i)}),0n)}function u(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<<i}function f(t,r){return"number"==typeof t&&(t=BigInt(t)),"number"==typeof r&&(r=BigInt(r)),0n===t&&0n===r?BigInt(0):n(t/u(t,r)*r)}function g(n,t){return n>=t?n:t}function c(n,t){return n>=t?t:n}function m(n,t){const r=BigInt(t);return e(n.map((n=>BigInt(n)%r)).reduce(((n,t)=>n+t%r),0n),r)}function p(n,t){const r=BigInt(t);return e(n.map((n=>BigInt(n)%r)).reduce(((n,t)=>n*t%r),1n),r)}function a(n){return n.map((n=>n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function s(t,r,u,f){if("number"==typeof t&&(t=BigInt(t)),"number"==typeof r&&(r=BigInt(r)),"number"==typeof u&&(u=BigInt(u)),u<=0n)throw new RangeError("n must be > 0");if(1n===u)return 0n;if(t=e(t,u),r<0n)return o(s(t,n(r),u,f),u);if(void 0!==f)return function(n,t,r,e){const o=e.map((n=>n[0]**n[1])),u=e.map((n=>a([n]))),f=u.map(((r,e)=>s(n,t%r,o[e])));return i(f,o,r)}(t,r,u,function(n){const t={};return n.forEach((n=>{if("bigint"==typeof n||"number"==typeof n){const r=String(n);void 0===t[r]?t[r]={p:BigInt(n),k:1n}:t[r].k+=1n}else{const r=String(n[0]);void 0===t[r]?t[r]={p:BigInt(n[0]),k:BigInt(n[1])}:t[r].k+=BigInt(n[1])}})),Object.values(t).map((n=>[n.p,n.k]))}(f));let g=1n;for(;r>0;)r%2n===1n&&(g=g*t%u),r/=2n,t=t**2n%u;return g}export{n as abs,t as bitLength,i as crt,r as eGcd,u as gcd,f as lcm,g as max,c as min,m as modAdd,o as modInv,p as modMultiply,s as modPow,a as phi,e as toZn};

1
dist/bundle.iife.js vendored
View File

@ -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,c=r-o*u,g=e-i*u;t=n,n=f,r=o,e=i,o=c,i=g}return{g:t,x:r,y:e}}function e(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 o(n,t){const o=r(e(n,t),t);if(1n!==o.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return e(o.x,t)}function i(n,t,r){if(n.length!==t.length)throw new RangeError("The remainders and modulos arrays should have the same length");const i=r??t.reduce(((n,t)=>n*t),1n);return t.reduce(((t,r,u)=>{const f=i/r;return e(t+f*o(f,r)%i*n[u]%i,i)}),0n)}function u(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 f(n){return n.map((n=>n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function c(n,r,u,g){if("number"==typeof n&&(n=BigInt(n)),"number"==typeof r&&(r=BigInt(r)),"number"==typeof u&&(u=BigInt(u)),u<=0n)throw new RangeError("n must be > 0");if(1n===u)return 0n;if(n=e(n,u),r<0n)return o(c(n,t(r),u,g),u);if(void 0!==g)return function(n,t,r,e){const o=e.map((n=>n[0]**n[1])),u=e.map((n=>f([n]))),g=u.map(((r,e)=>c(n,t%r,o[e])));return i(g,o,r)}(n,r,u,function(n){const t={};return n.forEach((n=>{if("bigint"==typeof n||"number"==typeof n){const r=String(n);void 0===t[r]?t[r]={p:BigInt(n),k:1n}:t[r].k+=1n}else{const r=String(n[0]);void 0===t[r]?t[r]={p:BigInt(n[0]),k:BigInt(n[1])}:t[r].k+=BigInt(n[1])}})),Object.values(t).map((n=>[n.p,n.k]))}(g));let m=1n;for(;r>0;)r%2n===1n&&(m=m*n%u),r/=2n,n=n**2n%u;return m}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.crt=i,n.eGcd=r,n.gcd=u,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/u(n,r)*r)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modAdd=function(n,t){const r=BigInt(t);return e(n.map((n=>BigInt(n)%r)).reduce(((n,t)=>n+t%r),0n),r)},n.modInv=o,n.modMultiply=function(n,t){const r=BigInt(t);return e(n.map((n=>BigInt(n)%r)).reduce(((n,t)=>n*t%r),1n),r)},n.modPow=c,n.phi=f,n.toZn=e,n}({});

1
dist/bundle.umd.js vendored
View File

@ -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 u=t/n,f=t%n,c=e-o*u,g=r-i*u;t=n,n=f,e=o,r=i,o=c,i=g}return{g:t,x:e,y:r}}function r(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 o(n,t){const o=e(r(n,t),t);if(1n!==o.g)throw new RangeError(`${n.toString()} does not have inverse modulo ${t.toString()}`);return r(o.x,t)}function i(n,t,e){if(n.length!==t.length)throw new RangeError("The remainders and modulos arrays should have the same length");const i=e??t.reduce(((n,t)=>n*t),1n);return t.reduce(((t,e,u)=>{const f=i/e;return r(t+f*o(f,e)%i*n[u]%i,i)}),0n)}function u(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 f(n){return n.map((n=>n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}function c(n,e,u,g){if("number"==typeof n&&(n=BigInt(n)),"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(n=r(n,u),e<0n)return o(c(n,t(e),u,g),u);if(void 0!==g)return function(n,t,e,r){const o=r.map((n=>n[0]**n[1])),u=r.map((n=>f([n]))),g=u.map(((e,r)=>c(n,t%e,o[r])));return i(g,o,e)}(n,e,u,function(n){const t={};return n.forEach((n=>{if("bigint"==typeof n||"number"==typeof n){const e=String(n);void 0===t[e]?t[e]={p:BigInt(n),k:1n}:t[e].k+=1n}else{const e=String(n[0]);void 0===t[e]?t[e]={p:BigInt(n[0]),k:BigInt(n[1])}:t[e].k+=BigInt(n[1])}})),Object.values(t).map((n=>[n.p,n.k]))}(g));let d=1n;for(;e>0;)e%2n===1n&&(d=d*n%u),e/=2n,n=n**2n%u;return d}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.crt=i,n.eGcd=e,n.gcd=u,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/u(n,e)*e)},n.max=function(n,t){return n>=t?n:t},n.min=function(n,t){return n>=t?t:n},n.modAdd=function(n,t){const e=BigInt(t);return r(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n+t%e),0n),e)},n.modInv=o,n.modMultiply=function(n,t){const e=BigInt(t);return r(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n*t%e),1n),e)},n.modPow=c,n.phi=f,n.toZn=r}));

File diff suppressed because one or more lines are too long

157
dist/index.d.ts vendored
View File

@ -1,157 +0,0 @@
/**
* Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
*
* @param a
*
* @returns The absolute value of a
*/
declare function abs(a: number | bigint): number | bigint;
/**
* Returns the (minimum) length of a number expressed in bits.
*
* @param a
* @returns The bit length
*/
declare function bitLength(a: number | bigint): number;
/**
* Chinese remainder theorem states that if one knows the remainders of the Euclidean division of an integer n by several integers, then one can determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime (no two divisors share a common factor other than 1). Provided that n_i are pairwise coprime, and a_i any integers, this function returns a solution for the following system of equations:
x a_1 mod n_1
x a_2 mod n_2
x a_k mod n_k
*
* @param remainders the array of remainders a_i. For example [17n, 243n, 344n]
* @param modulos the array of modulos n_i. For example [769n, 2017n, 47701n]
* @param modulo the product of all modulos. Provided here just to save some operations if it is already known
* @returns x
*/
declare function crt(remainders: bigint[], modulos: bigint[], modulo?: bigint): bigint;
interface Egcd {
g: bigint;
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).
*/
declare function eGcd(a: number | bigint, b: number | bigint): Egcd;
/**
* 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
*/
declare function gcd(a: number | bigint, b: number | bigint): bigint;
/**
* 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
*/
declare function lcm(a: number | bigint, b: number | bigint): bigint;
/**
* 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
*/
declare function max(a: number | bigint, b: number | bigint): number | bigint;
/**
* 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
*/
declare function min(a: number | bigint, b: number | bigint): number | bigint;
/**
* Modular addition of (a_1 + ... + a_r) mod n
* @param addends an array of the numbers a_i to add. For example [3, 12353251235n, 1243, -12341232545990n]
* @param n the modulo
* @returns The smallest positive integer that is congruent with (a_1 + ... + a_r) mod n
*/
declare function modAdd(addends: Array<number | bigint>, n: number | bigint): bigint;
/**
* 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
*/
declare function modInv(a: number | bigint, n: number | bigint): bigint;
/**
* Modular addition of (a_1 * ... * a_r) mod n
* @param factors an array of the numbers a_i to multiply. For example [3, 12353251235n, 1243, -12341232545990n]
* @param n the modulo
* @returns The smallest positive integer that is congruent with (a_1 * ... * a_r) mod n
*/
declare function modMultiply(factors: Array<number | bigint>, n: number | bigint): bigint;
type PrimePower = [number | bigint, number | bigint];
type PrimeFactor = number | bigint | PrimePower;
/**
* Modular exponentiation b**e mod n. Currently using the right-to-left binary method if the prime factorization is not provided, or the chinese remainder theorem otherwise.
*
* @param b base
* @param e exponent
* @param n modulo
* @param primeFactorization an array of the prime factors, for example [5n, 5n, 13n, 27n], or prime powers as [p, k], for instance [[5, 2], [13, 1], [27, 1]]. If the prime factorization is provided the chinese remainder theorem is used to greatly speed up the exponentiation.
*
* @throws {@link RangeError} if n <= 0
*
* @returns b**e mod n
*/
declare function modPow(b: number | bigint, e: number | bigint, n: number | bigint, primeFactorization?: PrimeFactor[]): bigint;
type PrimeFactorization = Array<[bigint, bigint]>;
/**
* A function that computes the Euler's totien function of a number n, whose prime power factorization is known
*
* @param primeFactorization an array of arrays containing the prime power factorization of a number n. For example, for n = (p1**k1)*(p2**k2)*...*(pr**kr), one should provide [[p1, k1], [p2, k2], ... , [pr, kr]]
* @returns phi((p1**k1)*(p2**k2)*...*(pr**kr))
*/
declare function phi(primeFactorization: PrimeFactorization): bigint;
/**
* 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
*/
declare function toZn(a: number | bigint, n: number | bigint): bigint;
export { Egcd, PrimeFactor, PrimeFactorization, PrimePower, abs, bitLength, crt, eGcd, gcd, lcm, max, min, modAdd, modInv, modMultiply, modPow, phi, toZn };

2
dist/index.node.cjs vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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.

View File

@ -1,438 +0,0 @@
# bigint-mod-arith - v3.3.1
Some common functions for modular arithmetic using native JS implementation of BigInt
## Table of contents
### Interfaces
- [Egcd](interfaces/Egcd.md)
### Type Aliases
- [PrimeFactor](API.md#primefactor)
- [PrimeFactorization](API.md#primefactorization)
- [PrimePower](API.md#primepower)
### Functions
- [abs](API.md#abs)
- [bitLength](API.md#bitlength)
- [crt](API.md#crt)
- [eGcd](API.md#egcd)
- [gcd](API.md#gcd)
- [lcm](API.md#lcm)
- [max](API.md#max)
- [min](API.md#min)
- [modAdd](API.md#modadd)
- [modInv](API.md#modinv)
- [modMultiply](API.md#modmultiply)
- [modPow](API.md#modpow)
- [phi](API.md#phi)
- [toZn](API.md#tozn)
## Type Aliases
### PrimeFactor
Ƭ **PrimeFactor**: `number` \| `bigint` \| [`PrimePower`](API.md#primepower)
#### Defined in
[modPow.ts:8](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/modPow.ts#L8)
___
### PrimeFactorization
Ƭ **PrimeFactorization**: [`bigint`, `bigint`][]
#### Defined in
[phi.ts:1](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/phi.ts#L1)
___
### PrimePower
Ƭ **PrimePower**: [`number` \| `bigint`, `number` \| `bigint`]
#### Defined in
[modPow.ts:7](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/modPow.ts#L7)
## 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/b365f49/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/b365f49/src/ts/bitLength.ts#L7)
___
### crt
**crt**(`remainders`, `modulos`, `modulo?`): `bigint`
Chinese remainder theorem states that if one knows the remainders of the Euclidean division of an integer n by several integers, then one can determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime (no two divisors share a common factor other than 1). Provided that n_i are pairwise coprime, and a_i any integers, this function returns a solution for the following system of equations:
x ≡ a_1 mod n_1
x ≡ a_2 mod n_2
x ≡ a_k mod n_k
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `remainders` | `bigint`[] | the array of remainders a_i. For example [17n, 243n, 344n] |
| `modulos` | `bigint`[] | the array of modulos n_i. For example [769n, 2017n, 47701n] |
| `modulo?` | `bigint` | the product of all modulos. Provided here just to save some operations if it is already known |
#### Returns
`bigint`
x
#### Defined in
[crt.ts:16](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/crt.ts#L16)
___
### 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/b365f49/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:11](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/gcd.ts#L11)
___
### 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:11](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/lcm.ts#L11)
___
### max
**max**(`a`, `b`): `number` \| `bigint`
Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<b
#### Parameters
| Name | Type |
| :------ | :------ |
| `a` | `number` \| `bigint` |
| `b` | `number` \| `bigint` |
#### Returns
`number` \| `bigint`
Maximum of numbers a and b
#### Defined in
[max.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/max.ts#L9)
___
### min
**min**(`a`, `b`): `number` \| `bigint`
Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<b
#### Parameters
| Name | Type |
| :------ | :------ |
| `a` | `number` \| `bigint` |
| `b` | `number` \| `bigint` |
#### Returns
`number` \| `bigint`
Minimum of numbers a and b
#### Defined in
[min.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/min.ts#L9)
___
### modAdd
**modAdd**(`addends`, `n`): `bigint`
Modular addition of (a_1 + ... + a_r) mod n
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `addends` | (`number` \| `bigint`)[] | an array of the numbers a_i to add. For example [3, 12353251235n, 1243, -12341232545990n] |
| `n` | `number` \| `bigint` | the modulo |
#### Returns
`bigint`
The smallest positive integer that is congruent with (a_1 + ... + a_r) mod n
#### Defined in
[modAdd.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/modAdd.ts#L9)
___
### modInv
**modInv**(`a`, `n`): `bigint`
Modular inverse.
**`Throws`**
RangeError if a does not have inverse modulo n
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | `number` \| `bigint` | The number to find an inverse for |
| `n` | `number` \| `bigint` | The modulo |
#### Returns
`bigint`
The inverse modulo n
#### Defined in
[modInv.ts:14](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/modInv.ts#L14)
___
### modMultiply
**modMultiply**(`factors`, `n`): `bigint`
Modular addition of (a_1 * ... * a_r) mod n
*
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `factors` | (`number` \| `bigint`)[] | an array of the numbers a_i to multiply. For example [3, 12353251235n, 1243, -12341232545990n] * |
| `n` | `number` \| `bigint` | the modulo * |
#### Returns
`bigint`
The smallest positive integer that is congruent with (a_1 * ... * a_r) mod n
#### Defined in
[modMultiply.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/modMultiply.ts#L9)
___
### modPow
**modPow**(`b`, `e`, `n`, `primeFactorization?`): `bigint`
Modular exponentiation b**e mod n. Currently using the right-to-left binary method if the prime factorization is not provided, or the chinese remainder theorem otherwise.
**`Throws`**
RangeError if n <= 0
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `b` | `number` \| `bigint` | base |
| `e` | `number` \| `bigint` | exponent |
| `n` | `number` \| `bigint` | modulo |
| `primeFactorization?` | [`PrimeFactor`](API.md#primefactor)[] | an array of the prime factors, for example [5n, 5n, 13n, 27n], or prime powers as [p, k], for instance [[5, 2], [13, 1], [27, 1]]. If the prime factorization is provided the chinese remainder theorem is used to greatly speed up the exponentiation. |
#### Returns
`bigint`
b**e mod n
#### Defined in
[modPow.ts:22](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/modPow.ts#L22)
___
### phi
**phi**(`primeFactorization`): `bigint`
A function that computes the Euler's totien function of a number n, whose prime power factorization is known
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `primeFactorization` | [`PrimeFactorization`](API.md#primefactorization) | an array of arrays containing the prime power factorization of a number n. For example, for n = (p1**k1)*(p2**k2)*...*(pr**kr), one should provide [[p1, k1], [p2, k2], ... , [pr, kr]] |
#### Returns
`bigint`
phi((p1**k1)*(p2**k2)*...*(pr**kr))
#### Defined in
[phi.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/phi.ts#L9)
___
### toZn
**toZn**(`a`, `n`): `bigint`
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
**`Throws`**
RangeError if n <= 0
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | `number` \| `bigint` | An integer |
| `n` | `number` \| `bigint` | The modulo |
#### Returns
`bigint`
A bigint with the smallest positive representation of a modulo n
#### Defined in
[toZn.ts:14](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/toZn.ts#L14)

View File

@ -1,39 +0,0 @@
# Interface: Egcd
## Table of contents
### Properties
- [g](Egcd.md#g)
- [x](Egcd.md#x)
- [y](Egcd.md#y)
## Properties
### g
**g**: `bigint`
#### Defined in
[egcd.ts:2](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/egcd.ts#L2)
___
### x
**x**: `bigint`
#### Defined in
[egcd.ts:3](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/egcd.ts#L3)
___
### y
**y**: `bigint`
#### Defined in
[egcd.ts:4](https://github.com/juanelas/bigint-mod-arith/blob/b365f49/src/ts/egcd.ts#L4)

19304
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

7069
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,183 +1,50 @@
{
"name": "bigint-mod-arith",
"version": "3.3.1",
"description": "Some common functions for modular arithmetic using native JS implementation of BigInt",
"keywords": [
"modular arithmetics",
"BigInt",
"lcm",
"gcd",
"egcd",
"modinv",
"modular inverse",
"modpow",
"modular exponentiation"
],
"license": "MIT",
"author": {
"name": "Juan Hernández Serrano",
"email": "j.hernandez@upc.edu",
"url": "https://github.com/juanelas"
},
"repository": "github:juanelas/bigint-mod-arith",
"engines": {
"node": ">=10.4.0"
},
"type": "module",
"main": "./dist/index.node.cjs",
"browser": "./dist/index.browser.esm.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"node": {
"module": {
"types": "./dist/index.d.ts",
"default": "./dist/index.node.esm.js"
},
"import": {
"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": {
"types": "./dist/index.d.ts",
"default": "./dist/index.browser.esm.js"
}
},
"./esm-browser-bundle": "./dist/bundle.esm.min.js",
"./dist/bundle.esm.min.js": "./dist/bundle.esm.min.js",
"./esm-browser-bundle-nomin": "./dist/bundle.esm.js",
"./dist/bundle.esm.js": "./dist/bundle.esm.js",
"./iife-browser-bundle": "./dist/bundle.iife.js",
"./dist/bundle.iife.js": "./dist/bundle.iife.js",
"./umd-browser-bundle": "./dist/bundle.umd.js",
"./dist/bundle.umd.js": "./dist/bundle.umd.js",
"./dist/index.node": {
"types": "./dist/index.d.ts",
"default": "./dist/index.node.cjs"
},
"./dist/index.node.esm": {
"types": "./dist/index.d.ts",
"default": "./dist/index.node.esm.js"
},
"./dist/index.browser.esm": {
"types": "./dist/index.d.ts",
"default": "./dist/index.browser.esm.js"
},
"./package.json": "./package.json"
},
"imports": {
"#pkg": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.node.cjs"
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.node.esm.js"
},
"default": {
"types": "./dist/index.d.ts",
"default": "./dist/index.browser.esm.js"
}
}
},
"directories": {
"build": "./build",
"dist": "./dist",
"docs": "./docs",
"src": "./src",
"test": "./test",
"benchmark": "./benchmark",
"mocha-ts": "./.mocha-ts"
},
"scripts": {
"build": "run-s lint:src build:js lint:test docs",
"build:js": "rollup -c build/rollup.config.js",
"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",
"lint": "ts-standard --fix",
"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: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",
"test:browser": "npm run mocha-ts:browser",
"test:browser-headless": "npm run mocha-ts:browser-headless",
"test:node": "run-s test:node-cjs test:node-esm",
"test:node-cjs": "npm run mocha-ts:cjs ",
"test:node-esm": "npm run mocha-ts ",
"watch": "npm run mocha-ts:watch "
},
"ts-standard": {
"project": "tsconfig.json",
"env": [
"mocha"
"name": "@lumeweb/bigint-mod-arith",
"version": "3.3.1",
"description": "Some common functions for modular arithmetic using native JS implementation of BigInt",
"keywords": [
"modular arithmetics",
"BigInt",
"lcm",
"gcd",
"egcd",
"modinv",
"modular inverse",
"modpow",
"modular exponentiation"
],
"globals": [
"IS_BROWSER",
"browser",
"page",
"chai"
],
"ignore": [
"dist/**/*",
"examples/**/*",
"types/**/*",
"benchmark/**/*"
]
},
"nodeBrowserSkel": {
"badges": {
"workflow": true,
"coveralls": true
"license": "MIT",
"author": {
"name": "Juan Hernández Serrano",
"email": "j.hernandez@upc.edu",
"url": "https://github.com/juanelas"
},
"git": {
"branch": "main"
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/bigint-mod-arith.git"
},
"engines": {
"node": ">=10.4.0"
},
"type": "module",
"main": "lib/index.js",
"devDependencies": {
"@lumeweb/node-library-preset": "^0.2.7",
"presetter": "*"
},
"bugs": {
"url": "https://github.com/juanelas/bigint-mod-arith/issues"
},
"readme": "ERROR: No README data found!",
"homepage": "https://github.com/juanelas/bigint-mod-arith#readme",
"_id": "bigint-mod-arith@3.3.1",
"scripts": {
"prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"files": ["lib"],
"publishConfig": {
"access": "public"
}
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.2",
"@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": "^8.0.0",
"chai": "^4.3.3",
"dotenv": "^16.0.3",
"glob": "^10.0.0",
"json5": "^2.2.0",
"minimatch": "^9.0.0",
"mocha": "^10.0.0",
"npm-run-all": "^4.1.5",
"pirates": "^4.0.1",
"puppeteer": "^20.7.3",
"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",
"typedoc-plugin-markdown": "~3.14.0",
"typescript": "^5.0.3"
}
}

View File

@ -1,64 +0,0 @@
[![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)
{{GITHUB_ACTIONS_BADGES}}
# {{PKG_NAME}}
Some extra functions to work with modular arithmetic using native JS ([ES-2020](https://tc39.es/ecma262/#sec-bigint-objects)) implementation of BigInt. It can be used by any [Web Browser or webview supporting BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) and with Node.js (>=10.4.0).
> The operations supported on BigInts are not constant time. BigInt can be therefore **[unsuitable for use in cryptography](https://www.chosenplaintext.ca/articles/beginners-guide-constant-time-cryptography.html).** Many platforms provide native support for cryptography, such as [Web Cryptography API](https://w3c.github.io/webcrypto/) or [Node.js Crypto](https://nodejs.org/dist/latest/docs/api/crypto.html).
## Usage
`{{PKG_NAME}}` can be imported to your project with `npm`:
```console
npm install {{PKG_NAME}}
```
Then either require (Node.js CJS):
```javascript
const {{PKG_CAMELCASE}} = require('{{PKG_NAME}}')
```
> **Node >=10.4 <11**. `{{PKG_NAME}}` uses workers to speed up some operations. Workers are enabled by default with Node.js from version 11. In order to use them with Node >=10.4 and <11, you need to execute node with the flag `--experimental-worker`, and require the `.js` file manually (otherwise `.cjs` is required by default and would not be supported by the workers)
>
> ```javascript
> const bigintCryptoUtils = require('bigint-crypto-utils/dist/cjs/index.node') // ONLY FOR node >=10.4 <11 !
> ```
or import (JavaScript ES module):
```javascript
import * as {{PKG_CAMELCASE}} from '{{PKG_NAME}}'
```
The appropriate version for browser or node is automatically exported.
You can also download the {{IIFE_BUNDLE}}, the {{ESM_BUNDLE}} or the {{UMD_BUNDLE}} and manually add it to your project, or, if you have already imported `{{PKG_NAME}}` to your project, just get the bundles from `node_modules/{{PKG_NAME}}/dist/bundles/`.
An example of usage could be:
```typescript
/* Stage 3 BigInts with value 666 can be declared as BigInt('666')
or the shorter syntax 666n.
Notice that you can also pass a number, e.g. BigInt(666), but it is not
recommended since values over 2**53 - 1 won't be safe but no warning will
be raised.
*/
const a = BigInt('5')
const b = BigInt('2')
const n = 19n
console.log({{PKG_CAMELCASE}}.modPow(a, b, n)) // prints 6
console.log({{PKG_CAMELCASE}}.modInv(2n, 5n)) // prints 3
console.log({{PKG_CAMELCASE}}.modInv(BigInt('3'), BigInt('5'))) // prints 2
```
## API reference documentation
[Check the API](./docs/API.md)

View File

@ -1,30 +0,0 @@
import * as bma from '#pkg'
describe('abs', function () {
const inputs = [
{
value: 1,
abs: 1
},
{
value: BigInt(-2),
abs: BigInt(2)
},
{
value: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'),
abs: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
},
{
value: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'),
abs: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
}
]
for (const input of inputs) {
describe(`abs(${input.value})`, function () {
it(`should return ${input.abs}`, function () {
const ret = bma.abs(input.value)
chai.expect(ret).to.equal(input.abs)
})
})
}
})

View File

@ -1,31 +0,0 @@
import * as bma from '#pkg'
describe('bitLength', function () {
const inputs = [
{
value: BigInt(1),
bitLength: 1
},
{
value: 15,
bitLength: 4
},
{
value: BigInt(-2),
bitLength: 2
},
{
value: BigInt('11592217955149597331'),
abs: BigInt('11592217955149597331'),
bitLength: 64
}
]
for (const input of inputs) {
describe(`bitLength(${input.value})`, function () {
it(`should return ${input.bitLength}`, function () {
const ret = bma.bitLength(input.value)
chai.expect(ret).to.equal(input.bitLength)
})
})
}
})

View File

@ -1,50 +0,0 @@
import * as bma from '#pkg'
describe('crt', function () {
const tests = [
{
input: {
remainders: [2n, 3n, 10n],
modulos: [5n, 7n, 11n]
},
output: 87n
},
{
input: {
remainders: [3n, 3n, 4n],
modulos: [7n, 5n, 12n],
modulo: 7n * 5n * 12n
},
output: 388n
}
]
const invalidTests = [
{
input: {
remainders: [2n, 3n, 10n],
modulos: [5n, 7n]
},
output: 87n
}
]
for (const test of tests) {
describe(`crt([${test.input.remainders.toString()}], [${test.input.modulos.toString()}])`, function () {
it(`should return ${test.output}`, function () {
const ret = bma.crt(test.input.remainders, test.input.modulos, test.input.modulo)
chai.expect(ret).to.equal(test.output)
})
})
}
for (const test of invalidTests) {
describe(`crt([${test.input.remainders.toString()}], [${test.input.modulos.toString()}])`, function () {
it('should throw RangeError', function () {
try {
bma.crt(test.input.remainders, test.input.modulos)
throw new Error('should have failed')
} catch (err) {
chai.expect(err).to.be.instanceOf(RangeError)
}
})
})
}
})

View File

@ -1,41 +0,0 @@
import * as bma from '#pkg'
describe('egcd', function () {
const inputs = [
{
a: 1,
b: 1,
egcd: {
g: 1n,
x: 1n,
y: 0n
}
},
{
a: 1n,
b: 1n,
egcd: {
g: 1n,
x: 1n,
y: 0n
}
},
{
a: 19168541349167916541934149125444444491635125783192549n,
b: 1254366468914567943795n,
egcd: {
g: 3n,
x: -51600903958588471463n,
y: 788536751975320746859894014817801548390476186596482n
}
}
]
for (const input of inputs) {
describe(`eGcd(${input.a}, ${input.b})`, function () {
it('should return the egcd', function () {
const ret = bma.eGcd(input.a, input.b)
chai.expect(ret).to.eql(input.egcd)
})
})
}
})

View File

@ -1,59 +0,0 @@
import * as bma from '#pkg'
describe('gcd', function () {
const inputs = [
{
a: 1,
b: 1,
gcd: BigInt(1)
},
{
a: BigInt(0),
b: BigInt(189),
gcd: BigInt(189)
},
{
a: BigInt(189),
b: BigInt(0),
gcd: BigInt(189)
},
{
a: BigInt(0),
b: BigInt(0),
gcd: BigInt(0)
},
{
a: BigInt(1),
b: BigInt('14546149867129487614601346814'),
gcd: BigInt(1)
},
{
a: BigInt(27),
b: BigInt(18),
gcd: BigInt(9)
},
{
a: BigInt(-27),
b: BigInt(18),
gcd: BigInt(9)
},
{
a: BigInt(256),
b: BigInt(128),
gcd: BigInt(128)
},
{
a: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109'),
b: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243'),
gcd: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109')
}
]
for (const input of inputs) {
describe(`gcd(${input.a}, ${input.b})`, function () {
it(`should return ${input.gcd}`, function () {
const ret = bma.gcd(input.a, input.b)
chai.expect(ret).to.equal(input.gcd)
})
})
}
})

View File

@ -1,44 +0,0 @@
import * as bma from '#pkg'
describe('lcm', function () {
const inputs = [
{
a: BigInt(0),
b: BigInt(0),
lcm: BigInt(0)
},
{
a: 1,
b: 1,
lcm: BigInt(1)
},
{
a: BigInt(1),
b: BigInt('14546149867129487614601346814'),
lcm: BigInt('14546149867129487614601346814')
},
{
a: BigInt(27),
b: BigInt(18),
lcm: BigInt(27) * BigInt(2)
},
{
a: BigInt(-27),
b: BigInt(18),
lcm: BigInt(27) * BigInt(2)
},
{
a: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109'),
b: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243'),
lcm: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243')
}
]
for (const input of inputs) {
describe(`lcm(${input.a}, ${input.b})`, function () {
it(`should return ${input.lcm}`, function () {
const ret = bma.lcm(input.a, input.b)
chai.expect(ret).to.equal(input.lcm)
})
})
}
})

View File

@ -1,86 +0,0 @@
import * as bma from '#pkg'
describe('max', function () {
const inputs = [
{
value: [BigInt(1), BigInt(2)],
max: BigInt(2)
},
{
value: [BigInt(2), BigInt(1)],
max: BigInt(2)
},
{
value: [BigInt(2), BigInt(2)],
max: BigInt(2)
},
{
value: [BigInt(1), BigInt(-2)],
max: BigInt(1)
},
{
value: [BigInt(-2), BigInt(1)],
max: BigInt(1)
},
{
value: [BigInt(-2), BigInt(-2)],
max: BigInt(-2)
},
{
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
},
{
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
},
{
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
},
{
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
},
{
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
max: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
},
{
value: [BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
max: BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
},
{
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
},
{
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
},
{
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
max: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
},
{
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
max: BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
},
{
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
max: BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
},
{
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
max: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
}
]
for (const input of inputs) {
describe(`max(${input.value[0]}, ${input.value[1]})`, function () {
it(`should return ${input.max}`, function () {
const ret = bma.max(input.value[0], input.value[1])
chai.expect(ret).to.equal(input.max)
})
})
}
})

View File

@ -1,86 +0,0 @@
import * as bma from '#pkg'
describe('min', function () {
const inputs = [
{
value: [BigInt(1), BigInt(2)],
min: BigInt(1)
},
{
value: [BigInt(2), BigInt(1)],
min: BigInt(1)
},
{
value: [BigInt(2), BigInt(2)],
min: BigInt(2)
},
{
value: [BigInt(1), BigInt(-2)],
min: BigInt(-2)
},
{
value: [BigInt(-2), BigInt(1)],
min: BigInt(-2)
},
{
value: [BigInt(-2), BigInt(-2)],
min: BigInt(-2)
},
{
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
},
{
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
},
{
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
min: BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
},
{
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252'), BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
},
{
value: [BigInt('115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')],
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252')
},
{
value: [BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777'), BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')],
min: BigInt('-115922179551495973383410176342643722334557255682879605864838806293659619625004303206250384392546855063844106965156287951749387634112551089284595541103692716528774876311641700929986988023197242224581099872580798960693521778607396791006450968430359009613295725905514216842343121690916290236558767890728449777')
},
{
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
min: BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
},
{
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
min: BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
},
{
value: [BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
min: BigInt('918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
},
{
value: [BigInt('94120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
},
{
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('918145974144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
},
{
value: [BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203'), BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')],
min: BigInt('-918145944120889203205646923554374144932845997937845799234617798611046542304088105084854788397071323714642587188481158334265864050544813693415594035822877094557870151480865568334936301231664228940480803192289508235412296324312748621874408067955753620604885023289655277704554716080844406284392300643321715285709865081125252390440327650852470312931679380011885102491340191287595160450544053114365852338670819405357496612993587404998677760882578064637552397840566752638770525765833183986360029736508910848408875329873614164495552615086579144675027852136994842529623698055210822311666048300438808691619782893307972452223713060928388502843564836966586109748062827799521852219158489504529458627699284110902303538160168376473182639384638674469114371472053977558648090155686345760457454061117853710619580819749222459422610617170567016772342291486643520567969321969827786373531753524990712622940069883277763528926899970596407140603912036918433859986491820017690762751824769335720368488097262208835708414085501930989486498185503469986946236128468697606998536541209764920494156326791142098506801288127033229779646920082892258428128572765585196779698362187479280520327053508580551167899837393726371144977951402741307021389967382422805567365901203')
}
]
for (const input of inputs) {
describe(`min(${input.value[0]}, ${input.value[1]})`, function () {
it(`should return ${input.min}`, function () {
const ret = bma.min(input.value[0], input.value[1])
chai.expect(ret).to.equal(input.min)
})
})
}
})

View File

@ -1,31 +0,0 @@
import * as bma from '#pkg'
describe('modAdd', function () {
const inputs = [
{
addends: [1n, 14n, 5n],
n: 5n,
result: 0n
},
{
addends: [98146598146508942650812465n, 971326598235697821592183520352089356n],
n: 972136523n,
result: 88640188n
},
{
addends: [98146598146508942650812465n, -971326598235697821592183520352089356n],
n: 972136523n,
result: 133225889n
}
]
for (const input of inputs) {
describe(`modAdd([${input.addends.toString()}], ${input.n})`, function () {
it(`should return ${input.result}`, function () {
const ret = bma.modAdd(input.addends, input.n)
// chai.assert( String(ret) === String(input.modInv) );
chai.expect(String(ret)).to.be.equal(String(input.result))
})
})
}
})

View File

@ -1,56 +0,0 @@
import * as bma from '#pkg'
describe('modInv', function () {
const inputs = [
{
a: BigInt(1),
n: BigInt(19),
modInv: BigInt(1)
},
{
a: BigInt(2),
n: BigInt(5),
modInv: BigInt(3)
},
{
a: BigInt(-2),
n: BigInt(5),
modInv: BigInt(2)
}]
const invalidInputs = [
{
a: BigInt(2),
n: BigInt(4)
},
{
a: BigInt(0),
n: BigInt(0)
},
{
a: BigInt(0),
n: BigInt(37)
}
]
for (const input of inputs) {
describe(`modInv(${input.a}, ${input.n})`, function () {
it(`should return ${input.modInv}`, function () {
const ret = bma.modInv(input.a, input.n)
// chai.assert( String(ret) === String(input.modInv) );
chai.expect(String(ret)).to.be.equal(String(input.modInv))
})
})
}
for (const input of invalidInputs) {
describe(`modInv(${input.a}, ${input.n})`, function () {
it('should throw RangeError', function () {
try {
bma.modInv(input.a, input.n)
throw new Error('should have failed')
} catch (err) {
chai.expect(err).to.be.instanceOf(RangeError)
}
})
})
}
})

View File

@ -1,30 +0,0 @@
import * as bma from '#pkg'
describe('modMultiply', function () {
const inputs = [
{
factors: [-1n, 1n, 19n],
n: 5n,
result: 1n
},
{
factors: [98146598146508942650812465n, 971326598235697821592183520352089356n],
n: 972136523n,
result: 326488233n
},
{
factors: [98146598146508942650812465n, -971326598235697821592183520352089356n],
n: 972136523n,
result: 645648290n
}
]
for (const input of inputs) {
describe(`modMultiply([${input.factors.toString()}], ${input.n})`, function () {
it(`should return ${input.result}`, function () {
const ret = bma.modMultiply(input.factors, input.n)
chai.expect(String(ret)).to.be.equal(String(input.result))
})
})
}
})

View File

@ -1,152 +0,0 @@
import * as bma from '#pkg'
describe('modPow', function () {
const inputs = [
{
a: BigInt(4),
b: BigInt(-1),
n: BigInt(1),
modPow: BigInt(0)
},
{
a: BigInt(4),
b: -1,
n: BigInt(19),
modPow: BigInt(5)
},
{
a: BigInt(-5),
b: BigInt(2),
n: 7,
modPow: BigInt(4)
},
{
a: 2,
b: BigInt(255),
n: BigInt(64),
modPow: BigInt(0),
factorization: [
[2n, 6n] as [bigint, bigint]
]
},
{
a: BigInt(3),
b: BigInt(3),
n: BigInt(25),
modPow: BigInt(2)
},
{
a: 1245124521461246134613464612465425n,
b: 9861532432154028374523497086414586n,
n: 500153323344587826888856848415851710985056973082286918972465210560564286327935715658989361814629267526408365126549790626298674370641919299205366510873756645480988096218726721049169354944272728793562147809267541398194457197043260189n,
modPow: 240451691789770161942445790505417018856065097712648273113407316782091824158551945401793333941917448724323499865320019414055693250255681376010258044942735855039307823617978628203426153507803442305305788129411652227222626528677503357n,
factorization: [
218230499735828681265329912048785421189n,
303663914757588658442322995331731552767n,
330074629227155283615948126790169269393n,
318474781297924758545194431666113118619n,
258866136593300047022978927175555617677n,
277352503791024309522752317490262967817n
]
},
{
a: 14,
b: 7,
n: 75,
modPow: (14n ** 7n) % 75n,
factorization: [5, 5, 3]
},
{
a: 14,
b: 7,
n: 75,
modPow: (14n ** 7n) % 75n,
factorization: [
[5, 2],
[3, 1]
] as Array<[number, number]>
},
{
a: 14,
b: 7,
n: 75,
modPow: (14n ** 7n) % 75n,
factorization: [
[5, 1],
[5, 1],
[3, 1]
] as Array<[number, number]>
}
]
const invalidInputs = [
{
a: BigInt(4),
b: BigInt(-1),
n: BigInt(0)
}
]
this.timeout(90000)
for (const input of inputs) {
describe(`modPow(${input.a}, ${input.b}, ${input.n})`, function () {
it(`should return ${input.modPow}`, function () {
const ret = bma.modPow(input.a, input.b, input.n)
chai.expect(String(ret)).to.equal(String(input.modPow))
})
})
if (input.factorization !== undefined) {
describe(`modPow(${input.a}, ${input.b}, ${input.n}, ${input.factorization.toString()})`, function () {
it(`should return ${input.modPow}`, function () {
const ret = bma.modPow(input.a, input.b, input.n, input.factorization)
chai.expect(String(ret)).to.equal(String(input.modPow))
})
})
}
}
for (const input of invalidInputs) {
describe(`modPow(${input.a}, ${input.b}, ${input.n})`, function () {
it('should throw RangeError', function () {
try {
bma.modPow(input.a, input.b, input.n)
throw new Error('should have failed')
} catch (err) {
chai.expect(err).to.be.instanceOf(RangeError)
}
})
})
}
describe('Time profiling', function () {
let iterations = 200
it(`just testing ${iterations} iterations of a big modular exponentiation (2556 bits) without knowing the factorization`, function () {
const b = 14456431150320172221616509514915526986361238106327826551303073486525612767865296230128540157601034246266893020552680362383297675100669325175361571346279322237329539671666972989978592763343703141198972640627941866075477300010699834312750158094259287059018038648351844386887485449450696346016139524199689991349708808322654998848805208669420846568444495238595132694793197702398883664520354286998606227508937724093725751362231924270085297872354786607945787781132474291940577910417557559293025781300297297108502666688221522472289490235815670978276613741134646350434101590756987811531081642032408524942596500338402454466381n
const e = 6476828424489334540282736436237684965801863681796103123350476262449294411071194504043425154023126089205310946452545492503146985930350204469300515359582715304152166280054365341048395809786334314857324636363499307693460463510288529968621389225833525926438586030988343742064052508822378379640511991190252363284703683198952353035019752852304188032580325320976126425473699273404534699914473174622613565918567472049036606462965033376292343629368800907251671928637057211397168781968913665986137146419257679003630816671501426427417948524164164352320112674416922816719009895345189205426946805834621054179616261802871233808542n
const p = 14042712215688595888153548037889265603500445396639048834534593945467996508131090693365705725532399000992101105698944349047255173597667719370418259169482368508397450171314103850946590710597528264317201250415269575297721977669910571659769606054734401815045082525419212665804298903457270476082779587884970903510490346851467622773314340966549056833592925777140709340896303359906331395892064520612544700229681757412030739888382792194999476266900467607277786534152843408108882693507381781909441777014175765880808549111456404523289456415574592100070259890096499076724913855490255757168221008761519287520710678016476002003203122666993484494111951001896014648841958164118312595430383512299989338389906619375114947097244226374433271798549164684597345168487916487128962249635970759n
while (iterations > 0) {
bma.modPow(b, e, p)
iterations--
}
})
let iterations2 = 200
it(`just testing ${iterations2} iterations of a big modular exponentiation (2556 bits) knowing the factorization`, function () {
const b = 14456431150320172221616509514915526986361238106327826551303073486525612767865296230128540157601034246266893020552680362383297675100669325175361571346279322237329539671666972989978592763343703141198972640627941866075477300010699834312750158094259287059018038648351844386887485449450696346016139524199689991349708808322654998848805208669420846568444495238595132694793197702398883664520354286998606227508937724093725751362231924270085297872354786607945787781132474291940577910417557559293025781300297297108502666688221522472289490235815670978276613741134646350434101590756987811531081642032408524942596500338402454466381n
const e = 6476828424489334540282736436237684965801863681796103123350476262449294411071194504043425154023126089205310946452545492503146985930350204469300515359582715304152166280054365341048395809786334314857324636363499307693460463510288529968621389225833525926438586030988343742064052508822378379640511991190252363284703683198952353035019752852304188032580325320976126425473699273404534699914473174622613565918567472049036606462965033376292343629368800907251671928637057211397168781968913665986137146419257679003630816671501426427417948524164164352320112674416922816719009895345189205426946805834621054179616261802871233808542n
const p = 14042712215688595888153548037889265603500445396639048834534593945467996508131090693365705725532399000992101105698944349047255173597667719370418259169482368508397450171314103850946590710597528264317201250415269575297721977669910571659769606054734401815045082525419212665804298903457270476082779587884970903510490346851467622773314340966549056833592925777140709340896303359906331395892064520612544700229681757412030739888382792194999476266900467607277786534152843408108882693507381781909441777014175765880808549111456404523289456415574592100070259890096499076724913855490255757168221008761519287520710678016476002003203122666993484494111951001896014648841958164118312595430383512299989338389906619375114947097244226374433271798549164684597345168487916487128962249635970759n
const factorization = [
64735041287835073339645110378796758902638279101014381826528695387496122442691n,
100608456040189246257906094489725850536673092825529567729728751391736301991369n,
58992718408385655584411200892712190864864350334099743757220725378063820240657n,
96562131825975924912838022675233698320760586729314385931723127363428962983247n,
68620104844493133229164822823175832794894654493599547904820655831878232061531n,
71474468886948151751742173259692288576445414562898468020644046548578552084431n,
96793884673833556249816099345608529931050134280462961194018209385115828684189n,
94085307601549784597508419912586171618182711224796241928810495401174923988119n,
91841918562944515248478087657554520191420619060733607414018266296555587309041n,
92269642318171922312931975258187595106742943586895754768486213552371747180589n
]
while (iterations2 > 0) {
bma.modPow(b, e, p, factorization)
iterations2--
}
})
})
})

View File

@ -1,22 +0,0 @@
import * as bma from '#pkg'
describe('phi', function () {
const tests = [
{
input: [[17n, 1n], [19n, 1n]] as bma.PrimeFactorization,
output: (17n - 1n) * (19n - 1n)
},
{
input: [[17n, 4n]] as bma.PrimeFactorization,
output: (17n ** 3n) * 16n
}
]
for (const test of tests) {
describe(`phi([${test.input.toString()}])`, function () {
it(`should return ${test.output}`, function () {
const ret = bma.phi(test.input)
chai.expect(ret).to.equal(test.output)
})
})
}
})

View File

@ -1,48 +0,0 @@
import * as bma from '#pkg'
describe('toZn', function () {
const inputs = [
{
a: BigInt(1),
n: BigInt(19),
toZn: BigInt(1)
},
{
a: -25,
n: BigInt(9),
toZn: BigInt(2)
},
{
a: BigInt('12359782465012847510249'),
n: 5,
toZn: BigInt(4)
}
]
const invalidInputs = [
{
a: BigInt(4),
n: BigInt(-1),
toZn: BigInt(0)
}
]
for (const input of inputs) {
describe(`toZn(${input.a}, ${input.n})`, function () {
it(`should return ${input.toZn}`, function () {
const ret = bma.toZn(input.a, input.n)
chai.expect(ret).to.equal(input.toZn)
})
})
}
for (const input of invalidInputs) {
describe(`toZn(${input.a}, ${input.n})`, function () {
it('should throw RangeError', function () {
try {
bma.toZn(input.a, input.n)
throw new Error('should have failed')
} catch (err) {
chai.expect(err).to.be.instanceOf(RangeError)
}
})
})
}
})

View File

@ -1,47 +0,0 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"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. */
"outDir": ".dst", /* If not set we cannot import .js files without a warning that is going to be overwritten. outDir is not going to be used in any case */
"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. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
/* Module Resolution Options */
"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. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
"resolveJsonModule": true,
"paths": {
"#pkg": ["./src/ts/index.ts"]
}
},
"include": ["src/ts/**/*", "build/typings/**/*.d.ts", "test/**/*", "test-vectors/**/*.ts", "benchmark/**/*.ts"]
}

View File

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

View File

@ -1 +0,0 @@
{"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/abs.d.ts vendored
View File

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

View File

@ -1 +0,0 @@
{"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"}

View File

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

View File

@ -1 +0,0 @@
{"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,2 +0,0 @@
export declare function bitLength(a: number | bigint): number;
//# sourceMappingURL=bitLength.d.ts.map

View File

@ -1 +0,0 @@
{"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,7 +0,0 @@
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

View File

@ -1 +0,0 @@
{"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"}

7
types/egcd.d.ts vendored
View File

@ -1,7 +0,0 @@
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

View File

@ -1 +0,0 @@
{"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"}

View File

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

View File

@ -1 +0,0 @@
{"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"}

2
types/gcd.d.ts vendored
View File

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

View File

@ -1 +0,0 @@
{"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"}

View File

@ -1,11 +0,0 @@
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 +0,0 @@
{"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"}

11
types/index.d.ts vendored
View File

@ -1,11 +0,0 @@
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 +0,0 @@
{"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"}

View File

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

View File

@ -1 +0,0 @@
{"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/lcm.d.ts vendored
View File

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

View File

@ -1 +0,0 @@
{"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"}

View File

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

View File

@ -1 +0,0 @@
{"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/max.d.ts vendored
View File

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

View File

@ -1 +0,0 @@
{"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"}

View File

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

View File

@ -1 +0,0 @@
{"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/min.d.ts vendored
View File

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

View File

@ -1 +0,0 @@
{"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"}

View File

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

View File

@ -1 +0,0 @@
{"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/modInv.d.ts vendored
View File

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

View File

@ -1 +0,0 @@
{"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"}

View File

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

View File

@ -1 +0,0 @@
{"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"}

Some files were not shown because too many files have changed in this diff Show More