support for node16 and nodenext module resolution
This commit is contained in:
parent
6894e72264
commit
d1da4b2894
|
@ -9,6 +9,28 @@ const rimraf = require('rimraf')
|
|||
|
||||
const rootDir = path.join(__dirname, '..')
|
||||
|
||||
const templateFilePath = path.join(rootDir, pkgJson.directories.src, 'docs/index.md')
|
||||
let template = fs.readFileSync(templateFilePath, { encoding: 'utf-8' })
|
||||
|
||||
async function main () {
|
||||
// Generate API doc with typedoc
|
||||
await typedoc()
|
||||
|
||||
// Translate relaitive links to project's root
|
||||
replaceRelativeLinks()
|
||||
|
||||
// Let us replace variables and badges
|
||||
variableReplacements()
|
||||
|
||||
const readmeFile = path.join(rootDir, 'README.md')
|
||||
fs.writeFileSync(readmeFile, template)
|
||||
}
|
||||
|
||||
main()
|
||||
/* ------------------------------------------------------------------------- |
|
||||
| UTILITY FUNCTIONS |
|
||||
| ------------------------------------------------------------------------- */
|
||||
|
||||
function camelise (str) {
|
||||
return str.replace(/-([a-z])/g,
|
||||
function (m, w) {
|
||||
|
@ -16,13 +38,13 @@ function camelise (str) {
|
|||
})
|
||||
}
|
||||
|
||||
const tsConfigPath = path.join(rootDir, 'tsconfig.json')
|
||||
const tempTsConfigPath = path.join(rootDir, '.tsconfig.json')
|
||||
|
||||
async function typedoc () {
|
||||
const app = new TypeDoc.Application()
|
||||
|
||||
// prepare tsconfig
|
||||
const tsConfigPath = path.join(rootDir, 'tsconfig.json')
|
||||
const tempTsConfigPath = path.join(rootDir, '.tsconfig.json')
|
||||
|
||||
const tsConfig = json5.parse(fs.readFileSync(tsConfigPath, 'utf8'))
|
||||
tsConfig.include = ['src/ts/**/*', 'build/typings/**/*.d.ts']
|
||||
tsConfig.exclude = ['src/**/*.spec.ts']
|
||||
|
@ -30,7 +52,7 @@ async function typedoc () {
|
|||
|
||||
// If you want TypeDoc to load tsconfig.json / typedoc.json files
|
||||
app.options.addReader(new TypeDoc.TSConfigReader())
|
||||
app.options.addReader(new TypeDoc.TypeDocReader())
|
||||
// app.options.addReader(new TypeDoc.TypeDocReader())
|
||||
|
||||
app.bootstrap({
|
||||
// typedoc options here
|
||||
|
@ -53,57 +75,80 @@ async function typedoc () {
|
|||
// Rendered docs
|
||||
await app.generateDocs(project, output)
|
||||
}
|
||||
|
||||
rimraf.sync(tempTsConfigPath)
|
||||
}
|
||||
|
||||
function getRepositoryData () {
|
||||
let ret
|
||||
if (typeof pkgJson.repository === 'string') {
|
||||
const repodata = pkgJson.repository.split(/[:/]/)
|
||||
const repoProvider = repodata[0]
|
||||
if (repoProvider === 'github' || repoProvider === 'gitlab' || repoProvider === 'bitbucket') {
|
||||
return {
|
||||
ret = {
|
||||
repoProvider,
|
||||
repoUsername: repodata[1],
|
||||
repoName: repodata.slice(2).join('/')
|
||||
}
|
||||
} else return null
|
||||
} else {
|
||||
if (pkgJson.repository.url !== 'undefined') {
|
||||
}
|
||||
} else if (typeof pkgJson.repository === 'object' && pkgJson.repository.type === 'git' && pkgJson.repository.url !== 'undefined') {
|
||||
const regex = /(?:.+?\+)?http[s]?:\/\/(?<repoProvider>[\w._-]+)\.\w{2,3}\/(?<repoUsername>[\w._-]+)\/(?<repoName>[\w._\-/]+?)\.git/
|
||||
const match = pkgJson.repository.url.match(regex)
|
||||
return {
|
||||
ret = {
|
||||
repoProvider: match[1],
|
||||
repoUsername: match[2],
|
||||
repoName: match[3]
|
||||
repoName: match[3],
|
||||
repoDirectory: pkgJson.repository.directory
|
||||
}
|
||||
}
|
||||
if (typeof ret === 'object') {
|
||||
if (typeof pkgJson.nodeBrowserSkel === 'object' && typeof pkgJson.nodeBrowserSkel.git === 'object' && typeof pkgJson.nodeBrowserSkel.git.branch === 'string') {
|
||||
ret.branch = pkgJson.nodeBrowserSkel.git.branch
|
||||
} else {
|
||||
ret.branch = (ret.repoProvider === 'github') ? 'main' : 'master'
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
const { repoProvider, repoUsername, repoName } = getRepositoryData() || { repoProvider: null, repoUsername: null, repoName: null }
|
||||
function variableReplacements () {
|
||||
const { repoProvider, repoUsername, repoName, repoDirectory, branch } = getRepositoryData() || {}
|
||||
|
||||
const regex = /^(?:(?<scope>@.*?)\/)?(?<name>.*)/ // We are going to take only the package name part if there is a scope, e.g. @my-org/package-name
|
||||
const { name } = pkgJson.name.match(regex).groups
|
||||
const camelCaseName = camelise(name)
|
||||
|
||||
const iifeBundlePath = path.relative('.', pkgJson.exports['./iife-browser-bundle'])
|
||||
const esmBundlePath = path.relative('.', pkgJson.exports['./esm-browser-bundle'])
|
||||
const umdBundlePath = path.relative('.', pkgJson.exports['./umd-browser-bundle'])
|
||||
const iifeBundlePath = pkgJson.exports['./iife-browser-bundle'] !== undefined ? path.relative('.', pkgJson.exports['./iife-browser-bundle']) : undefined
|
||||
const esmBundlePath = pkgJson.exports['./esm-browser-bundle'] !== undefined ? path.relative('.', pkgJson.exports['./esm-browser-bundle']) : undefined
|
||||
const umdBundlePath = pkgJson.exports['./umd-browser-bundle'] !== undefined ? path.relative('.', pkgJson.exports['./umd-browser-bundle']) : undefined
|
||||
|
||||
let 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
|
||||
|
||||
let iifeBundle, esmBundle, umdBundle, workflowBadget, coverallsBadge
|
||||
if (repoProvider) {
|
||||
switch (repoProvider) {
|
||||
case 'github':
|
||||
iifeBundle = `[IIFE bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/main/${iifeBundlePath})`
|
||||
esmBundle = `[ESM bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/main/${esmBundlePath})`
|
||||
umdBundle = `[UMD bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/main/${umdBundlePath})`
|
||||
workflowBadget = `[![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)`
|
||||
coverallsBadge = `[![Coverage Status](https://coveralls.io/repos/github/${repoUsername}/${repoName}/badge.svg?branch=main)](https://coveralls.io/github/${repoUsername}/${repoName}?branch=main)`
|
||||
iifeBundle = iifeBundlePath !== undefined ? `[IIFE bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${iifeBundlePath})` : undefined
|
||||
esmBundle = esmBundlePath !== undefined ? `[ESM bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${esmBundlePath})` : undefined
|
||||
umdBundle = umdBundlePath !== undefined ? `[UMD bundle](https://raw.githubusercontent.com/${repoUsername}/${repoName}/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${umdBundlePath})` : undefined
|
||||
workflowBadge = useWorkflowBadge ? `[![Node.js CI](https://github.com/${repoUsername}/${repoName}/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/${repoUsername}/${repoName}/actions/workflows/build-and-test.yml)` : undefined
|
||||
coverallsBadge = useCoverallsBadge ? `[![Coverage Status](https://coveralls.io/repos/github/${repoUsername}/${repoName}/badge.svg?branch=${branch})](https://coveralls.io/github/${repoUsername}/${repoName}?branch=${branch})` : undefined
|
||||
break
|
||||
|
||||
case 'gitlab':
|
||||
iifeBundle = `[IIFE bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/master/${iifeBundlePath}?inline=false)`
|
||||
esmBundle = `[ESM bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/master/${esmBundlePath}?inline=false)`
|
||||
umdBundle = `[UMD bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/master/${umdBundlePath}?inline=false)`
|
||||
iifeBundle = iifeBundlePath !== undefined ? `[IIFE bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${iifeBundlePath}?inline=false)` : undefined
|
||||
esmBundle = esmBundlePath !== undefined ? `[ESM bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${esmBundlePath}?inline=false)` : undefined
|
||||
umdBundle = umdBundlePath !== undefined ? `[UMD bundle](https://gitlab.com/${repoUsername}/${repoName}/-/raw/${branch}/${repoDirectory !== undefined ? repoDirectory + '/' : ''}${umdBundlePath}?inline=false)` : undefined
|
||||
break
|
||||
|
||||
default:
|
||||
|
@ -111,23 +156,49 @@ if (repoProvider) {
|
|||
}
|
||||
}
|
||||
|
||||
const templateFile = path.join(rootDir, pkgJson.directories.src, 'docs/index.md')
|
||||
let template = fs.readFileSync(templateFile, { encoding: 'UTF-8' })
|
||||
template = template
|
||||
.replace(/\{\{PKG_NAME\}\}/g, pkgJson.name)
|
||||
.replace(/\{\{PKG_LICENSE\}\}/g, pkgJson.license.replace('-', '_'))
|
||||
.replace(/\{\{PKG_DESCRIPTION\}\}/g, pkgJson.description)
|
||||
.replace(/\{\{PKG_CAMELCASE\}\}/g, camelCaseName)
|
||||
.replace(/\{\{IIFE_BUNDLE\}\}/g, iifeBundle || 'IIFE bundle')
|
||||
.replace(/\{\{ESM_BUNDLE\}\}/g, esmBundle || 'ESM bundle')
|
||||
.replace(/\{\{UMD_BUNDLE\}\}/g, umdBundle || 'UMD bundle')
|
||||
|
||||
if (repoProvider && repoProvider === 'github') {
|
||||
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}/g, workflowBadget + '\n' + coverallsBadge)
|
||||
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}\n/gs, (workflowBadge ? `${workflowBadge}\n` : '') + (coverallsBadge ? `${coverallsBadge}\n` : ''))
|
||||
} else {
|
||||
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}/g, '')
|
||||
template = template.replace(/\{\{GITHUB_ACTIONS_BADGES\}\}\n/gs, '')
|
||||
}
|
||||
}
|
||||
|
||||
const readmeFile = path.join(rootDir, 'README.md')
|
||||
fs.writeFileSync(readmeFile, template)
|
||||
|
||||
typedoc()
|
||||
|
||||
rimraf.sync(tempTsConfigPath)
|
||||
function replaceRelativeLinks () {
|
||||
const replacements = []
|
||||
const relativePathRegex = /(\[[\w\s\d]+\]\()(?!(?:http:\/\/)|(?:https:\/\/))([\w\d;,/?:@&=+$-_.!~*'()\\#]+)\)/g
|
||||
const matches = template.matchAll(relativePathRegex)
|
||||
if (matches) {
|
||||
for (const match of matches) {
|
||||
const index = (match.index ?? 0) + match[1].length
|
||||
const filepath = match[2]
|
||||
if (!path.isAbsolute(filepath)) {
|
||||
const absoluteFilePath = path.join(path.dirname(templateFilePath), filepath)
|
||||
if (!fs.existsSync(absoluteFilePath)) {
|
||||
console.warn(`File ${absoluteFilePath} is linked in your index.md but it does not exist. Ignoring`)
|
||||
} else {
|
||||
const replacement = path.relative(rootDir, absoluteFilePath)
|
||||
replacements.push({ index, length: filepath.length, replacement })
|
||||
}
|
||||
}
|
||||
}
|
||||
const sortedReplacements = replacements.sort((a, b) => a.index - b.index)
|
||||
let ret = ''
|
||||
let index = 0
|
||||
for (const replacement of sortedReplacements) {
|
||||
ret += template.slice(index, replacement.index)
|
||||
ret += replacement.replacement
|
||||
index = replacement.index + replacement.length
|
||||
}
|
||||
ret += template.slice(index)
|
||||
template = ret
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { mkdirSync, readFileSync, writeFileSync } from 'fs'
|
||||
import ts from 'typescript'
|
||||
import { join, dirname } from 'path'
|
||||
import { join, dirname, extname } from 'path'
|
||||
import { sync } from 'rimraf'
|
||||
import * as url from 'url'
|
||||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
||||
|
||||
const { readJsonConfigFile, sys, parseJsonSourceFileConfigFileContent, createCompilerHost, createProgram } = ts
|
||||
|
||||
|
@ -31,6 +33,15 @@ const host = createCompilerHost(compilerOptions)
|
|||
host.writeFile = (fileName, contents) => {
|
||||
mkdirSync(dirname(fileName), { recursive: true })
|
||||
writeFileSync(fileName, contents)
|
||||
|
||||
// we also write the .d.cts types
|
||||
let fileName2 = ''
|
||||
if (extname(fileName) === '.ts') {
|
||||
fileName2 = fileName.slice(0, -2) + 'cts'
|
||||
} else { // ext is .d.ts.map
|
||||
fileName2 = fileName.slice(0, -6) + 'cts.map'
|
||||
}
|
||||
writeFileSync(fileName2, contents)
|
||||
}
|
||||
|
||||
export const compile = () => {
|
||||
|
|
|
@ -1,19 +1,25 @@
|
|||
'use strict'
|
||||
|
||||
import inject from '@rollup/plugin-inject'
|
||||
import { nodeResolve as resolve } from '@rollup/plugin-node-resolve'
|
||||
import replace from '@rollup/plugin-replace'
|
||||
import { terser } from 'rollup-plugin-terser'
|
||||
import terser from '@rollup/plugin-terser'
|
||||
import typescriptPlugin from '@rollup/plugin-typescript'
|
||||
import commonjs from '@rollup/plugin-commonjs'
|
||||
import json from '@rollup/plugin-json'
|
||||
|
||||
import { dirname, join } from 'path'
|
||||
import { existsSync } from 'fs-extra'
|
||||
import { directories, name as _name, exports } from '../package.json'
|
||||
import { existsSync, readFileSync } from 'fs'
|
||||
|
||||
// import { browser, name as _name, exports } from '../package.json' assert { type: 'json' }
|
||||
import { compile } from './rollup-plugin-dts.js'
|
||||
|
||||
import * as url from 'url'
|
||||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
||||
|
||||
const rootDir = join(__dirname, '..')
|
||||
const dstDir = join(rootDir, directories.dist)
|
||||
const pkgJson = JSON.parse(readFileSync(join(rootDir, 'package.json')))
|
||||
// const dstDir = join(rootDir, directories.dist)
|
||||
const srcDir = join(rootDir, 'src', 'ts')
|
||||
|
||||
function camelise (str) {
|
||||
|
@ -24,7 +30,7 @@ function camelise (str) {
|
|||
}
|
||||
|
||||
const regex = /^(?:(?<scope>@.*?)\/)?(?<name>.*)/ // We are going to take only the package name part if there is a scope, e.g. @my-org/package-name
|
||||
const { name } = _name.match(regex).groups
|
||||
const { name } = pkgJson.name.match(regex).groups
|
||||
const pkgCamelisedName = camelise(name)
|
||||
|
||||
const input = join(srcDir, 'index.ts')
|
||||
|
@ -53,57 +59,18 @@ function compileDts () {
|
|||
|
||||
export default [
|
||||
{ // Browser ESM bundle
|
||||
input: input,
|
||||
input,
|
||||
output: [
|
||||
{
|
||||
file: join(rootDir, exports['.'].default),
|
||||
file: join(rootDir, pkgJson.browser),
|
||||
...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({
|
||||
IS_BROWSER: true,
|
||||
_MODULE_TYPE: "'ESM'",
|
||||
preventAssignment: true
|
||||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
|
@ -116,14 +83,61 @@ export default [
|
|||
json()
|
||||
]
|
||||
},
|
||||
{ // Node CJS
|
||||
input: input,
|
||||
{ // Browser bundles
|
||||
input,
|
||||
output: [
|
||||
{
|
||||
file: join(rootDir, exports['.'].node.require),
|
||||
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,
|
||||
_MODULE_TYPE: "'BUNDLE'",
|
||||
preventAssignment: true
|
||||
}),
|
||||
typescriptPlugin({
|
||||
...tsBundleOptions,
|
||||
sourceMap: false
|
||||
}),
|
||||
resolve({
|
||||
browser: true,
|
||||
exportConditions: ['browser', 'default'],
|
||||
mainFields: ['browser', 'module', 'main']
|
||||
}),
|
||||
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
|
||||
json()
|
||||
]
|
||||
},
|
||||
{ // Node CJS
|
||||
input,
|
||||
output: [
|
||||
{
|
||||
file: join(rootDir, pkgJson.exports['.'].node.require.default),
|
||||
...sourcemapOutputOptions,
|
||||
format: 'cjs',
|
||||
exports: 'auto'
|
||||
exports: 'auto',
|
||||
plugins: [
|
||||
terser()
|
||||
]
|
||||
}
|
||||
],
|
||||
plugins: [
|
||||
|
@ -134,37 +148,48 @@ export default [
|
|||
}),
|
||||
replace({
|
||||
IS_BROWSER: false,
|
||||
_MODULE_TYPE: "'CJS'",
|
||||
preventAssignment: true
|
||||
}),
|
||||
inject({
|
||||
crypto: ['crypto', 'webcrypto']
|
||||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
resolve({
|
||||
browser: false,
|
||||
exportConditions: ['require', 'node', 'module', 'import']
|
||||
exportConditions: ['require', 'node', 'module']
|
||||
}),
|
||||
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
|
||||
json()
|
||||
]
|
||||
},
|
||||
{ // Node ESM and type declarations
|
||||
input: input,
|
||||
input,
|
||||
output: [
|
||||
{
|
||||
file: join(rootDir, exports['.'].node.import),
|
||||
file: join(rootDir, pkgJson.exports['.'].node.import.default),
|
||||
...sourcemapOutputOptions,
|
||||
format: 'es'
|
||||
format: 'es',
|
||||
plugins: [
|
||||
terser()
|
||||
]
|
||||
}
|
||||
],
|
||||
plugins: [
|
||||
replace({
|
||||
IS_BROWSER: false,
|
||||
__filename: `'${exports['.'].node.import}'`,
|
||||
__dirname: `'${dirname(exports['.'].node.import)}'`,
|
||||
_MODULE_TYPE: "'ESM'",
|
||||
__filename: `'${pkgJson.exports['.'].node.import.default}'`,
|
||||
__dirname: `'${dirname(pkgJson.exports['.'].node.import.default)}'`,
|
||||
preventAssignment: true
|
||||
}),
|
||||
inject({
|
||||
crypto: ['crypto', 'webcrypto']
|
||||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
resolve({
|
||||
browser: false,
|
||||
exportConditions: ['node']
|
||||
exportConditions: ['node', 'import']
|
||||
}),
|
||||
compileDts(),
|
||||
commonjs({ extensions: ['.js', '.cjs', '.ts', '.jsx', '.cjsx', '.tsx'] }), // the ".ts" extension is required
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 326 B |
|
@ -4,6 +4,7 @@ const puppeteer = require('puppeteer')
|
|||
const minimatch = require('minimatch')
|
||||
const glob = require('glob')
|
||||
const rootDir = path.join(__dirname, '../../..')
|
||||
const pkgJson = require(path.join(rootDir, 'package.json'))
|
||||
|
||||
const browserTests = async (
|
||||
{
|
||||
|
@ -21,12 +22,7 @@ const browserTests = async (
|
|||
const browser = await puppeteer.launch(puppeteerOptions)
|
||||
const page = (await browser.pages())[0]
|
||||
page.on('console', function (message) {
|
||||
let ignore = message.type() === 'warning' && !logWarnings
|
||||
if (message.type() === 'error' && message.location()) {
|
||||
if (message.location().url.includes('favicon.ico')) {
|
||||
ignore = true
|
||||
}
|
||||
}
|
||||
const ignore = message.type() === 'warning' && !logWarnings
|
||||
if (ignore) return
|
||||
|
||||
let text = (message.args().length > 0) ? message.args()[0].remoteObject().value : message.text()
|
||||
|
@ -83,12 +79,15 @@ const browserTests = async (
|
|||
|
||||
function processedTestFiles (testFilesStr) {
|
||||
if (testFilesStr === undefined) {
|
||||
return undefined
|
||||
}
|
||||
testFilesStr = [pkgJson.directories.test + '/**/*.ts', pkgJson.directories.src + '/**/*.spec.ts']
|
||||
} else {
|
||||
// Let us first remove surrounding quotes in string (it gives issues in windows)
|
||||
testFilesStr = testFilesStr.replace(/^['"]/, '').replace(/['"]$/, '')
|
||||
}
|
||||
const filenames = glob.sync(testFilesStr, { cwd: rootDir, matchBase: true })
|
||||
if (filenames.length > 0) {
|
||||
if (filenames.length === 0) {
|
||||
throw new Error('no test files found for ' + testFilesStr)
|
||||
} else {
|
||||
filenames.forEach(file => {
|
||||
const isTsTestFile = minimatch(file, '{test/**/*.ts,src/**/*.spec.ts}', { matchBase: true })
|
||||
if (!isTsTestFile) {
|
||||
|
|
|
@ -9,10 +9,10 @@ require('dotenv').config()
|
|||
const rollup = require('rollup')
|
||||
const resolve = require('@rollup/plugin-node-resolve').nodeResolve
|
||||
const replace = require('@rollup/plugin-replace')
|
||||
const multi = require('@rollup/plugin-multi-entry')
|
||||
const typescriptPlugin = require('@rollup/plugin-typescript')
|
||||
const commonjs = require('@rollup/plugin-commonjs')
|
||||
const json = require('@rollup/plugin-json')
|
||||
const multi = require('@rollup/plugin-multi-entry')
|
||||
const runScript = require('../../run-script.cjs')
|
||||
|
||||
const rootDir = path.join(__dirname, '..', '..', '..')
|
||||
|
@ -49,16 +49,17 @@ const indexHtml = `<!DOCTYPE html>
|
|||
|
||||
const tsBundleOptions = {
|
||||
tsconfig: path.join(rootDir, 'tsconfig.json'),
|
||||
outDir: undefined // ignore outDir in tsconfig.json
|
||||
outDir: undefined, // ignore outDir in tsconfig.json
|
||||
sourceMap: false
|
||||
// include: ['build/typings/is-browser.d.ts']
|
||||
}
|
||||
|
||||
async function buildTests (testFiles) {
|
||||
// create a bundle
|
||||
const input = testFiles ?? [path.join(rootDir, pkgJson.directories.test, '**/*.ts'), path.join(rootDir, pkgJson.directories.src, '**/*.spec.ts')]
|
||||
const inputOptions = {
|
||||
input,
|
||||
input: testFiles,
|
||||
plugins: [
|
||||
multi({ exports: true }),
|
||||
multi(),
|
||||
replace({
|
||||
'#pkg': `/${name}.esm.js`,
|
||||
delimiters: ['', ''],
|
||||
|
@ -66,12 +67,14 @@ async function buildTests (testFiles) {
|
|||
}),
|
||||
replace({
|
||||
IS_BROWSER: true,
|
||||
_MODULE_TYPE: "'ESM'",
|
||||
preventAssignment: true
|
||||
}),
|
||||
typescriptPlugin(tsBundleOptions),
|
||||
resolve({
|
||||
browser: true,
|
||||
exportConditions: ['browser', 'default']
|
||||
exportConditions: ['browser', 'default'],
|
||||
mainFields: ['browser', 'module', 'main']
|
||||
}),
|
||||
commonjs(),
|
||||
json()
|
||||
|
@ -79,7 +82,7 @@ async function buildTests (testFiles) {
|
|||
external: [`/${name}.esm.js`]
|
||||
}
|
||||
const bundle = await rollup.rollup(inputOptions)
|
||||
const { output } = await bundle.generate({ format: 'esm' })
|
||||
const { output } = await bundle.generate({ format: 'es' })
|
||||
await bundle.close()
|
||||
let bundledCode = output[0].code
|
||||
const replacements = _getEnvVarsReplacements(bundledCode)
|
||||
|
@ -97,14 +100,14 @@ class TestServer {
|
|||
|
||||
async init (testFiles) {
|
||||
/** Let us first check if the necessary files are built, and if not, build */
|
||||
if (!fs.existsSync(pkgJson.exports['./esm-browser-bundle'])) {
|
||||
if (!fs.existsSync(pkgJson.exports['./esm-browser-bundle-nomin'])) {
|
||||
await runScript(path.join(rootDir, 'node_modules', '.bin', 'rollup'), ['-c', 'build/rollup.config.js'])
|
||||
}
|
||||
|
||||
const tests = await buildTests(testFiles)
|
||||
this.server.on('request', function (req, res) {
|
||||
if (req.url === `/${name}.esm.js`) {
|
||||
fs.readFile(path.join(rootDir, pkgJson.exports['./esm-browser-bundle']), function (err, data) {
|
||||
fs.readFile(path.join(rootDir, pkgJson.exports['./esm-browser-bundle-nomin']), function (err, data) {
|
||||
if (err) {
|
||||
res.writeHead(404)
|
||||
res.end(JSON.stringify(err))
|
||||
|
@ -129,6 +132,16 @@ class TestServer {
|
|||
res.writeHead(200, { 'Content-Type': 'text/javascript' })
|
||||
res.end(data)
|
||||
})
|
||||
} else if (req.url === '/mocha.js.map') {
|
||||
fs.readFile(path.join(rootDir, 'node_modules/mocha/mocha.js.map'), function (err, data) {
|
||||
if (err) {
|
||||
res.writeHead(404)
|
||||
res.end(JSON.stringify(err))
|
||||
return
|
||||
}
|
||||
res.writeHead(200, { 'Content-Type': 'text/javascript' })
|
||||
res.end(data)
|
||||
})
|
||||
} else if (req.url === '/chai.js' || req.url === '/chai') {
|
||||
fs.readFile(path.join(rootDir, 'node_modules/chai/chai.js'), function (err, data) {
|
||||
if (err) {
|
||||
|
@ -139,6 +152,16 @@ class TestServer {
|
|||
res.writeHead(200, { 'Content-Type': 'text/javascript' })
|
||||
res.end(data)
|
||||
})
|
||||
} else if (req.url === '/favicon.ico') {
|
||||
fs.readFile(path.join(__dirname, 'favicon.ico'), function (err, data) {
|
||||
if (err) {
|
||||
res.writeHead(404)
|
||||
res.end(JSON.stringify(err))
|
||||
return
|
||||
}
|
||||
res.writeHead(200, { 'Content-Type': 'application/ico' })
|
||||
res.end(data)
|
||||
})
|
||||
} else {
|
||||
res.writeHead(404)
|
||||
res.end()
|
||||
|
@ -171,7 +194,7 @@ function _getEnvVarsReplacements (testsCode) {
|
|||
if (process.env[envVar] !== undefined) {
|
||||
replacements[match[0]] = '`' + process.env[envVar] + '`'
|
||||
} else {
|
||||
missingEnvVars.push(envVar)
|
||||
replacements[match[0]] = undefined
|
||||
}
|
||||
}
|
||||
for (const match of testsCode.matchAll(/process\.env\[['"](\w+)['"]\]/g)) {
|
||||
|
@ -179,11 +202,11 @@ function _getEnvVarsReplacements (testsCode) {
|
|||
if (process.env[envVar] !== undefined) {
|
||||
replacements[match[0]] = '`' + process.env[envVar] + '`'
|
||||
} else {
|
||||
missingEnvVars.push(envVar)
|
||||
replacements[match[0]] = undefined
|
||||
}
|
||||
}
|
||||
if (missingEnvVars.length > 0) {
|
||||
throw EvalError('The folloinwg environment variables are missing in your .env file: ' + missingEnvVars)
|
||||
console.warn('The folloinwg environment variables are missing in your .env file and will be replaced with "undefined": ' + [...(new Set(missingEnvVars)).values()].join(', '))
|
||||
}
|
||||
return replacements
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ const fs = require('fs')
|
|||
const path = require('path')
|
||||
|
||||
const rollup = require('rollup')
|
||||
const loadAndParseConfigFile = require('rollup/dist/loadConfigFile')
|
||||
const loadAndParseConfigFile = require('rollup/loadConfigFile').loadConfigFile
|
||||
|
||||
const Builder = require('./Builder.cjs')
|
||||
|
||||
|
@ -27,7 +27,7 @@ class RollupBuilder extends Builder {
|
|||
|
||||
this.watch = watch
|
||||
this.commonjs = commonjs
|
||||
this.watchedModule = commonjs ? pkgJson.exports['.'].node.require : pkgJson.exports['.'].node.import
|
||||
this.watchedModule = commonjs ? pkgJson.exports['.'].node.require.default : pkgJson.exports['.'].node.import.default
|
||||
|
||||
const { options } = await loadAndParseConfigFile(this.configPath)
|
||||
|
||||
|
|
|
@ -30,13 +30,36 @@ function renameJsToCjs (dir, fileList = []) {
|
|||
const files = fs.readdirSync(dir)
|
||||
|
||||
files.forEach(file => {
|
||||
if (fs.statSync(path.join(dir, file)).isDirectory()) {
|
||||
fileList = renameJsToCjs(path.join(dir, file), fileList)
|
||||
const srcFile = path.join(dir, file)
|
||||
if (fs.statSync(srcFile).isDirectory()) {
|
||||
fileList = renameJsToCjs(srcFile, fileList)
|
||||
} else {
|
||||
const match = file.match(/(.*)\.js$/)
|
||||
if (match !== null) {
|
||||
const filename = match[1]
|
||||
fs.renameSync(path.join(dir, file), path.join(dir, `${filename}.cjs`))
|
||||
const dstFile = path.join(dir, `${filename}.cjs`)
|
||||
fs.renameSync(srcFile, dstFile)
|
||||
const fileContents = fs.readFileSync(dstFile, 'utf8')
|
||||
const updatedFileContents = fileContents.replace(/(require\([`'"])(\..*[^.]{5})([`'"])/g, '$1$2.cjs$3')
|
||||
fs.writeFileSync(dstFile, updatedFileContents, { encoding: 'utf8' })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function fixJsonAssertsInESMTests (dir, fileList = []) {
|
||||
const files = fs.readdirSync(dir)
|
||||
|
||||
files.forEach(file => {
|
||||
const srcFile = path.join(dir, file)
|
||||
if (fs.statSync(srcFile).isDirectory()) {
|
||||
fileList = fixJsonAssertsInESMTests(srcFile, fileList)
|
||||
} else {
|
||||
const match = file.match(/(.*)\.js$/)
|
||||
if (match !== null) {
|
||||
const fileContents = fs.readFileSync(srcFile, 'utf8')
|
||||
const updatedFileContents = fileContents.replace(/(import\([`'"]\..*\.json[`'"])\)/g, '$1, { assert: { type: "json" } })')
|
||||
fs.writeFileSync(srcFile, updatedFileContents, { encoding: 'utf8' })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -124,6 +147,8 @@ class TestsBuilder extends Builder {
|
|||
}
|
||||
if (this.commonjs) {
|
||||
renameJsToCjs(mochaTsDir)
|
||||
} else {
|
||||
fixJsonAssertsInESMTests(mochaTsDir)
|
||||
}
|
||||
this.emit('ready', updateSemaphore)
|
||||
} else {
|
||||
|
|
|
@ -27,6 +27,8 @@ let commonjs = setup.commonjs
|
|||
|
||||
commonjs = watch ? true : commonjs // mocha in watch mode only supports commonjs
|
||||
|
||||
global._MODULE_TYPE = commonjs ? 'CJS' : 'ESM'
|
||||
|
||||
exports.mochaGlobalSetup = async function () {
|
||||
if (watch) {
|
||||
await rollupBuilder.start({ commonjs, watch })
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
declare const IS_BROWSER: boolean
|
||||
declare const _MODULE_TYPE: string
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
123
docs/API.md
123
docs/API.md
|
@ -29,8 +29,6 @@
|
|||
|
||||
▸ **abs**(`a`): `number` \| `bigint`
|
||||
|
||||
Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
|
@ -41,11 +39,9 @@ Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0
|
|||
|
||||
`number` \| `bigint`
|
||||
|
||||
The absolute value of a
|
||||
|
||||
#### Defined in
|
||||
|
||||
node_modules/bigint-mod-arith/types/abs.d.ts:8
|
||||
node_modules/bigint-mod-arith/types/abs.d.ts:1
|
||||
|
||||
___
|
||||
|
||||
|
@ -53,8 +49,6 @@ ___
|
|||
|
||||
▸ **bitLength**(`a`): `number`
|
||||
|
||||
Returns the (minimum) length of a number expressed in bits.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
|
@ -65,11 +59,9 @@ Returns the (minimum) length of a number expressed in bits.
|
|||
|
||||
`number`
|
||||
|
||||
The bit length
|
||||
|
||||
#### Defined in
|
||||
|
||||
node_modules/bigint-mod-arith/types/bitLength.d.ts:7
|
||||
node_modules/bigint-mod-arith/types/bitLength.d.ts:1
|
||||
|
||||
___
|
||||
|
||||
|
@ -77,13 +69,6 @@ ___
|
|||
|
||||
▸ **eGcd**(`a`, `b`): `Egcd`
|
||||
|
||||
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 |
|
||||
|
@ -95,11 +80,9 @@ RangeError if a or b are <= 0
|
|||
|
||||
`Egcd`
|
||||
|
||||
A triple (g, x, y), such that ax + by = g = gcd(a, b).
|
||||
|
||||
#### Defined in
|
||||
|
||||
node_modules/bigint-mod-arith/types/egcd.d.ts:17
|
||||
node_modules/bigint-mod-arith/types/egcd.d.ts:6
|
||||
|
||||
___
|
||||
|
||||
|
@ -107,8 +90,6 @@ ___
|
|||
|
||||
▸ **gcd**(`a`, `b`): `bigint`
|
||||
|
||||
Greatest common divisor of two integers based on the iterative binary algorithm.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
|
@ -120,11 +101,9 @@ Greatest common divisor of two integers based on the iterative binary algorithm.
|
|||
|
||||
`bigint`
|
||||
|
||||
The greatest common divisor of a and b
|
||||
|
||||
#### Defined in
|
||||
|
||||
node_modules/bigint-mod-arith/types/gcd.d.ts:9
|
||||
node_modules/bigint-mod-arith/types/gcd.d.ts:1
|
||||
|
||||
___
|
||||
|
||||
|
@ -155,7 +134,7 @@ A promise that resolves to a boolean that is either true (a probably prime numbe
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/isProbablyPrime.ts:20](https://github.com/juanelas/bigint-crypto-utils/blob/e99584a/src/ts/isProbablyPrime.ts#L20)
|
||||
[src/ts/isProbablyPrime.ts:20](https://github.com/juanelas/bigint-crypto-utils/blob/6894e72/src/ts/isProbablyPrime.ts#L20)
|
||||
|
||||
___
|
||||
|
||||
|
@ -163,8 +142,6 @@ ___
|
|||
|
||||
▸ **lcm**(`a`, `b`): `bigint`
|
||||
|
||||
The least common multiple computed as abs(a*b)/gcd(a,b)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
|
@ -176,11 +153,9 @@ The least common multiple computed as abs(a*b)/gcd(a,b)
|
|||
|
||||
`bigint`
|
||||
|
||||
The least common multiple of a and b
|
||||
|
||||
#### Defined in
|
||||
|
||||
node_modules/bigint-mod-arith/types/lcm.d.ts:8
|
||||
node_modules/bigint-mod-arith/types/lcm.d.ts:1
|
||||
|
||||
___
|
||||
|
||||
|
@ -188,8 +163,6 @@ ___
|
|||
|
||||
▸ **max**(`a`, `b`): `number` \| `bigint`
|
||||
|
||||
Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<b
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
|
@ -201,11 +174,9 @@ Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<b
|
|||
|
||||
`number` \| `bigint`
|
||||
|
||||
Maximum of numbers a and b
|
||||
|
||||
#### Defined in
|
||||
|
||||
node_modules/bigint-mod-arith/types/max.d.ts:9
|
||||
node_modules/bigint-mod-arith/types/max.d.ts:1
|
||||
|
||||
___
|
||||
|
||||
|
@ -213,8 +184,6 @@ ___
|
|||
|
||||
▸ **min**(`a`, `b`): `number` \| `bigint`
|
||||
|
||||
Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<b
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
|
@ -226,11 +195,9 @@ Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<b
|
|||
|
||||
`number` \| `bigint`
|
||||
|
||||
Minimum of numbers a and b
|
||||
|
||||
#### Defined in
|
||||
|
||||
node_modules/bigint-mod-arith/types/min.d.ts:9
|
||||
node_modules/bigint-mod-arith/types/min.d.ts:1
|
||||
|
||||
___
|
||||
|
||||
|
@ -238,28 +205,20 @@ ___
|
|||
|
||||
▸ **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 |
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `a` | `number` \| `bigint` |
|
||||
| `n` | `number` \| `bigint` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`bigint`
|
||||
|
||||
The inverse modulo n
|
||||
|
||||
#### Defined in
|
||||
|
||||
node_modules/bigint-mod-arith/types/modInv.d.ts:11
|
||||
node_modules/bigint-mod-arith/types/modInv.d.ts:1
|
||||
|
||||
___
|
||||
|
||||
|
@ -267,29 +226,21 @@ ___
|
|||
|
||||
▸ **modPow**(`b`, `e`, `n`): `bigint`
|
||||
|
||||
Modular exponentiation b**e mod n. Currently using the right-to-left binary method
|
||||
|
||||
**`Throws`**
|
||||
|
||||
RangeError if n <= 0
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `b` | `number` \| `bigint` | base |
|
||||
| `e` | `number` \| `bigint` | exponent |
|
||||
| `n` | `number` \| `bigint` | modulo |
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `b` | `number` \| `bigint` |
|
||||
| `e` | `number` \| `bigint` |
|
||||
| `n` | `number` \| `bigint` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`bigint`
|
||||
|
||||
b**e mod n
|
||||
|
||||
#### Defined in
|
||||
|
||||
node_modules/bigint-mod-arith/types/modPow.d.ts:12
|
||||
node_modules/bigint-mod-arith/types/modPow.d.ts:1
|
||||
|
||||
___
|
||||
|
||||
|
@ -322,7 +273,7 @@ A promise that resolves to a bigint probable prime of bitLength bits.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/prime.ts:28](https://github.com/juanelas/bigint-crypto-utils/blob/e99584a/src/ts/prime.ts#L28)
|
||||
[src/ts/prime.ts:28](https://github.com/juanelas/bigint-crypto-utils/blob/6894e72/src/ts/prime.ts#L28)
|
||||
|
||||
___
|
||||
|
||||
|
@ -352,7 +303,7 @@ A bigint probable prime of bitLength bits.
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/prime.ts:109](https://github.com/juanelas/bigint-crypto-utils/blob/e99584a/src/ts/prime.ts#L109)
|
||||
[src/ts/prime.ts:109](https://github.com/juanelas/bigint-crypto-utils/blob/6894e72/src/ts/prime.ts#L109)
|
||||
|
||||
___
|
||||
|
||||
|
@ -381,7 +332,7 @@ A cryptographically secure random bigint between [min,max]
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/randBetween.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/e99584a/src/ts/randBetween.ts#L14)
|
||||
[src/ts/randBetween.ts:14](https://github.com/juanelas/bigint-crypto-utils/blob/6894e72/src/ts/randBetween.ts#L14)
|
||||
|
||||
___
|
||||
|
||||
|
@ -410,7 +361,7 @@ A Promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cry
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/randBits.ts:13](https://github.com/juanelas/bigint-crypto-utils/blob/e99584a/src/ts/randBits.ts#L13)
|
||||
[src/ts/randBits.ts:13](https://github.com/juanelas/bigint-crypto-utils/blob/6894e72/src/ts/randBits.ts#L13)
|
||||
|
||||
___
|
||||
|
||||
|
@ -439,7 +390,7 @@ A Uint8Array/Buffer (Browser/Node.js) filled with cryptographically secure rando
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/randBits.ts:43](https://github.com/juanelas/bigint-crypto-utils/blob/e99584a/src/ts/randBits.ts#L43)
|
||||
[src/ts/randBits.ts:43](https://github.com/juanelas/bigint-crypto-utils/blob/6894e72/src/ts/randBits.ts#L43)
|
||||
|
||||
___
|
||||
|
||||
|
@ -468,7 +419,7 @@ A promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cry
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/randBytes.ts:13](https://github.com/juanelas/bigint-crypto-utils/blob/e99584a/src/ts/randBytes.ts#L13)
|
||||
[src/ts/randBytes.ts:13](https://github.com/juanelas/bigint-crypto-utils/blob/6894e72/src/ts/randBytes.ts#L13)
|
||||
|
||||
___
|
||||
|
||||
|
@ -498,7 +449,7 @@ A UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure rando
|
|||
|
||||
#### Defined in
|
||||
|
||||
[src/ts/randBytes.ts:54](https://github.com/juanelas/bigint-crypto-utils/blob/e99584a/src/ts/randBytes.ts#L54)
|
||||
[src/ts/randBytes.ts:54](https://github.com/juanelas/bigint-crypto-utils/blob/6894e72/src/ts/randBytes.ts#L54)
|
||||
|
||||
___
|
||||
|
||||
|
@ -506,29 +457,17 @@ ___
|
|||
|
||||
▸ **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 |
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `a` | `number` \| `bigint` |
|
||||
| `n` | `number` \| `bigint` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`bigint`
|
||||
|
||||
A bigint with the smallest positive representation of a modulo n
|
||||
|
||||
#### Defined in
|
||||
|
||||
node_modules/bigint-mod-arith/types/toZn.d.ts:14
|
||||
node_modules/bigint-mod-arith/types/toZn.d.ts:1
|
||||
|
|
File diff suppressed because it is too large
Load Diff
92
package.json
92
package.json
|
@ -25,28 +25,47 @@
|
|||
"node": ">=10.4.0"
|
||||
},
|
||||
"type": "module",
|
||||
"types": "./types/index.d.ts",
|
||||
"main": "./dist/cjs/index.node.cjs",
|
||||
"types": "./types/index.d.cts",
|
||||
"browser": "./dist/esm/index.browser.js",
|
||||
"module": "./dist/esm/index.node.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"node": {
|
||||
"require": "./dist/cjs/index.node.cjs",
|
||||
"import": "./dist/esm/index.node.js",
|
||||
"module": "./dist/esm/index.node.js"
|
||||
"require": {
|
||||
"default": "./dist/cjs/index.node.cjs",
|
||||
"types": "./types/index.d.cts"
|
||||
},
|
||||
"default": "./dist/esm/index.browser.js"
|
||||
"import": {
|
||||
"default": "./dist/esm/index.node.js",
|
||||
"types": "./types/index.d.ts"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"default": "./dist/esm/index.browser.js",
|
||||
"types": "./types/index.d.ts"
|
||||
}
|
||||
},
|
||||
"./esm-browser-bundle": "./dist/bundles/esm.min.js",
|
||||
"./esm-browser-bundle-nomin": "./dist/bundles/esm.js",
|
||||
"./iife-browser-bundle": "./dist/bundles/iife.js",
|
||||
"./umd-browser-bundle": "./dist/bundles/umd.js",
|
||||
"./types": "./types/index.d.ts"
|
||||
"./types": "./types/index.d.cts"
|
||||
},
|
||||
"imports": {
|
||||
"#pkg": {
|
||||
"import": "./dist/esm/index.node.js",
|
||||
"require": "./dist/cjs/index.node.cjs"
|
||||
"require": {
|
||||
"default": "./dist/cjs/index.node.cjs",
|
||||
"types": "./types/index.d.cts"
|
||||
},
|
||||
"import": {
|
||||
"default": "./dist/esm/index.node.js",
|
||||
"types": "./types/index.d.ts"
|
||||
},
|
||||
"default": {
|
||||
"default": "./dist/esm/index.browser.js",
|
||||
"types": "./types/index.d.ts"
|
||||
}
|
||||
}
|
||||
},
|
||||
"directories": {
|
||||
|
@ -59,19 +78,21 @@
|
|||
"mocha-ts": "./.mocha-ts"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "run-s lint build:js docs",
|
||||
"build": "run-s lint:src build:js lint:test docs",
|
||||
"build:js": "rollup -c build/rollup.config.js",
|
||||
"clean": "rimraf .mocha-ts coverage dist types docs",
|
||||
"coverage": "c8 --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 ",
|
||||
"coverage": "c8 --clean --check-coverage --exclude \"{src/ts/**/*.spec.ts,test,test-vectors,build}\" --exclude-after-remap --reporter=text --reporter=lcov node ./build/bin/mocha-ts.cjs --commonjs ",
|
||||
"docs": "node build/build.docs.cjs",
|
||||
"git:add": "git add -A",
|
||||
"lint": "ts-standard --fix",
|
||||
"mocha-ts": "node --experimental-modules --es-module-specifier-resolution=node ./build/bin/mocha-ts.cjs ",
|
||||
"lint:src": "ts-standard --fix \"src/**/!(*.spec).ts\"",
|
||||
"lint:test": "ts-standard --fix \"{test/**/*.ts,src/**/*.spec.ts}\"",
|
||||
"mocha-ts": "node --experimental-modules --experimental-json-modules --es-module-specifier-resolution=node ./build/bin/mocha-ts.cjs ",
|
||||
"mocha-ts:cjs": "node ./build/bin/mocha-ts.cjs --commonjs ",
|
||||
"mocha-ts:watch": "npm run mocha-ts:cjs -- --watch ",
|
||||
"mocha-ts:browser": "node build/testing/browser/index.cjs ",
|
||||
"mocha-ts:browser-headless": "node build/testing/browser/index.cjs headless ",
|
||||
"preversion": "run-s clean lint build:js coverage test:browser-headless",
|
||||
"preversion": "run-s clean lint:src build:js lint:test coverage test:browser-headless",
|
||||
"version": "run-s docs git:add",
|
||||
"postversion": "git push --follow-tags",
|
||||
"test": "run-s test:node test:browser-headless",
|
||||
|
@ -97,39 +118,48 @@
|
|||
"dist/**/*",
|
||||
"examples/**/*",
|
||||
"types/**/*",
|
||||
"build/testing/mocha/mocha-init.js"
|
||||
"benchmark/**/*"
|
||||
]
|
||||
},
|
||||
"nodeBrowserSkel": {
|
||||
"badges": {
|
||||
"workflow": true,
|
||||
"coveralls": true
|
||||
},
|
||||
"git": {
|
||||
"branch": "main"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^22.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-multi-entry": "^4.0.0",
|
||||
"@rollup/plugin-node-resolve": "^14.1.0",
|
||||
"@rollup/plugin-replace": "^4.0.0",
|
||||
"@rollup/plugin-typescript": "^8.2.0",
|
||||
"@rollup/plugin-commonjs": "^24.0.1",
|
||||
"@rollup/plugin-inject": "^5.0.3",
|
||||
"@rollup/plugin-json": "^6.0.0",
|
||||
"@rollup/plugin-multi-entry": "^6.0.0",
|
||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||
"@rollup/plugin-replace": "^5.0.1",
|
||||
"@rollup/plugin-terser": "^0.4.0",
|
||||
"@rollup/plugin-typescript": "^11.1.0",
|
||||
"@types/chai": "^4.2.22",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"c8": "^7.12.0",
|
||||
"chai": "^4.3.3",
|
||||
"dotenv": "^16.0.3",
|
||||
"fs-extra": "^10.1.0",
|
||||
"glob": "^8.0.1",
|
||||
"glob": "^9.3.4",
|
||||
"json5": "^2.2.0",
|
||||
"minimatch": "^5.0.1",
|
||||
"minimatch": "^8.0.3",
|
||||
"mocha": "^10.0.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"pirates": "^4.0.1",
|
||||
"puppeteer": "^18.0.5",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "^2.57.0",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"ts-standard": "^11.0.0",
|
||||
"puppeteer": "^19.1.2",
|
||||
"rimraf": "^4.4.1",
|
||||
"rollup": "^3.20.2",
|
||||
"ts-standard": "^12.0.2",
|
||||
"tslib": "^2.3.1",
|
||||
"typedoc": "^0.23.0",
|
||||
"typedoc-plugin-markdown": "^3.11.0",
|
||||
"typescript": "^4.4.3"
|
||||
"typedoc": "~0.23.0",
|
||||
"typedoc-plugin-markdown": "~3.14.0",
|
||||
"typescript": "^5.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"bigint-mod-arith": "^3.1.0"
|
||||
"bigint-mod-arith": "^3.2.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export { abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn } from 'bigint-mod-arith'
|
||||
|
||||
export { isProbablyPrime } from './isProbablyPrime'
|
||||
export { prime, primeSync } from './prime'
|
||||
export { randBetween } from './randBetween'
|
||||
export { randBits, randBitsSync } from './randBits'
|
||||
export { randBytes, randBytesSync } from './randBytes'
|
||||
export { isProbablyPrime } from './isProbablyPrime.js'
|
||||
export { prime, primeSync } from './prime.js'
|
||||
export { randBetween } from './randBetween.js'
|
||||
export { randBits, randBitsSync } from './randBits.js'
|
||||
export { randBytes, randBytesSync } from './randBytes.js'
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { eGcd, modInv, modPow, toZn, bitLength } from 'bigint-mod-arith'
|
||||
import { fromBuffer } from './fromBuffer'
|
||||
import { randBetween } from './randBetween'
|
||||
import { randBitsSync } from './randBits'
|
||||
import { randBytesSync } from './randBytes'
|
||||
import { _useWorkers, _workerUrl, WorkerToMainMsg, MainToWorkerMsg } from './workerUtils'
|
||||
import { fromBuffer } from './fromBuffer.js'
|
||||
import { randBetween } from './randBetween.js'
|
||||
import { randBitsSync } from './randBits.js'
|
||||
import { randBytesSync } from './randBytes.js'
|
||||
import { _useWorkers, _workerUrl, WorkerToMainMsg, MainToWorkerMsg } from './workerUtils.js'
|
||||
|
||||
/**
|
||||
* The test first tries if any of the first 250 small primes are a factor of the input number and then passes several
|
||||
|
@ -40,7 +40,7 @@ export function isProbablyPrime (w: number|bigint, iterations: number = 16, disa
|
|||
const msg: MainToWorkerMsg = {
|
||||
_bcu: {
|
||||
rnd: w as bigint,
|
||||
iterations: iterations,
|
||||
iterations,
|
||||
id: 0
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ export function isProbablyPrime (w: number|bigint, iterations: number = 16, disa
|
|||
const msg: MainToWorkerMsg = {
|
||||
_bcu: {
|
||||
rnd: w as bigint,
|
||||
iterations: iterations,
|
||||
iterations,
|
||||
id: 0
|
||||
}
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ if (!IS_BROWSER && _useWorkers) { // node.js with support for workers
|
|||
const isPrime = _isProbablyPrime(data._bcu.rnd, data._bcu.iterations)
|
||||
const msg: WorkerToMainMsg = {
|
||||
_bcu: {
|
||||
isPrime: isPrime,
|
||||
isPrime,
|
||||
value: data._bcu.rnd,
|
||||
id: data._bcu.id
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { fromBuffer } from './fromBuffer'
|
||||
import { _isProbablyPrime, _isProbablyPrimeWorkerUrl } from './isProbablyPrime'
|
||||
import { randBits, randBitsSync } from './randBits'
|
||||
import { _useWorkers, WorkerToMainMsg, MainToWorkerMsg } from './workerUtils'
|
||||
import { fromBuffer } from './fromBuffer.js'
|
||||
import { _isProbablyPrime, _isProbablyPrimeWorkerUrl } from './isProbablyPrime.js'
|
||||
import { randBits, randBitsSync } from './randBits.js'
|
||||
import { _useWorkers, WorkerToMainMsg, MainToWorkerMsg } from './workerUtils.js'
|
||||
import type { Worker as NodeWorker } from 'worker_threads'
|
||||
|
||||
if (!IS_BROWSER) var os = await import('os') // eslint-disable-line no-var
|
||||
|
@ -55,8 +55,8 @@ export function prime (bitLength: number, iterations: number = 16): Promise<bigi
|
|||
try {
|
||||
const msgToWorker: MainToWorkerMsg = {
|
||||
_bcu: {
|
||||
rnd: rnd,
|
||||
iterations: iterations,
|
||||
rnd,
|
||||
iterations,
|
||||
id: msg._bcu.id
|
||||
}
|
||||
}
|
||||
|
@ -85,8 +85,8 @@ export function prime (bitLength: number, iterations: number = 16): Promise<bigi
|
|||
const rnd = fromBuffer(buf)
|
||||
workerList[i].postMessage({
|
||||
_bcu: {
|
||||
rnd: rnd,
|
||||
iterations: iterations,
|
||||
rnd,
|
||||
iterations,
|
||||
id: i
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { bitLength } from 'bigint-mod-arith'
|
||||
import { fromBuffer } from './fromBuffer'
|
||||
import { randBitsSync } from './randBits'
|
||||
import { fromBuffer } from './fromBuffer.js'
|
||||
import { randBitsSync } from './randBits.js'
|
||||
|
||||
/**
|
||||
* Returns a cryptographically secure random integer between [min,max].
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { randBytes, randBytesSync } from './randBytes'
|
||||
import { randBytes, randBytesSync } from './randBytes.js'
|
||||
|
||||
/**
|
||||
* Secure random bits for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', 'ES2023', 'ES2023' or 'ESNEXT'. */
|
||||
"module": "ESNext",
|
||||
// "lib": [ "es2020" ], /* Specify library files to be included in the compilation. */
|
||||
"allowJs": true, /* Allow javascript files to be compiled. */
|
||||
|
@ -9,6 +9,7 @@
|
|||
"checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'react', 'react-jsx', 'react-jsxdev', 'preserve' or 'react-native'. */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"removeComments": true,
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
|
@ -21,13 +22,14 @@
|
|||
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDir": ".",
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
"typeRoots": [ "node_modules/@types", "build/typings" ], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
"allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
|
@ -38,7 +40,7 @@
|
|||
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
||||
"resolveJsonModule": true,
|
||||
"paths": {
|
||||
"#pkg": ["."]
|
||||
"#pkg": ["./src/ts/index.ts"]
|
||||
}
|
||||
},
|
||||
"include": ["src/ts/**/*", "build/typings/**/*.d.ts", "test/**/*", "test-vectors/**/*.ts", "benchmark/**/*.ts"]
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
/// <reference types="node" />
|
||||
export declare function fromBuffer(buf: Uint8Array | Buffer): bigint;
|
||||
//# sourceMappingURL=fromBuffer.d.ts.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"fromBuffer.d.ts","sourceRoot":"","sources":["../src/ts/fromBuffer.ts"],"names":[],"mappings":";AAAA,wBAAgB,UAAU,CAAE,GAAG,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAO5D"}
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"fromBuffer.d.ts","sourceRoot":"","sources":["../src/ts/fromBuffer.ts"],"names":[],"mappings":";AAAA,wBAAgB,UAAU,CAAE,GAAG,EAAE,UAAU,GAAC,MAAM,GAAG,MAAM,CAO1D"}
|
||||
{"version":3,"file":"fromBuffer.d.ts","sourceRoot":"","sources":["../src/ts/fromBuffer.ts"],"names":[],"mappings":";AAAA,wBAAgB,UAAU,CAAE,GAAG,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAO5D"}
|
|
@ -0,0 +1,7 @@
|
|||
export { abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn } from 'bigint-mod-arith';
|
||||
export { isProbablyPrime } from './isProbablyPrime.js';
|
||||
export { prime, primeSync } from './prime.js';
|
||||
export { randBetween } from './randBetween.js';
|
||||
export { randBits, randBitsSync } from './randBits.js';
|
||||
export { randBytes, randBytesSync } from './randBytes.js';
|
||||
//# sourceMappingURL=index.d.ts.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/ts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEjG,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@ -1,7 +1,7 @@
|
|||
export { abs, bitLength, eGcd, gcd, lcm, max, min, modInv, modPow, toZn } from 'bigint-mod-arith';
|
||||
export { isProbablyPrime } from './isProbablyPrime';
|
||||
export { prime, primeSync } from './prime';
|
||||
export { randBetween } from './randBetween';
|
||||
export { randBits, randBitsSync } from './randBits';
|
||||
export { randBytes, randBytesSync } from './randBytes';
|
||||
export { isProbablyPrime } from './isProbablyPrime.js';
|
||||
export { prime, primeSync } from './prime.js';
|
||||
export { randBetween } from './randBetween.js';
|
||||
export { randBits, randBitsSync } from './randBits.js';
|
||||
export { randBytes, randBytesSync } from './randBytes.js';
|
||||
//# sourceMappingURL=index.d.ts.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/ts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEjG,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA"}
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/ts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEjG,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@ -0,0 +1,4 @@
|
|||
export declare function isProbablyPrime(w: number | bigint, iterations?: number, disableWorkers?: boolean): Promise<boolean>;
|
||||
export declare function _isProbablyPrime(w: bigint, iterations: number): boolean;
|
||||
export declare function _isProbablyPrimeWorkerUrl(): string;
|
||||
//# sourceMappingURL=isProbablyPrime.d.ts.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"isProbablyPrime.d.ts","sourceRoot":"","sources":["../src/ts/isProbablyPrime.ts"],"names":[],"mappings":"AAmBA,wBAAgB,eAAe,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,UAAU,GAAE,MAAW,EAAE,cAAc,GAAE,OAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CA2D7H;AAED,wBAAgB,gBAAgB,CAAE,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CA0TxE;AAED,wBAAgB,yBAAyB,IAAK,MAAM,CA8BnD"}
|
|
@ -1,15 +1,3 @@
|
|||
/**
|
||||
* The test first tries if any of the first 250 small primes are a factor of the input number and then passes several
|
||||
* iterations of Miller-Rabin Probabilistic Primality Test (FIPS 186-4 C.3.1)
|
||||
*
|
||||
* @param w - A positive integer to be tested for primality
|
||||
* @param iterations - The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3 of FIPS 186-4
|
||||
* @param disableWorkers - Disable the use of workers for the primality test
|
||||
*
|
||||
* @throws {@link RangeError} if w<0
|
||||
*
|
||||
* @returns A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)
|
||||
*/
|
||||
export declare function isProbablyPrime(w: number | bigint, iterations?: number, disableWorkers?: boolean): Promise<boolean>;
|
||||
export declare function _isProbablyPrime(w: bigint, iterations: number): boolean;
|
||||
export declare function _isProbablyPrimeWorkerUrl(): string;
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"isProbablyPrime.d.ts","sourceRoot":"","sources":["../src/ts/isProbablyPrime.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,UAAU,GAAE,MAAW,EAAE,cAAc,GAAE,OAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CA2D7H;AAED,wBAAgB,gBAAgB,CAAE,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CA0TxE;AAED,wBAAgB,yBAAyB,IAAK,MAAM,CA8BnD"}
|
||||
{"version":3,"file":"isProbablyPrime.d.ts","sourceRoot":"","sources":["../src/ts/isProbablyPrime.ts"],"names":[],"mappings":"AAmBA,wBAAgB,eAAe,CAAE,CAAC,EAAE,MAAM,GAAC,MAAM,EAAE,UAAU,GAAE,MAAW,EAAE,cAAc,GAAE,OAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CA2D7H;AAED,wBAAgB,gBAAgB,CAAE,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CA0TxE;AAED,wBAAgB,yBAAyB,IAAK,MAAM,CA8BnD"}
|
|
@ -0,0 +1,3 @@
|
|||
export declare function prime(bitLength: number, iterations?: number): Promise<bigint>;
|
||||
export declare function primeSync(bitLength: number, iterations?: number): bigint;
|
||||
//# sourceMappingURL=prime.d.ts.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"prime.d.ts","sourceRoot":"","sources":["../src/ts/prime.ts"],"names":[],"mappings":"AA2BA,wBAAgB,KAAK,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAoElF;AAaD,wBAAgB,SAAS,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,MAAM,CAO7E"}
|
|
@ -1,28 +1,3 @@
|
|||
/**
|
||||
* A probably-prime (Miller-Rabin), cryptographically-secure, random-number generator.
|
||||
* The browser version uses web workers to parallelise prime look up. Therefore, it does not lock the UI
|
||||
* main process, and it can be much faster (if several cores or cpu are available).
|
||||
* The node version can also use worker_threads if they are available (enabled by default with Node 11 and
|
||||
* and can be enabled at runtime executing node --experimental-worker with node >=10.5.0).
|
||||
*
|
||||
* @param bitLength - The required bit length for the generated prime
|
||||
* @param iterations - The number of iterations for the Miller-Rabin Probabilistic Primality Test
|
||||
*
|
||||
* @throws {@link RangeError} if bitLength < 1
|
||||
*
|
||||
* @returns A promise that resolves to a bigint probable prime of bitLength bits.
|
||||
*/
|
||||
export declare function prime(bitLength: number, iterations?: number): Promise<bigint>;
|
||||
/**
|
||||
* A probably-prime (Miller-Rabin), cryptographically-secure, random-number generator.
|
||||
* The sync version is NOT RECOMMENDED since it won't use workers and thus it'll be slower and may freeze thw window in browser's javascript. Please consider using prime() instead.
|
||||
*
|
||||
* @param bitLength - The required bit length for the generated prime
|
||||
* @param iterations - The number of iterations for the Miller-Rabin Probabilistic Primality Test
|
||||
*
|
||||
* @throws {@link RangeError} if bitLength < 1
|
||||
*
|
||||
* @returns A bigint probable prime of bitLength bits.
|
||||
*/
|
||||
export declare function primeSync(bitLength: number, iterations?: number): bigint;
|
||||
//# sourceMappingURL=prime.d.ts.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"prime.d.ts","sourceRoot":"","sources":["../src/ts/prime.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAoElF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,MAAM,CAO7E"}
|
||||
{"version":3,"file":"prime.d.ts","sourceRoot":"","sources":["../src/ts/prime.ts"],"names":[],"mappings":"AA2BA,wBAAgB,KAAK,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAoElF;AAaD,wBAAgB,SAAS,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,MAAM,CAO7E"}
|
|
@ -0,0 +1,2 @@
|
|||
export declare function randBetween(max: bigint, min?: bigint): bigint;
|
||||
//# sourceMappingURL=randBetween.d.ts.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"randBetween.d.ts","sourceRoot":"","sources":["../src/ts/randBetween.ts"],"names":[],"mappings":"AAaA,wBAAgB,WAAW,CAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAW,GAAG,MAAM,CAUlE"}
|
|
@ -1,11 +1,2 @@
|
|||
/**
|
||||
* Returns a cryptographically secure random integer between [min,max].
|
||||
* @param max Returned value will be <= max
|
||||
* @param min Returned value will be >= min
|
||||
*
|
||||
* @throws {@link RangeError} if max <= min
|
||||
*
|
||||
* @returns A cryptographically secure random bigint between [min,max]
|
||||
*/
|
||||
export declare function randBetween(max: bigint, min?: bigint): bigint;
|
||||
//# sourceMappingURL=randBetween.d.ts.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"randBetween.d.ts","sourceRoot":"","sources":["../src/ts/randBetween.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAW,GAAG,MAAM,CAUlE"}
|
||||
{"version":3,"file":"randBetween.d.ts","sourceRoot":"","sources":["../src/ts/randBetween.ts"],"names":[],"mappings":"AAaA,wBAAgB,WAAW,CAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAW,GAAG,MAAM,CAUlE"}
|
|
@ -0,0 +1,4 @@
|
|||
/// <reference types="node" />
|
||||
export declare function randBits(bitLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>;
|
||||
export declare function randBitsSync(bitLength: number, forceLength?: boolean): Uint8Array | Buffer;
|
||||
//# sourceMappingURL=randBits.d.ts.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"randBits.d.ts","sourceRoot":"","sources":["../src/ts/randBits.ts"],"names":[],"mappings":";AAYA,wBAAgB,QAAQ,CAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,OAAO,CAAC,UAAU,GAAC,MAAM,CAAC,CAmBrG;AAWD,wBAAgB,YAAY,CAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,UAAU,GAAG,MAAM,CAelG"}
|
|
@ -1,23 +1,4 @@
|
|||
/// <reference types="node" />
|
||||
/**
|
||||
* Secure random bits for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
|
||||
*
|
||||
* @param bitLength - The desired number of random bits
|
||||
* @param forceLength - Set to true if you want to force the output to have a specific bit length. It basically forces the msb to be 1
|
||||
*
|
||||
* @throws {@link RangeError} if bitLength < 1
|
||||
*
|
||||
* @returns A Promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bits
|
||||
*/
|
||||
export declare function randBits(bitLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>;
|
||||
/**
|
||||
* Secure random bits for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
|
||||
* @param bitLength - The desired number of random bits
|
||||
* @param forceLength - Set to true if you want to force the output to have a specific bit length. It basically forces the msb to be 1
|
||||
*
|
||||
* @throws {@link RangeError} if bitLength < 1
|
||||
*
|
||||
* @returns A Uint8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bits
|
||||
*/
|
||||
export declare function randBitsSync(bitLength: number, forceLength?: boolean): Uint8Array | Buffer;
|
||||
//# sourceMappingURL=randBits.d.ts.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"randBits.d.ts","sourceRoot":"","sources":["../src/ts/randBits.ts"],"names":[],"mappings":";AAEA;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,OAAO,CAAC,UAAU,GAAC,MAAM,CAAC,CAmBrG;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,UAAU,GAAC,MAAM,CAehG"}
|
||||
{"version":3,"file":"randBits.d.ts","sourceRoot":"","sources":["../src/ts/randBits.ts"],"names":[],"mappings":";AAYA,wBAAgB,QAAQ,CAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,OAAO,CAAC,UAAU,GAAC,MAAM,CAAC,CAmBrG;AAWD,wBAAgB,YAAY,CAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,UAAU,GAAG,MAAM,CAelG"}
|
|
@ -0,0 +1,4 @@
|
|||
/// <reference types="node" />
|
||||
export declare function randBytes(byteLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>;
|
||||
export declare function randBytesSync(byteLength: number, forceLength?: boolean): Uint8Array | Buffer;
|
||||
//# sourceMappingURL=randBytes.d.ts.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"randBytes.d.ts","sourceRoot":"","sources":["../src/ts/randBytes.ts"],"names":[],"mappings":";AAYA,wBAAgB,SAAS,CAAE,UAAU,EAAE,MAAM,EAAE,WAAW,UAAQ,GAAG,OAAO,CAAC,UAAU,GAAC,MAAM,CAAC,CA4B9F;AAaD,wBAAgB,aAAa,CAAE,UAAU,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,UAAU,GAAG,MAAM,CA0BpG"}
|
|
@ -1,25 +1,4 @@
|
|||
/// <reference types="node" />
|
||||
/**
|
||||
* Secure random bytes for both node and browsers. Node version uses crypto.randomBytes() and browser one self.crypto.getRandomValues()
|
||||
*
|
||||
* @param byteLength - The desired number of random bytes
|
||||
* @param forceLength - Set to true if you want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
|
||||
*
|
||||
* @throws {@link RangeError} if byteLength < 1
|
||||
*
|
||||
* @returns A promise that resolves to a UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bytes
|
||||
*/
|
||||
export declare function randBytes(byteLength: number, forceLength?: boolean): Promise<Uint8Array | Buffer>;
|
||||
/**
|
||||
* Secure random bytes for both node and browsers. Node version uses crypto.randomFill() and browser one self.crypto.getRandomValues()
|
||||
* This is the synchronous version, consider using the asynchronous one for improved efficiency.
|
||||
*
|
||||
* @param byteLength - The desired number of random bytes
|
||||
* @param forceLength - Set to true if you want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
|
||||
*
|
||||
* @throws {@link RangeError} if byteLength < 1
|
||||
*
|
||||
* @returns A UInt8Array/Buffer (Browser/Node.js) filled with cryptographically secure random bytes
|
||||
*/
|
||||
export declare function randBytesSync(byteLength: number, forceLength?: boolean): Uint8Array | Buffer;
|
||||
//# sourceMappingURL=randBytes.d.ts.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"randBytes.d.ts","sourceRoot":"","sources":["../src/ts/randBytes.ts"],"names":[],"mappings":";AAEA;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAE,UAAU,EAAE,MAAM,EAAE,WAAW,UAAQ,GAAG,OAAO,CAAC,UAAU,GAAC,MAAM,CAAC,CA4B9F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAE,UAAU,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,UAAU,GAAC,MAAM,CA0BlG"}
|
||||
{"version":3,"file":"randBytes.d.ts","sourceRoot":"","sources":["../src/ts/randBytes.ts"],"names":[],"mappings":";AAYA,wBAAgB,SAAS,CAAE,UAAU,EAAE,MAAM,EAAE,WAAW,UAAQ,GAAG,OAAO,CAAC,UAAU,GAAC,MAAM,CAAC,CA4B9F;AAaD,wBAAgB,aAAa,CAAE,UAAU,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,UAAU,GAAG,MAAM,CA0BpG"}
|
|
@ -0,0 +1,18 @@
|
|||
export declare function _workerUrl(workerCode: string): string;
|
||||
declare let _useWorkers: boolean;
|
||||
export { _useWorkers };
|
||||
export interface WorkerToMainMsg {
|
||||
_bcu: {
|
||||
isPrime: boolean;
|
||||
value: bigint;
|
||||
id: number;
|
||||
};
|
||||
}
|
||||
export interface MainToWorkerMsg {
|
||||
_bcu: {
|
||||
rnd: bigint;
|
||||
iterations: number;
|
||||
id: number;
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=workerUtils.d.ts.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"workerUtils.d.ts","sourceRoot":"","sources":["../src/ts/workerUtils.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAItD;AAED,QAAA,IAAI,WAAW,SAAQ,CAAA;AAiBvB,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE;QACJ,OAAO,EAAE,OAAO,CAAA;QAChB,KAAK,EAAE,MAAM,CAAA;QACb,EAAE,EAAE,MAAM,CAAA;KACX,CAAA;CACF;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE;QACJ,GAAG,EAAE,MAAM,CAAA;QACX,UAAU,EAAE,MAAM,CAAA;QAClB,EAAE,EAAE,MAAM,CAAA;KACX,CAAA;CACF"}
|
Loading…
Reference in New Issue