bigint-mod-arith
Advanced tools
Comparing version 2.0.8 to 2.1.0
100
package.json
{ | ||
"name": "bigint-mod-arith", | ||
"version": "2.0.8", | ||
"version": "2.1.0", | ||
"description": "Some common functions for modular arithmetic using native JS implementation of BigInt", | ||
@@ -23,28 +23,42 @@ "keywords": [ | ||
"repository": "github:juanelas/bigint-mod-arith", | ||
"main": "./lib/index.node.js", | ||
"browser": "./lib/index.browser.mod.js", | ||
"types": "./types/index.d.ts", | ||
"engines": { | ||
"node": ">=10.4.0" | ||
}, | ||
"types": "./dist/esm/types/index.d.ts", | ||
"main": "./dist/cjs/index.node.cjs", | ||
"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" | ||
}, | ||
"default": "./dist/esm/index.browser.js" | ||
}, | ||
"./bundles/": "./dist/bundles/", | ||
"./types/": "./dist/esm/types/" | ||
}, | ||
"directories": { | ||
"build": "./build", | ||
"lib": "./lib", | ||
"dist": "./dist", | ||
"docs": "./docs", | ||
"src": "./src", | ||
"test": "./test", | ||
"types": "./types" | ||
"test": "./test" | ||
}, | ||
"engines": { | ||
"node": ">=10.4.0" | ||
}, | ||
"scripts": { | ||
"test": "nyc --check-coverage mocha", | ||
"coverage": "nyc report --reporter=lcov", | ||
"build": "run-s lint build:js docs test:browser coverage", | ||
"build:js": "rollup -c build/rollup.config.js", | ||
"build:standard": "standard --fix", | ||
"build:browserTests": "rollup -c build/rollup.tests.config.js", | ||
"build:docs": "node build/build.docs.js", | ||
"build:dts": "node build/build.dts.js", | ||
"build": "run-s build:**", | ||
"preversion": "npm run build && npm run test", | ||
"postversion": "git push" | ||
"clean": "rimraf .nyc_output .mocha-ts coverage dist docs", | ||
"coverage": "nyc --check-coverage --exclude build --exclude '{src/**/*.spec.ts,test/**/*.ts}' --reporter=text --reporter=lcov node ./build/bin/mocha-ts.js --require build/testing/mocha/mocha-init.js '{src/**/*.spec.ts,test/**/*.ts}'", | ||
"docs": "node build/build.docs.js", | ||
"lint": "ts-standard --fix", | ||
"mocha": "node ./build/bin/mocha-ts.js --require build/testing/mocha/mocha-init.js ", | ||
"preversion": "npm run build", | ||
"test": "run-s test:browser test:node", | ||
"test:browser": "node build/testing/browser/index.js", | ||
"test:node": "npm run mocha -- '{src/**/*.spec.ts,test/**/*.ts}'", | ||
"watch": "npm run mocha -- --watch '{src/**/*.spec.ts,test/**/*.ts}'" | ||
}, | ||
"standard": { | ||
"ts-standard": { | ||
"env": [ | ||
@@ -54,25 +68,39 @@ "mocha" | ||
"globals": [ | ||
"BigInt" | ||
"IS_BROWSER", | ||
"browser", | ||
"page", | ||
"_pkg", | ||
"chai" | ||
], | ||
"project": "./tsconfig.json", | ||
"ignore": [ | ||
"/test/browser/", | ||
"/lib/index.browser.bundle.iife.js", | ||
"/lib/index.browser.bundle.mod.js" | ||
"dist/**/*" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^11.1.0", | ||
"@rollup/plugin-multi-entry": "^3.0.0", | ||
"@rollup/plugin-node-resolve": "^7.1.3", | ||
"@rollup/plugin-replace": "^2.3.1", | ||
"chai": "^4.2.0", | ||
"jsdoc-to-markdown": "^5.0.3", | ||
"mocha": "^7.1.1", | ||
"@rollup/plugin-commonjs": "^17.0.0", | ||
"@rollup/plugin-multi-entry": "^4.0.0", | ||
"@rollup/plugin-node-resolve": "^11.2.0", | ||
"@rollup/plugin-replace": "^2.4.1", | ||
"@rollup/plugin-typescript": "^8.2.0", | ||
"@types/chai": "^4.2.14", | ||
"@types/mocha": "^8.2.1", | ||
"chai": "^4.3.3", | ||
"glob": "^7.1.6", | ||
"json5": "^2.2.0", | ||
"minimatch": "^3.0.4", | ||
"mocha": "^8.3.0", | ||
"npm-run-all": "^4.1.5", | ||
"nyc": "^15.0.1", | ||
"rollup": "^2.6.1", | ||
"rollup-plugin-terser": "^5.3.0", | ||
"standard": "^14.3.3", | ||
"typescript": "^3.8.3" | ||
"nyc": "^15.1.0", | ||
"pirates": "^4.0.1", | ||
"puppeteer": "^8.0.0", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.40.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"ts-standard": "^10.0.0", | ||
"tslib": "^2.1.0", | ||
"typedoc": "^0.20.29", | ||
"typedoc-plugin-markdown": "^3.6.0", | ||
"typescript": "^4.2.2" | ||
} | ||
} |
221
README.md
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
![Node CI](https://github.com/juanelas/bigint-mod-arith/workflows/Node%20CI/badge.svg) | ||
[![Node CI](https://github.com/juanelas/bigint-mod-arith/workflows/Node%20CI/badge.svg)](https://github.com/juanelas/bigint-mod-arith/actions?query=workflow%3A%22Node+CI%22) | ||
[![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) | ||
@@ -12,53 +12,29 @@ | ||
## Installation | ||
## Usage | ||
bigint-mod-arith is distributed for [web browsers and/or webviews supporting BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) as an ES6 module or an IIFE file; and for Node.js (>=10.4.0), as a CJS module. | ||
`bigint-mod-arith` can be imported to your project with `npm`: | ||
bigint-mod-arith can be imported to your project with `npm`: | ||
```bash | ||
```console | ||
npm install bigint-mod-arith | ||
``` | ||
NPM installation defaults to the ES6 module for browsers and the CJS one for Node.js. For web browsers, you can also directly download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/lib/index.browser.bundle.iife.js) or the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/lib/index.browser.bundle.mod.js) from the repository. | ||
Then either require (Node.js CJS): | ||
```javascript | ||
const bigintModArith = require('bigint-mod-arith') | ||
``` | ||
## Usage example | ||
or import (JavaScript ES module): | ||
Import your module as : | ||
```javascript | ||
import * as bigintModArith from 'bigint-mod-arith' | ||
``` | ||
- Node.js | ||
```javascript | ||
const bigintModArith = require('bigint-mod-arith') | ||
... // your code here | ||
``` | ||
- JavaScript native or TypeScript project (including React and Angular) | ||
```javascript | ||
import * as bigintModArith from 'bigint-mod-arith' | ||
... // your code here | ||
``` | ||
- JavaScript native browser ES module | ||
```html | ||
<script type="module"> | ||
import * as bigintModArith from 'lib/index.browser.bundle.mod.js' // Use you actual path to the broser mod bundle | ||
... // your code here | ||
</script> | ||
``` | ||
- JavaScript native browser IIFE | ||
```html | ||
<head> | ||
... | ||
<script src="../../lib/index.browser.bundle.iife.js"></script> <!-- Use you actual path to the browser bundle --> | ||
</head> | ||
<body> | ||
... | ||
<script> | ||
... // your code here | ||
</script> | ||
</body> | ||
``` | ||
The appropriate version for browser or node is automatically exported. | ||
You can also download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/dist/bundles/bigint-mod-arith.iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/dist/bundles/bigint-mod-arith.esm.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/bigint-mod-arith/master/dist/bundles/bigint-mod-arith.umd.js) and manually add it to your project, or, if you have already imported `bigint-mod-arith` to your project, just get the bundles from `node_modules/bigint-mod-arith/dist/bundles/`. | ||
An example of usage could be: | ||
```javascript | ||
```typescript | ||
/* Stage 3 BigInts with value 666 can be declared as BigInt('666') | ||
@@ -79,3 +55,2 @@ or the shorter syntax 666n. | ||
console.log(bigintModArith.modInv(BigInt('3'), BigInt('5'))) // prints 2 | ||
``` | ||
@@ -85,164 +60,2 @@ | ||
<a name="module_bigint-mod-arith"></a> | ||
### bigint-mod-arith | ||
Some common functions for modular arithmetic using native JS implementation of BigInt | ||
* [bigint-mod-arith](#module_bigint-mod-arith) | ||
* [~abs(a)](#module_bigint-mod-arith..abs) β <code>bigint</code> | ||
* [~bitLength(a)](#module_bigint-mod-arith..bitLength) β <code>number</code> | ||
* [~eGcd(a, b)](#module_bigint-mod-arith..eGcd) β <code>egcdReturn</code> | ||
* [~gcd(a, b)](#module_bigint-mod-arith..gcd) β <code>bigint</code> | ||
* [~lcm(a, b)](#module_bigint-mod-arith..lcm) β <code>bigint</code> | ||
* [~max(a, b)](#module_bigint-mod-arith..max) β <code>bigint</code> | ||
* [~min(a, b)](#module_bigint-mod-arith..min) β <code>bigint</code> | ||
* [~modInv(a, n)](#module_bigint-mod-arith..modInv) β <code>bigint</code> \| <code>NaN</code> | ||
* [~modPow(b, e, n)](#module_bigint-mod-arith..modPow) β <code>bigint</code> | ||
* [~toZn(a, n)](#module_bigint-mod-arith..toZn) β <code>bigint</code> | ||
* [~egcdReturn](#module_bigint-mod-arith..egcdReturn) : <code>Object</code> | ||
<a name="module_bigint-mod-arith..abs"></a> | ||
#### bigint-mod-arith~abs(a) β <code>bigint</code> | ||
Absolute value. abs(a)==a if a>=0. abs(a)==-a if a<0 | ||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith) | ||
**Returns**: <code>bigint</code> - the absolute value of a | ||
| Param | Type | | ||
| --- | --- | | ||
| a | <code>number</code> \| <code>bigint</code> | | ||
<a name="module_bigint-mod-arith..bitLength"></a> | ||
#### bigint-mod-arith~bitLength(a) β <code>number</code> | ||
Returns the bitlength of a number | ||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith) | ||
**Returns**: <code>number</code> - - the bit length | ||
| Param | Type | | ||
| --- | --- | | ||
| a | <code>number</code> \| <code>bigint</code> | | ||
<a name="module_bigint-mod-arith..eGcd"></a> | ||
#### bigint-mod-arith~eGcd(a, b) β <code>egcdReturn</code> | ||
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). | ||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith) | ||
**Returns**: <code>egcdReturn</code> - A triple (g, x, y), such that ax + by = g = gcd(a, b). | ||
| Param | Type | | ||
| --- | --- | | ||
| a | <code>number</code> \| <code>bigint</code> | | ||
| b | <code>number</code> \| <code>bigint</code> | | ||
<a name="module_bigint-mod-arith..gcd"></a> | ||
#### bigint-mod-arith~gcd(a, b) β <code>bigint</code> | ||
Greatest-common divisor of two integers based on the iterative binary algorithm. | ||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith) | ||
**Returns**: <code>bigint</code> - The greatest common divisor of a and b | ||
| Param | Type | | ||
| --- | --- | | ||
| a | <code>number</code> \| <code>bigint</code> | | ||
| b | <code>number</code> \| <code>bigint</code> | | ||
<a name="module_bigint-mod-arith..lcm"></a> | ||
#### bigint-mod-arith~lcm(a, b) β <code>bigint</code> | ||
The least common multiple computed as abs(a*b)/gcd(a,b) | ||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith) | ||
**Returns**: <code>bigint</code> - The least common multiple of a and b | ||
| Param | Type | | ||
| --- | --- | | ||
| a | <code>number</code> \| <code>bigint</code> | | ||
| b | <code>number</code> \| <code>bigint</code> | | ||
<a name="module_bigint-mod-arith..max"></a> | ||
#### bigint-mod-arith~max(a, b) β <code>bigint</code> | ||
Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b | ||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith) | ||
**Returns**: <code>bigint</code> - maximum of numbers a and b | ||
| Param | Type | | ||
| --- | --- | | ||
| a | <code>number</code> \| <code>bigint</code> | | ||
| b | <code>number</code> \| <code>bigint</code> | | ||
<a name="module_bigint-mod-arith..min"></a> | ||
#### bigint-mod-arith~min(a, b) β <code>bigint</code> | ||
Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b | ||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith) | ||
**Returns**: <code>bigint</code> - minimum of numbers a and b | ||
| Param | Type | | ||
| --- | --- | | ||
| a | <code>number</code> \| <code>bigint</code> | | ||
| b | <code>number</code> \| <code>bigint</code> | | ||
<a name="module_bigint-mod-arith..modInv"></a> | ||
#### bigint-mod-arith~modInv(a, n) β <code>bigint</code> \| <code>NaN</code> | ||
Modular inverse. | ||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith) | ||
**Returns**: <code>bigint</code> \| <code>NaN</code> - the inverse modulo n or NaN if it does not exist | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| a | <code>number</code> \| <code>bigint</code> | The number to find an inverse for | | ||
| n | <code>number</code> \| <code>bigint</code> | The modulo | | ||
<a name="module_bigint-mod-arith..modPow"></a> | ||
#### bigint-mod-arith~modPow(b, e, n) β <code>bigint</code> | ||
Modular exponentiation b**e mod n. Currently using the right-to-left binary method | ||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith) | ||
**Returns**: <code>bigint</code> - b**e mod n | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| b | <code>number</code> \| <code>bigint</code> | base | | ||
| e | <code>number</code> \| <code>bigint</code> | exponent | | ||
| n | <code>number</code> \| <code>bigint</code> | modulo | | ||
<a name="module_bigint-mod-arith..toZn"></a> | ||
#### bigint-mod-arith~toZn(a, n) β <code>bigint</code> | ||
Finds the smallest positive element that is congruent to a in modulo n | ||
**Kind**: inner method of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith) | ||
**Returns**: <code>bigint</code> - The smallest positive representation of a in modulo n | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| a | <code>number</code> \| <code>bigint</code> | An integer | | ||
| n | <code>number</code> \| <code>bigint</code> | The modulo | | ||
<a name="module_bigint-mod-arith..egcdReturn"></a> | ||
#### bigint-mod-arith~egcdReturn : <code>Object</code> | ||
A triple (g, x, y), such that ax + by = g = gcd(a, b). | ||
**Kind**: inner typedef of [<code>bigint-mod-arith</code>](#module_bigint-mod-arith) | ||
**Properties** | ||
| Name | Type | | ||
| --- | --- | | ||
| g | <code>bigint</code> | | ||
| x | <code>bigint</code> | | ||
| y | <code>bigint</code> | | ||
[Check the API](./docs/API.md) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
44
1
63412
24
1109
59
1