fixed badges. small improvements
This commit is contained in:
parent
438d9bd9f3
commit
59cd071971
|
@ -1,7 +1,7 @@
|
|||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
||||
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
|
||||
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
|
||||
[![Node.js CI](https://github.com/juanelas/bigint-mod-arith/workflows/build/badge.svg)](https://github.com/juanelas/bigint-mod-arith/actions?query=workflow%3A%22build%22)
|
||||
[![Node.js CI](https://github.com/juanelas/bigint-mod-arith/actions/workflows/nodejs.yml/badge.svg)](https://github.com/juanelas/bigint-mod-arith/actions/workflows/nodejs.yml)
|
||||
[![Coverage Status](https://coveralls.io/repos/github/juanelas/bigint-mod-arith/badge.svg?branch=master)](https://coveralls.io/github/juanelas/bigint-mod-arith?branch=master)
|
||||
|
||||
# bigint-mod-arith
|
||||
|
@ -24,7 +24,7 @@ Then either require (Node.js CJS):
|
|||
const bigintModArith = require('bigint-mod-arith')
|
||||
```
|
||||
|
||||
> **Node >=10.4 <11**. `bigint-mod-arith` 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)
|
||||
> **Node >=10.4 <11**. `bigint-mod-arith` 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 !
|
||||
|
|
|
@ -1,75 +1,166 @@
|
|||
#! /usr/bin/env node
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const childProcess = require('child_process')
|
||||
const glob = require('glob')
|
||||
const minimatch = require('minimatch')
|
||||
const rimraf = require('rimraf')
|
||||
const runScript = require('../run-script.cjs')
|
||||
|
||||
const rootDir = path.join(__dirname, '../..')
|
||||
const mochaTsRelativeDir = '.mocha-ts'
|
||||
const minimatch = require('minimatch')
|
||||
const glob = require('glob')
|
||||
|
||||
// First let us prepare the args to pass to mocha.
|
||||
// ts.files will be replaced by their js-transpiled counterparts
|
||||
// a watch file to our semaphore will be added
|
||||
const processedArgs = processArgs(process.argv.slice(2))
|
||||
const pkgJson = require(path.join(rootDir, 'package.json'))
|
||||
|
||||
// Now we can run a script and invoke a callback when complete, e.g.
|
||||
runScript(path.join(rootDir, 'node_modules/mocha/bin/mocha'), processedArgs)
|
||||
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() ?? '').replace(/^['"]/, '').replace(/['"]$/, '') // Let us remove surrounding quotes in string (it gives issues in windows)
|
||||
if (testsGlob === '') {
|
||||
testsGlob = '{src/ts/**/*.spec.ts,test/**/*.ts}'
|
||||
}
|
||||
|
||||
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 = []
|
||||
|
||||
function processArgs (args) {
|
||||
args = process.argv.slice(2).map(arg => {
|
||||
// Let us first remove surrounding quotes in string (it gives issues in windows)
|
||||
arg = arg.replace(/^['"]/, '').replace(/['"]$/, '')
|
||||
const filenames = glob.sync(arg, { cwd: rootDir, matchBase: true })
|
||||
if (filenames.length > 0) {
|
||||
return filenames.map(file => {
|
||||
filenames.forEach(file => {
|
||||
const isTsTestFile = minimatch(file, '{test/**/*.ts,src/**/*.spec.ts}', { matchBase: true })
|
||||
if (isTsTestFile) {
|
||||
return `${mochaTsRelativeDir}/${file.slice(0, -3)}.js`
|
||||
testFiles.push(file)
|
||||
const extension = commonjs ? 'cjs' : 'js'
|
||||
jsTestFiles.push(`${mochaTsRelativeDir}/${file.slice(0, -3)}.${extension}`)
|
||||
}
|
||||
return file
|
||||
})
|
||||
}
|
||||
return arg
|
||||
})
|
||||
mochaArgs.push(...jsTestFiles)
|
||||
|
||||
const processedArgs = []
|
||||
return {
|
||||
mochaArgs,
|
||||
testFiles,
|
||||
commonjs
|
||||
}
|
||||
}
|
||||
|
||||
let addSemaphore = false
|
||||
let semaphoreAdded = false
|
||||
for (const arg of args) {
|
||||
if (Array.isArray(arg)) {
|
||||
processedArgs.push(...arg)
|
||||
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 {
|
||||
processedArgs.push(arg)
|
||||
if (arg === '--watch' || arg === '-w') {
|
||||
addSemaphore = true
|
||||
} else if (arg === '--watch-files') {
|
||||
processedArgs.push(`${mochaTsRelativeDir}/semaphore`)
|
||||
semaphoreAdded = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addSemaphore === true || semaphoreAdded === false) {
|
||||
processedArgs.push('--watch-files')
|
||||
processedArgs.push(`${mochaTsRelativeDir}/semaphore`)
|
||||
console.log('\x1b[33mℹ [mocha-ts] Running tests against the ESM module \x1b[0m\n')
|
||||
}
|
||||
|
||||
return processedArgs
|
||||
}
|
||||
const rollupBuilder = require('../testing/mocha/builders/RollupBuilder.cjs').rollupBuilder
|
||||
|
||||
function runScript (scriptPath, args) {
|
||||
const mochaCmd = childProcess.fork(scriptPath, args, {
|
||||
cwd: rootDir
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
||||
mochaCmd.on('error', (error) => {
|
||||
throw error
|
||||
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
|
||||
}
|
||||
|
||||
// execute the callback once the process has finished running
|
||||
mochaCmd.on('exit', function (code) {
|
||||
if (code !== 0) {
|
||||
throw new Error('exit code ' + code)
|
||||
function getOption (args, option) {
|
||||
const index = args.indexOf(option)
|
||||
if (index > -1 && index < args.length - 2) {
|
||||
return args.splice(index, 2)[1]
|
||||
}
|
||||
})
|
||||
return ''
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
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, '..')
|
||||
|
||||
|
@ -14,15 +16,25 @@ function camelise (str) {
|
|||
})
|
||||
}
|
||||
|
||||
const tsConfigPath = path.join(rootDir, 'tsconfig.json')
|
||||
const tempTsConfigPath = path.join(rootDir, '.tsconfig.json')
|
||||
|
||||
async function typedoc () {
|
||||
const app = new TypeDoc.Application()
|
||||
|
||||
// prepare tsconfig
|
||||
const 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,
|
||||
|
@ -84,7 +96,7 @@ if (repoProvider) {
|
|||
iifeBundle = `[IIFE bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/master/${iifeBundlePath})`
|
||||
esmBundle = `[ESM bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/master/${esmBundlePath})`
|
||||
umdBundle = `[UMD bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/master/${umdBundlePath})`
|
||||
workflowBadget = `[![Node.js CI](https://github.com/${repoUsername}/${repoName}/workflows/build/badge.svg)](https://github.com/${repoUsername}/${repoName}/actions?query=workflow%3A%22build%22)`
|
||||
workflowBadget = `[![Node.js CI](https://github.com/${repoUsername}/${repoName}/actions/workflows/nodejs.yml/badge.svg)](https://github.com/${repoUsername}/${repoName}/actions/workflows/nodejs.yml)`
|
||||
coverallsBadge = `[![Coverage Status](https://coveralls.io/repos/github/${repoUsername}/${repoName}/badge.svg?branch=master)](https://coveralls.io/github/${repoUsername}/${repoName}?branch=master)`
|
||||
break
|
||||
|
||||
|
@ -117,3 +129,5 @@ const readmeFile = path.join(rootDir, 'README.md')
|
|||
fs.writeFileSync(readmeFile, template)
|
||||
|
||||
typedoc()
|
||||
|
||||
rimraf.sync(tempTsConfigPath)
|
||||
|
|
|
@ -8,8 +8,8 @@ import commonjs from '@rollup/plugin-commonjs'
|
|||
import json from '@rollup/plugin-json'
|
||||
|
||||
import { join } from 'path'
|
||||
import { existsSync } from 'fs-extra'
|
||||
import { directories, name as _name, dependencies, peerDependencies, exports } from '../package.json'
|
||||
import { existsSync } from 'fs'
|
||||
import { directories, name as _name, exports } from '../package.json'
|
||||
import { compile } from './rollup-plugin-dts.js'
|
||||
|
||||
const rootDir = join(__dirname, '..')
|
||||
|
@ -37,8 +37,6 @@ const tsBundleOptions = {
|
|||
exclude: ['src/**/*.spec.ts']
|
||||
}
|
||||
|
||||
const external = [...Object.keys(dependencies || {}), ...Object.keys(peerDependencies || {})]
|
||||
|
||||
const sourcemapOutputOptions = {
|
||||
sourcemap: 'inline',
|
||||
sourcemapExcludeSources: true
|
||||
|
@ -54,83 +52,9 @@ function compileDts () {
|
|||
}
|
||||
|
||||
export default [
|
||||
{ // ESM for browsers and declarations
|
||||
{ // Node ESM with declarations
|
||||
input: input,
|
||||
output: [
|
||||
{
|
||||
file: join(rootDir, exports['.'].default),
|
||||
...sourcemapOutputOptions,
|
||||
format: 'es'
|
||||
}
|
||||
],
|
||||
plugins: [
|
||||
replace({
|
||||
IS_BROWSER: true,
|
||||
preventAssignment: true
|
||||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
compileDts(),
|
||||
json()
|
||||
],
|
||||
external
|
||||
},
|
||||
{ // Browser bundles
|
||||
input: input,
|
||||
output: [
|
||||
{
|
||||
file: join(dstDir, 'bundles/iife.js'),
|
||||
format: 'iife',
|
||||
name: pkgCamelisedName,
|
||||
plugins: [terser()]
|
||||
},
|
||||
{
|
||||
file: join(dstDir, 'bundles/esm.js'),
|
||||
...sourcemapOutputOptions,
|
||||
format: 'es'
|
||||
},
|
||||
{
|
||||
file: join(dstDir, 'bundles/esm.min.js'),
|
||||
format: 'es',
|
||||
plugins: [terser()]
|
||||
},
|
||||
{
|
||||
file: join(dstDir, 'bundles/umd.js'),
|
||||
format: 'umd',
|
||||
name: pkgCamelisedName,
|
||||
plugins: [terser()]
|
||||
}
|
||||
],
|
||||
plugins: [
|
||||
replace({
|
||||
IS_BROWSER: true,
|
||||
preventAssignment: true
|
||||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
resolve({
|
||||
browser: true,
|
||||
exportConditions: ['browser', 'default'],
|
||||
mainFields: ['browser', 'main']
|
||||
}),
|
||||
commonjs({
|
||||
// namedExports: {
|
||||
// 'bn.js': ['BN'],
|
||||
// 'hash.js': ['hmac', 'ripemd160', 'sha256', 'sha512'],
|
||||
// elliptic: ['ec'],
|
||||
// 'scrypt-js': ['scrypt', 'syncScrypt']
|
||||
// }
|
||||
}),
|
||||
json()
|
||||
]
|
||||
},
|
||||
{ // Node
|
||||
input: input,
|
||||
output: [
|
||||
{
|
||||
file: join(rootDir, exports['.'].node.require),
|
||||
...sourcemapOutputOptions,
|
||||
format: 'cjs',
|
||||
exports: 'auto'
|
||||
},
|
||||
{
|
||||
file: join(rootDir, exports['.'].node.import),
|
||||
...sourcemapOutputOptions,
|
||||
|
@ -143,9 +67,111 @@ export default [
|
|||
preventAssignment: true
|
||||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
compileDts(),
|
||||
// resolve({
|
||||
// browser: false,
|
||||
// exportConditions: ['node']
|
||||
// }),
|
||||
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
|
||||
json()
|
||||
]
|
||||
},
|
||||
{ // Node CJS
|
||||
input: input,
|
||||
output: [
|
||||
{
|
||||
file: join(rootDir, exports['.'].node.require),
|
||||
...sourcemapOutputOptions,
|
||||
format: 'cjs',
|
||||
exports: 'auto'
|
||||
}
|
||||
],
|
||||
external
|
||||
plugins: [
|
||||
// replace({
|
||||
// 'await import(': 'require(',
|
||||
// delimiters: ['', ''],
|
||||
// preventAssignment: true
|
||||
// }),
|
||||
replace({
|
||||
IS_BROWSER: false,
|
||||
preventAssignment: true
|
||||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
// resolve({
|
||||
// browser: false,
|
||||
// exportConditions: ['node']
|
||||
// }),
|
||||
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
|
||||
json()
|
||||
]
|
||||
},
|
||||
{ // ESM for browsers
|
||||
input: input,
|
||||
output: [
|
||||
{
|
||||
file: join(rootDir, exports['.'].default),
|
||||
...sourcemapOutputOptions,
|
||||
format: 'es'
|
||||
},
|
||||
{
|
||||
file: join(dstDir, 'bundles/esm.js'),
|
||||
...sourcemapOutputOptions,
|
||||
format: 'es'
|
||||
},
|
||||
{
|
||||
file: join(dstDir, 'bundles/esm.min.js'),
|
||||
format: 'es',
|
||||
plugins: [terser()]
|
||||
}
|
||||
],
|
||||
plugins: [
|
||||
replace({
|
||||
IS_BROWSER: true,
|
||||
preventAssignment: true
|
||||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
resolve({
|
||||
browser: true,
|
||||
exportConditions: ['browser', 'default']
|
||||
}),
|
||||
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
|
||||
json()
|
||||
]
|
||||
},
|
||||
{ // Browser bundles
|
||||
input: input,
|
||||
output: [
|
||||
{
|
||||
file: join(dstDir, 'bundles/iife.js'),
|
||||
format: 'iife',
|
||||
name: pkgCamelisedName,
|
||||
plugins: [terser()]
|
||||
},
|
||||
{
|
||||
file: join(dstDir, 'bundles/umd.js'),
|
||||
format: 'umd',
|
||||
name: pkgCamelisedName,
|
||||
plugins: [terser()]
|
||||
}
|
||||
],
|
||||
plugins: [
|
||||
// replace({
|
||||
// 'await import(': 'require(',
|
||||
// delimiters: ['', ''],
|
||||
// preventAssignment: true
|
||||
// }),
|
||||
replace({
|
||||
IS_BROWSER: true,
|
||||
preventAssignment: true
|
||||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
resolve({
|
||||
browser: true,
|
||||
exportConditions: ['browser', 'default'],
|
||||
mainFields: ['browser', 'module', 'main']
|
||||
}),
|
||||
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
|
||||
json()
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
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
|
|
@ -29,11 +29,11 @@ const browserTests = async (
|
|||
}
|
||||
if (ignore) return
|
||||
|
||||
let text = (message.args().length > 0) ? message.args()[0]._remoteObject.value : message.text()
|
||||
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)
|
||||
args.push(message.args()[i].remoteObject().value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ const multi = require('@rollup/plugin-multi-entry')
|
|||
const typescriptPlugin = require('@rollup/plugin-typescript')
|
||||
const commonjs = require('@rollup/plugin-commonjs')
|
||||
const json = require('@rollup/plugin-json')
|
||||
const runScript = require('../../run-script.cjs')
|
||||
|
||||
const rootDir = path.join(__dirname, '..', '..', '..')
|
||||
|
||||
|
@ -40,10 +41,6 @@ const indexHtml = `<!DOCTYPE html>
|
|||
timeout: 90000
|
||||
})
|
||||
</script>
|
||||
<script type="module">
|
||||
import * as _pkg from './${name}.esm.js'
|
||||
self._pkg = _pkg
|
||||
</script>
|
||||
<script type="module">
|
||||
import './tests.js'
|
||||
window._mocha = mocha.run()
|
||||
|
@ -62,6 +59,11 @@ async function buildTests (testFiles) {
|
|||
input,
|
||||
plugins: [
|
||||
multi({ exports: true }),
|
||||
replace({
|
||||
'#pkg': `/${name}.esm.js`,
|
||||
delimiters: ['', ''],
|
||||
preventAssignment: true
|
||||
}),
|
||||
replace({
|
||||
IS_BROWSER: true,
|
||||
preventAssignment: true
|
||||
|
@ -69,12 +71,12 @@ async function buildTests (testFiles) {
|
|||
typescriptPlugin(tsBundleOptions),
|
||||
resolve({
|
||||
browser: true,
|
||||
exportConditions: ['browser', 'module', 'import', 'default']
|
||||
exportConditions: ['browser', 'default']
|
||||
}),
|
||||
commonjs(),
|
||||
json()
|
||||
],
|
||||
external: [pkgJson.name]
|
||||
external: [`/${name}.esm.js`]
|
||||
}
|
||||
const bundle = await rollup.rollup(inputOptions)
|
||||
const { output } = await bundle.generate({ format: 'esm' })
|
||||
|
@ -82,7 +84,8 @@ async function buildTests (testFiles) {
|
|||
let bundledCode = output[0].code
|
||||
const replacements = _getEnvVarsReplacements(bundledCode)
|
||||
for (const replacement in replacements) {
|
||||
bundledCode = bundledCode.replaceAll(replacement, replacements[replacement])
|
||||
const regExp = new RegExp(replacement, 'g')
|
||||
bundledCode = bundledCode.replace(regExp, replacements[replacement])
|
||||
}
|
||||
return bundledCode
|
||||
}
|
||||
|
@ -93,10 +96,15 @@ class TestServer {
|
|||
}
|
||||
|
||||
async init (testFiles) {
|
||||
/** Let us first check if the necessary files are built, and if not, build */
|
||||
if (!fs.existsSync(pkgJson.exports['./esm-browser-bundle'])) {
|
||||
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.directories.dist, 'bundles/esm.js'), function (err, data) {
|
||||
fs.readFile(path.join(rootDir, pkgJson.exports['./esm-browser-bundle']), function (err, data) {
|
||||
if (err) {
|
||||
res.writeHead(404)
|
||||
res.end(JSON.stringify(err))
|
||||
|
|
|
@ -6,10 +6,13 @@ module.exports = class Builder extends EventEmitter {
|
|||
constructor (semaphoreFile, name = 'builder') {
|
||||
super()
|
||||
this.name = name
|
||||
this.firstBuild = true
|
||||
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) => {
|
||||
|
@ -24,12 +27,12 @@ module.exports = class Builder extends EventEmitter {
|
|||
}
|
||||
})
|
||||
|
||||
this.on('ready', () => {
|
||||
if (this.firstBuild === false) {
|
||||
fs.writeFileSync(this.semaphoreFile, '', 'utf-8')
|
||||
} else {
|
||||
this.firstBuild = false
|
||||
this.on('ready', (updateSemaphore = true) => {
|
||||
const now = Date.now()
|
||||
if (updateSemaphore) {
|
||||
fs.utimesSync(this.semaphoreFile, now, now)
|
||||
}
|
||||
|
||||
this._ready = true
|
||||
})
|
||||
|
||||
|
|
|
@ -3,36 +3,49 @@ const fs = require('fs')
|
|||
const path = require('path')
|
||||
|
||||
const rollup = require('rollup')
|
||||
const loadAndParseConfigFile = require('rollup/dist/loadConfigFile.js')
|
||||
const loadAndParseConfigFile = require('rollup/dist/loadConfigFile')
|
||||
|
||||
const Builder = require('./Builder.cjs')
|
||||
|
||||
const rootDir = path.join(__dirname, '../../../../')
|
||||
|
||||
const pkgJson = require(path.join(rootDir, 'package.json'))
|
||||
|
||||
module.exports = class RollupBuilder extends Builder {
|
||||
constructor ({ name = 'rollup', configPath = path.join(rootDir, 'rollup.config.js'), tempDir = path.join(rootDir, '.mocha-ts'), watch = false }) {
|
||||
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.watch = watch
|
||||
this.firstBuild = true
|
||||
}
|
||||
|
||||
async start () {
|
||||
async start ({ watch = false, commonjs = false }) {
|
||||
await super.start()
|
||||
|
||||
this.watch = watch
|
||||
this.commonjs = commonjs
|
||||
this.watchedModule = commonjs ? pkgJson.exports['.'].node.require : pkgJson.exports['.'].node.import
|
||||
|
||||
const { options } = await loadAndParseConfigFile(this.configPath)
|
||||
// Watch only the Node CJS module, that is the one we are going to use with mocha
|
||||
|
||||
// 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, pkgJson.main)
|
||||
return file === path.join(rootDir, this.watchedModule)
|
||||
})[0]
|
||||
delete rollupOptions.output.pop() // remove the second output
|
||||
if (rollupOptions.output.length > 1) {
|
||||
rollupOptions.output = rollupOptions.output[0]
|
||||
}
|
||||
|
||||
this.builder = new RollupBundler(rollupOptions, this.watch)
|
||||
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')
|
||||
|
@ -49,13 +62,23 @@ module.exports = class RollupBuilder extends Builder {
|
|||
|
||||
case 'END':
|
||||
if (event.result) event.result.close()
|
||||
this.emit('ready')
|
||||
|
||||
// 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, pkgJson.main), '', 'utf8')
|
||||
fs.writeFileSync(path.join(rootDir, this.watchedModule), '', 'utf8')
|
||||
// fs.writeFileSync(path.join(this.tempDir, this.watchedModule), '', 'utf8')
|
||||
this.emit('ready')
|
||||
break
|
||||
|
||||
|
@ -77,10 +100,11 @@ module.exports = class RollupBuilder extends Builder {
|
|||
}
|
||||
|
||||
class RollupBundler extends EventEmitter {
|
||||
constructor (rollupOptions, watch = false) {
|
||||
constructor ({ rollupOptions, watchedModule, watch = false }) {
|
||||
super()
|
||||
this.rollupOptions = rollupOptions
|
||||
this.watch = watch
|
||||
this.watchedModule = watchedModule
|
||||
}
|
||||
|
||||
async start () {
|
||||
|
@ -91,7 +115,7 @@ class RollupBundler extends EventEmitter {
|
|||
this.emit('event', event)
|
||||
})
|
||||
} else {
|
||||
if (fs.existsSync(path.join(rootDir, pkgJson.main)) === false) {
|
||||
if (!fs.existsSync(path.join(rootDir, this.watchedModule))) {
|
||||
await this._bundle()
|
||||
} else {
|
||||
this.emit('event', { code: 'END', noBuild: true })
|
||||
|
@ -121,3 +145,10 @@ class RollupBundler extends EventEmitter {
|
|||
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
|
||||
})
|
||||
|
|
|
@ -2,12 +2,15 @@ const path = require('path')
|
|||
const fs = require('fs')
|
||||
|
||||
const ts = require('typescript')
|
||||
const JSON5 = require('json5')
|
||||
const json5 = require('json5')
|
||||
|
||||
const Builder = require('./Builder.cjs')
|
||||
|
||||
const rootDir = path.join(__dirname, '../../../../')
|
||||
const mochaTsRelativeDir = '.mocha-ts'
|
||||
|
||||
const pkgJson = require(path.join(rootDir, 'package.json'))
|
||||
|
||||
const mochaTsRelativeDir = pkgJson.directories['mocha-ts']
|
||||
const mochaTsDir = path.join(rootDir, mochaTsRelativeDir)
|
||||
|
||||
const formatHost = {
|
||||
|
@ -16,23 +19,65 @@ const formatHost = {
|
|||
getNewLine: () => ts.sys.newLine
|
||||
}
|
||||
|
||||
module.exports = class TestsBuilder extends Builder {
|
||||
constructor ({ name = 'tsc', configPath = path.join(rootDir, 'tsconfig.json'), tempDir = mochaTsDir }) {
|
||||
super(path.join(tempDir, 'semaphore'), name)
|
||||
function fileChecksum (filePath) {
|
||||
return require('crypto')
|
||||
.createHash('md5')
|
||||
.update(fs.readFileSync(filePath, { encoding: 'utf-8' }), 'utf8')
|
||||
.digest('hex')
|
||||
}
|
||||
|
||||
if (fs.existsSync(configPath) !== true) throw new Error(`Couldn't find a tsconfig file at ${configPath}`)
|
||||
function renameJsToCjs (dir, fileList = []) {
|
||||
const files = fs.readdirSync(dir)
|
||||
|
||||
files.forEach(file => {
|
||||
if (fs.statSync(path.join(dir, file)).isDirectory()) {
|
||||
fileList = renameJsToCjs(path.join(dir, file), fileList)
|
||||
} else {
|
||||
const match = file.match(/(.*)\.js$/)
|
||||
if (match !== null) {
|
||||
const filename = match[1]
|
||||
fs.renameSync(path.join(dir, file), path.join(dir, `${filename}.cjs`))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
class TestsBuilder extends Builder {
|
||||
constructor ({ name, configPath, tempDir }) {
|
||||
super(path.join(tempDir, 'semaphore'), name)
|
||||
|
||||
this.tempDir = tempDir
|
||||
|
||||
const tsConfig = JSON5.parse(fs.readFileSync(configPath, 'utf8'))
|
||||
if (fs.existsSync(configPath) !== true) throw new Error(`Couldn't find a tsconfig file at ${configPath}`)
|
||||
|
||||
tsConfig.file = undefined
|
||||
this.tsConfigPath = configPath
|
||||
|
||||
// Exclude already transpiled files in src
|
||||
tsConfig.exclude = ['src/ts/**/!(*.spec).ts']
|
||||
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 = false
|
||||
// tsConfig.compilerOptions.noResolve = true
|
||||
|
||||
// we don't need declaration files
|
||||
tsConfig.compilerOptions.declaration = false
|
||||
|
@ -41,25 +86,24 @@ module.exports = class TestsBuilder extends Builder {
|
|||
tsConfig.compilerOptions.noEmit = false
|
||||
|
||||
// source mapping eases debuging
|
||||
tsConfig.compilerOptions.sourceMap = true
|
||||
tsConfig.compilerOptions.inlineSourceMap = true
|
||||
|
||||
// This prevents SyntaxError: Cannot use import statement outside a module
|
||||
tsConfig.compilerOptions.module = 'commonjs'
|
||||
tsConfig.compilerOptions.rootDir = '.'
|
||||
|
||||
// Removed typeroots (it causes issues)
|
||||
tsConfig.compilerOptions.typeRoots = undefined
|
||||
|
||||
tsConfig.compilerOptions.outDir = path.isAbsolute(tempDir) ? path.relative(rootDir, tempDir) : tempDir
|
||||
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))
|
||||
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(tempDir, filePath).slice(0, -3)}.js`
|
||||
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')
|
||||
|
@ -69,7 +113,19 @@ module.exports = class TestsBuilder extends Builder {
|
|||
|
||||
const reportWatchStatusChanged = (diagnostic, newLine, options, errorCount) => {
|
||||
if (errorCount !== undefined) {
|
||||
this.emit('ready')
|
||||
// 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)
|
||||
}
|
||||
this.emit('ready', updateSemaphore)
|
||||
} else {
|
||||
this.emit('busy')
|
||||
if (diagnostic.code === 6031) {
|
||||
|
@ -90,13 +146,11 @@ module.exports = class TestsBuilder extends Builder {
|
|||
reportDiagnostic,
|
||||
reportWatchStatusChanged
|
||||
)
|
||||
}
|
||||
|
||||
async start () {
|
||||
await super.start()
|
||||
// `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()
|
||||
}
|
||||
|
||||
|
@ -106,3 +160,10 @@ module.exports = class TestsBuilder extends Builder {
|
|||
fs.unlinkSync(this.tempTsConfigPath)
|
||||
}
|
||||
}
|
||||
|
||||
exports.TestsBuilder = TestsBuilder
|
||||
exports.testBuilder = new TestsBuilder({
|
||||
name: 'tsc',
|
||||
configPath: path.join(rootDir, 'tsconfig.json'),
|
||||
tempDir: mochaTsDir
|
||||
})
|
||||
|
|
|
@ -1,76 +1,66 @@
|
|||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const chai = require('chai')
|
||||
const rimraf = require('rimraf')
|
||||
|
||||
const RollupBuilder = require('./builders/RollupBuilder.cjs')
|
||||
const TestsBuilder = require('./builders/TestsBuilder.cjs')
|
||||
|
||||
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
|
||||
loadPkgToGlobal()
|
||||
|
||||
global.IS_BROWSER = false
|
||||
|
||||
const watch = process.argv.includes('--watch') || process.argv.includes('-w')
|
||||
|
||||
const tempDir = path.join(rootDir, '.mocha-ts')
|
||||
const setup = JSON.parse(fs.readFileSync(path.join(tempDir, 'testSetup.json'), 'utf-8'))
|
||||
|
||||
const rollupBuilder = new RollupBuilder({ name: 'rollup', configPath: path.join(rootDir, 'build/rollup.config.js'), tempDir, watch })
|
||||
const testBuilder = new TestsBuilder({ name: 'tsc', tempDir })
|
||||
const testFiles = setup.testFiles
|
||||
let commonjs = setup.commonjs
|
||||
|
||||
rollupBuilder.start() // This should be in exports.mochaGlobalSetup but mocha fails when not in watch mode (DIRT...)
|
||||
testBuilder.start() // This should be in exports.mochaGlobalSetup but mocha fails when not in watch mode (DIRT...)
|
||||
commonjs = watch ? true : commonjs // mocha in watch mode only supports commonjs
|
||||
|
||||
exports.mochaGlobalSetup = async function () {
|
||||
if (watch) {
|
||||
await rollupBuilder.start({ commonjs, watch })
|
||||
testsBuilder.start({ testFiles, commonjs })
|
||||
}
|
||||
}
|
||||
|
||||
exports.mochaHooks = {
|
||||
beforeAll: [
|
||||
async function () {
|
||||
this.timeout('120000')
|
||||
|
||||
await Promise.all([rollupBuilder.ready(), testBuilder.ready()])
|
||||
if (watch) {
|
||||
await Promise.all([rollupBuilder.ready(), testsBuilder.ready()])
|
||||
|
||||
// Just in case our module had been modified. Reload it when the tests are repeated (for mocha watch mode).
|
||||
delete require.cache[require.resolve(rootDir)]
|
||||
loadPkgToGlobal()
|
||||
|
||||
// And now reset any other transpiled module (just delete the cache so it is fully reloaded)
|
||||
// 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}`)) {
|
||||
if (relativePath.startsWith(`.mocha-ts${path.sep}`) || relativePath.startsWith(`dist${path.sep}`)) {
|
||||
delete require.cache[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// exports.mochaGlobalSetup = async function () {
|
||||
// await rollupBuilder.start()
|
||||
// await testBuilder.start()
|
||||
// }
|
||||
|
||||
exports.mochaGlobalTeardown = async function () {
|
||||
await testBuilder.close()
|
||||
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 })
|
||||
}
|
||||
|
||||
function loadPkgToGlobal () {
|
||||
const _pkg = require(rootDir)
|
||||
if (typeof _pkg === 'function') { // If it is just a default export, load it as named (for compatibility)
|
||||
global._pkg = {
|
||||
default: _pkg
|
||||
}
|
||||
} else {
|
||||
global._pkg = _pkg
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
import * as _pkgModule from '../../src/ts/index'
|
||||
|
||||
export as namespace _pkg
|
||||
export = _pkgModule
|
|
@ -10,7 +10,7 @@ function abs(a) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the bitlength of a number
|
||||
* Returns the (minimum) length of a number expressed in bits.
|
||||
*
|
||||
* @param a
|
||||
* @returns The bit length
|
||||
|
|
|
@ -14,7 +14,7 @@ function abs(a) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the bitlength of a number
|
||||
* Returns the (minimum) length of a number expressed in bits.
|
||||
*
|
||||
* @param a
|
||||
* @returns The bit length
|
||||
|
|
|
@ -10,7 +10,7 @@ function abs(a) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the bitlength of a number
|
||||
* Returns the (minimum) length of a number expressed in bits.
|
||||
*
|
||||
* @param a
|
||||
* @returns The bit length
|
||||
|
|
|
@ -10,7 +10,7 @@ function abs(a) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the bitlength of a number
|
||||
* Returns the (minimum) length of a number expressed in bits.
|
||||
*
|
||||
* @param a
|
||||
* @returns The bit length
|
||||
|
|
22
docs/API.md
22
docs/API.md
|
@ -43,7 +43,7 @@ The absolute value of a
|
|||
|
||||
#### Defined in
|
||||
|
||||
[abs.ts:8](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/abs.ts#L8)
|
||||
[abs.ts:8](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/abs.ts#L8)
|
||||
|
||||
___
|
||||
|
||||
|
@ -51,7 +51,7 @@ ___
|
|||
|
||||
▸ **bitLength**(`a`): `number`
|
||||
|
||||
Returns the bitlength of a number
|
||||
Returns the (minimum) length of a number expressed in bits.
|
||||
|
||||
#### Parameters
|
||||
|
||||
|
@ -67,7 +67,7 @@ The bit length
|
|||
|
||||
#### Defined in
|
||||
|
||||
[bitLength.ts:7](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/bitLength.ts#L7)
|
||||
[bitLength.ts:7](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/bitLength.ts#L7)
|
||||
|
||||
___
|
||||
|
||||
|
@ -97,7 +97,7 @@ A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
|||
|
||||
#### Defined in
|
||||
|
||||
[egcd.ts:17](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/egcd.ts#L17)
|
||||
[egcd.ts:17](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/egcd.ts#L17)
|
||||
|
||||
___
|
||||
|
||||
|
@ -122,7 +122,7 @@ The greatest common divisor of a and b
|
|||
|
||||
#### Defined in
|
||||
|
||||
[gcd.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/gcd.ts#L10)
|
||||
[gcd.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/gcd.ts#L10)
|
||||
|
||||
___
|
||||
|
||||
|
@ -147,7 +147,7 @@ The least common multiple of a and b
|
|||
|
||||
#### Defined in
|
||||
|
||||
[lcm.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/lcm.ts#L10)
|
||||
[lcm.ts:10](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/lcm.ts#L10)
|
||||
|
||||
___
|
||||
|
||||
|
@ -172,7 +172,7 @@ Maximum of numbers a and b
|
|||
|
||||
#### Defined in
|
||||
|
||||
[max.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/max.ts#L9)
|
||||
[max.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/max.ts#L9)
|
||||
|
||||
___
|
||||
|
||||
|
@ -197,7 +197,7 @@ Minimum of numbers a and b
|
|||
|
||||
#### Defined in
|
||||
|
||||
[min.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/min.ts#L9)
|
||||
[min.ts:9](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/min.ts#L9)
|
||||
|
||||
___
|
||||
|
||||
|
@ -226,7 +226,7 @@ The inverse modulo n
|
|||
|
||||
#### Defined in
|
||||
|
||||
[modInv.ts:13](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/modInv.ts#L13)
|
||||
[modInv.ts:13](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/modInv.ts#L13)
|
||||
|
||||
___
|
||||
|
||||
|
@ -256,7 +256,7 @@ b**e mod n
|
|||
|
||||
#### Defined in
|
||||
|
||||
[modPow.ts:15](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/modPow.ts#L15)
|
||||
[modPow.ts:15](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/modPow.ts#L15)
|
||||
|
||||
___
|
||||
|
||||
|
@ -289,4 +289,4 @@ A bigint with the smallest positive representation of a modulo n
|
|||
|
||||
#### Defined in
|
||||
|
||||
[toZn.ts:14](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/toZn.ts#L14)
|
||||
[toZn.ts:14](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/toZn.ts#L14)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#### Defined in
|
||||
|
||||
[egcd.ts:2](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/egcd.ts#L2)
|
||||
[egcd.ts:2](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/egcd.ts#L2)
|
||||
|
||||
___
|
||||
|
||||
|
@ -26,7 +26,7 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[egcd.ts:3](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/egcd.ts#L3)
|
||||
[egcd.ts:3](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/egcd.ts#L3)
|
||||
|
||||
___
|
||||
|
||||
|
@ -36,4 +36,4 @@ ___
|
|||
|
||||
#### Defined in
|
||||
|
||||
[egcd.ts:4](https://github.com/juanelas/bigint-mod-arith/blob/f8f1fb2/src/ts/egcd.ts#L4)
|
||||
[egcd.ts:4](https://github.com/juanelas/bigint-mod-arith/blob/438d9bd/src/ts/egcd.ts#L4)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
43
package.json
43
package.json
|
@ -42,32 +42,44 @@
|
|||
"./umd-browser-bundle": "./dist/bundles/umd.js",
|
||||
"./types": "./types/index.d.ts"
|
||||
},
|
||||
"imports": {
|
||||
"#pkg": {
|
||||
"import": "./dist/esm/index.node.js",
|
||||
"require": "./dist/cjs/index.node.cjs"
|
||||
}
|
||||
},
|
||||
"directories": {
|
||||
"build": "./build",
|
||||
"dist": "./dist",
|
||||
"docs": "./docs",
|
||||
"src": "./src",
|
||||
"test": "./test"
|
||||
"test": "./test",
|
||||
"benchmark": "./benchmark",
|
||||
"mocha-ts": "./.mocha-ts"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "run-s lint build:js docs",
|
||||
"build:js": "rollup -c build/rollup.config.js",
|
||||
"clean": "rimraf .nyc_output .mocha-ts coverage dist types docs",
|
||||
"coverage": "nyc --check-coverage --exclude build --exclude '{src/ts/**/*.spec.ts,test/**/*.ts,.mocha-ts/**/*}' --reporter=text --reporter=lcov node ./build/bin/mocha-ts.cjs --require build/testing/mocha/mocha-init.cjs '{src/ts/**/*.spec.ts,test/**/*.ts}'",
|
||||
"clean": "rimraf .mocha-ts coverage dist types docs",
|
||||
"coverage": "c8 --check-coverage --exclude '{src/ts/**/*.spec.ts,test,test-vectors,build}' --exclude-after-remap --reporter=text --reporter=lcov node ./build/bin/mocha-ts.cjs --commonjs ",
|
||||
"docs": "node build/build.docs.cjs",
|
||||
"git:add": "git add -A",
|
||||
"lint": "ts-standard --fix",
|
||||
"mocha-ts": "node ./build/bin/mocha-ts.cjs --require build/testing/mocha/mocha-init.cjs ",
|
||||
"mocha-ts": "node --experimental-modules --es-module-specifier-resolution=node ./build/bin/mocha-ts.cjs ",
|
||||
"mocha-ts:cjs": "node ./build/bin/mocha-ts.cjs --commonjs ",
|
||||
"mocha-ts:watch": "npm run mocha-ts:cjs -- --watch ",
|
||||
"mocha-ts:browser": "node build/testing/browser/index.cjs ",
|
||||
"mocha-ts:browser-headless": "node build/testing/browser/index.cjs headless ",
|
||||
"preversion": "run-s clean lint build:js coverage test:browser-headless",
|
||||
"version": "run-s docs git:add",
|
||||
"postversion": "git push --follow-tags",
|
||||
"test": "run-s test:browser-headless test:node",
|
||||
"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": "npm run mocha-ts -- '{src/ts/**/*.spec.ts,test/**/*.ts}'",
|
||||
"watch": "npm run mocha-ts:node -- --watch '{src/ts/**/*.spec.ts,test/**/*.ts}'"
|
||||
"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": {
|
||||
"env": [
|
||||
|
@ -77,36 +89,35 @@
|
|||
"IS_BROWSER",
|
||||
"browser",
|
||||
"page",
|
||||
"_pkg",
|
||||
"chai"
|
||||
],
|
||||
"project": "./tsconfig.json",
|
||||
"project": "tsconfig.json",
|
||||
"ignore": [
|
||||
"dist/**/*",
|
||||
"examples/**/*",
|
||||
"types/**/*",
|
||||
"build/testing/types/**/*"
|
||||
"build/testing/mocha/mocha-init.js"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^22.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-multi-entry": "^4.0.0",
|
||||
"@rollup/plugin-node-resolve": "^13.0.5",
|
||||
"@rollup/plugin-node-resolve": "^14.1.0",
|
||||
"@rollup/plugin-replace": "^4.0.0",
|
||||
"@rollup/plugin-typescript": "^8.2.0",
|
||||
"@types/chai": "^4.2.22",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"c8": "^7.12.0",
|
||||
"chai": "^4.3.3",
|
||||
"dotenv": "^16.0.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"glob": "^8.0.1",
|
||||
"json5": "^2.2.0",
|
||||
"minimatch": "^5.0.1",
|
||||
"mocha": "^10.0.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nyc": "^15.1.0",
|
||||
"pirates": "^4.0.1",
|
||||
"puppeteer": "^15.5.0",
|
||||
"puppeteer": "^18.0.5",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "^2.57.0",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
|
|
|
@ -23,7 +23,7 @@ Then either require (Node.js CJS):
|
|||
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)
|
||||
> **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 !
|
||||
|
@ -52,11 +52,11 @@ const a = BigInt('5')
|
|||
const b = BigInt('2')
|
||||
const n = 19n
|
||||
|
||||
console.log(bigintModArith.modPow(a, b, n)) // prints 6
|
||||
console.log({{PKG_CAMELCASE}}.modPow(a, b, n)) // prints 6
|
||||
|
||||
console.log(bigintModArith.modInv(2n, 5n)) // prints 3
|
||||
console.log({{PKG_CAMELCASE}}.modInv(2n, 5n)) // prints 3
|
||||
|
||||
console.log(bigintModArith.modInv(BigInt('3'), BigInt('5'))) // prints 2
|
||||
console.log({{PKG_CAMELCASE}}.modInv(BigInt('3'), BigInt('5'))) // prints 2
|
||||
```
|
||||
|
||||
## API reference documentation
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Returns the bitlength of a number
|
||||
* Returns the (minimum) length of a number expressed in bits.
|
||||
*
|
||||
* @param a
|
||||
* @returns The bit length
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as bma from '#pkg'
|
||||
|
||||
describe('abs', function () {
|
||||
const inputs = [
|
||||
{
|
||||
|
@ -20,7 +22,7 @@ describe('abs', function () {
|
|||
for (const input of inputs) {
|
||||
describe(`abs(${input.value})`, function () {
|
||||
it(`should return ${input.abs}`, function () {
|
||||
const ret = _pkg.abs(input.value)
|
||||
const ret = bma.abs(input.value)
|
||||
chai.expect(ret).to.equal(input.abs)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as bma from '#pkg'
|
||||
|
||||
describe('bitLength', function () {
|
||||
const inputs = [
|
||||
{
|
||||
|
@ -21,7 +23,7 @@ describe('bitLength', function () {
|
|||
for (const input of inputs) {
|
||||
describe(`bitLength(${input.value})`, function () {
|
||||
it(`should return ${input.bitLength}`, function () {
|
||||
const ret = _pkg.bitLength(input.value)
|
||||
const ret = bma.bitLength(input.value)
|
||||
chai.expect(ret).to.equal(input.bitLength)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as bma from '#pkg'
|
||||
|
||||
describe('egcd', function () {
|
||||
const inputs = [
|
||||
{
|
||||
|
@ -31,7 +33,7 @@ describe('egcd', function () {
|
|||
for (const input of inputs) {
|
||||
describe(`eGcd(${input.a}, ${input.b})`, function () {
|
||||
it('should return the egcd', function () {
|
||||
const ret = _pkg.eGcd(input.a, input.b)
|
||||
const ret = bma.eGcd(input.a, input.b)
|
||||
chai.expect(ret).to.eql(input.egcd)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as bma from '#pkg'
|
||||
|
||||
describe('gcd', function () {
|
||||
const inputs = [
|
||||
{
|
||||
|
@ -49,7 +51,7 @@ describe('gcd', function () {
|
|||
for (const input of inputs) {
|
||||
describe(`gcd(${input.a}, ${input.b})`, function () {
|
||||
it(`should return ${input.gcd}`, function () {
|
||||
const ret = _pkg.gcd(input.a, input.b)
|
||||
const ret = bma.gcd(input.a, input.b)
|
||||
chai.expect(ret).to.equal(input.gcd)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as bma from '#pkg'
|
||||
|
||||
describe('lcm', function () {
|
||||
const inputs = [
|
||||
{
|
||||
|
@ -34,7 +36,7 @@ describe('lcm', function () {
|
|||
for (const input of inputs) {
|
||||
describe(`lcm(${input.a}, ${input.b})`, function () {
|
||||
it(`should return ${input.lcm}`, function () {
|
||||
const ret = _pkg.lcm(input.a, input.b)
|
||||
const ret = bma.lcm(input.a, input.b)
|
||||
chai.expect(ret).to.equal(input.lcm)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as bma from '#pkg'
|
||||
|
||||
describe('max', function () {
|
||||
const inputs = [
|
||||
{
|
||||
|
@ -76,7 +78,7 @@ describe('max', function () {
|
|||
for (const input of inputs) {
|
||||
describe(`max(${input.value[0]}, ${input.value[1]})`, function () {
|
||||
it(`should return ${input.max}`, function () {
|
||||
const ret = _pkg.max(input.value[0], input.value[1])
|
||||
const ret = bma.max(input.value[0], input.value[1])
|
||||
chai.expect(ret).to.equal(input.max)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as bma from '#pkg'
|
||||
|
||||
describe('min', function () {
|
||||
const inputs = [
|
||||
{
|
||||
|
@ -76,7 +78,7 @@ describe('min', function () {
|
|||
for (const input of inputs) {
|
||||
describe(`min(${input.value[0]}, ${input.value[1]})`, function () {
|
||||
it(`should return ${input.min}`, function () {
|
||||
const ret = _pkg.min(input.value[0], input.value[1])
|
||||
const ret = bma.min(input.value[0], input.value[1])
|
||||
chai.expect(ret).to.equal(input.min)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as bma from '#pkg'
|
||||
|
||||
describe('modInv', function () {
|
||||
const inputs = [
|
||||
{
|
||||
|
@ -33,7 +35,7 @@ describe('modInv', function () {
|
|||
for (const input of inputs) {
|
||||
describe(`modInv(${input.a}, ${input.n})`, function () {
|
||||
it(`should return ${input.modInv}`, function () {
|
||||
const ret = _pkg.modInv(input.a, input.n)
|
||||
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))
|
||||
})
|
||||
|
@ -43,7 +45,7 @@ describe('modInv', function () {
|
|||
describe(`modInv(${input.a}, ${input.n})`, function () {
|
||||
it('should throw RangeError', function () {
|
||||
try {
|
||||
_pkg.modInv(input.a, input.n)
|
||||
bma.modInv(input.a, input.n)
|
||||
throw new Error('should have failed')
|
||||
} catch (err) {
|
||||
chai.expect(err).to.be.instanceOf(RangeError)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as bma from '#pkg'
|
||||
|
||||
describe('modPow', function () {
|
||||
const inputs = [
|
||||
{
|
||||
|
@ -43,7 +45,7 @@ describe('modPow', function () {
|
|||
for (const input of inputs) {
|
||||
describe(`modPow(${input.a}, ${input.b}, ${input.n})`, function () {
|
||||
it(`should return ${input.modPow}`, function () {
|
||||
const ret = _pkg.modPow(input.a, input.b, input.n)
|
||||
const ret = bma.modPow(input.a, input.b, input.n)
|
||||
chai.expect(String(ret)).to.equal(String(input.modPow))
|
||||
})
|
||||
})
|
||||
|
@ -52,7 +54,7 @@ describe('modPow', function () {
|
|||
describe(`modPow(${input.a}, ${input.b}, ${input.n})`, function () {
|
||||
it('should throw RangeError', function () {
|
||||
try {
|
||||
_pkg.modPow(input.a, input.b, input.n)
|
||||
bma.modPow(input.a, input.b, input.n)
|
||||
throw new Error('should have failed')
|
||||
} catch (err) {
|
||||
chai.expect(err).to.be.instanceOf(RangeError)
|
||||
|
@ -67,7 +69,7 @@ describe('modPow', function () {
|
|||
const b = BigInt('313632271690673451924314047671460131678794095260951233878123501752357966284491455239133687519908410656818506813151659324961829045286402303082891913186909806785080978448037486178337722667190743610785429936585699831407575170854873682955317589189564880931807976657385223632835801016017549762825562427694700595')
|
||||
const e = BigInt('452149997592306202232720864363485824701879487303880767747217308770351197801836846325633986474037061753983278534192061455638289551714281047915315943771002615269860312318606105460307037327329178890486613832051027105330475852552183444938408408863970975090778239473049899109989825645608770309107015209564444316')
|
||||
while (iterations > 0) {
|
||||
_pkg.modPow(b, e, p)
|
||||
bma.modPow(b, e, p)
|
||||
iterations--
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as bma from '#pkg'
|
||||
|
||||
describe('toZn', function () {
|
||||
const inputs = [
|
||||
{
|
||||
|
@ -26,7 +28,7 @@ describe('toZn', function () {
|
|||
for (const input of inputs) {
|
||||
describe(`toZn(${input.a}, ${input.n})`, function () {
|
||||
it(`should return ${input.toZn}`, function () {
|
||||
const ret = _pkg.toZn(input.a, input.n)
|
||||
const ret = bma.toZn(input.a, input.n)
|
||||
chai.expect(ret).to.equal(input.toZn)
|
||||
})
|
||||
})
|
||||
|
@ -35,7 +37,7 @@ describe('toZn', function () {
|
|||
describe(`toZn(${input.a}, ${input.n})`, function () {
|
||||
it('should throw RangeError', function () {
|
||||
try {
|
||||
_pkg.toZn(input.a, input.n)
|
||||
bma.toZn(input.a, input.n)
|
||||
throw new Error('should have failed')
|
||||
} catch (err) {
|
||||
chai.expect(err).to.be.instanceOf(RangeError)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||
"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 */
|
||||
|
@ -35,7 +36,10 @@
|
|||
/* Advanced Options */
|
||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"include": ["src/ts/**/*", "test/**/*", "build/typings/**/*.d.ts"]
|
||||
"resolveJsonModule": true,
|
||||
"paths": {
|
||||
"#pkg": ["."]
|
||||
}
|
||||
},
|
||||
"include": ["src/ts/**/*", "build/typings/**/*.d.ts", "test/**/*", "test-vectors/**/*.ts", "benchmark/**/*.ts"]
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Returns the bitlength of a number
|
||||
* Returns the (minimum) length of a number expressed in bits.
|
||||
*
|
||||
* @param a
|
||||
* @returns The bit length
|
||||
|
|
Loading…
Reference in New Issue