@digitalbazaar/bitstring
Advanced tools
| /*! | ||
| * Copyright (c) 2020 Digital Bazaar, Inc. All rights reserved. | ||
| */ | ||
| export function isNumber(value, name) { | ||
| if(typeof value !== 'number') { | ||
| throw new TypeError(`"${name}" must be number.`); | ||
| } | ||
| } | ||
| export function isPositiveInteger(value, name) { | ||
| if(!(Number.isInteger(value) && value > 0)) { | ||
| throw new TypeError(`"${name}" must be a positive integer.`); | ||
| } | ||
| } | ||
| export function isString(value, name) { | ||
| if(typeof value !== 'string') { | ||
| throw new TypeError(`"${name}" must be a string.`); | ||
| } | ||
| } | ||
| export function isBoolean(value, name) { | ||
| if(typeof value !== 'boolean') { | ||
| throw new TypeError(`"${name}" must be a boolean.`); | ||
| } | ||
| } | ||
| export function isNonNegativeInteger(value, name) { | ||
| if(!(Number.isInteger(value) && value >= 0)) { | ||
| throw new TypeError(`"${name}" must be a non-negative integer.`); | ||
| } | ||
| } | ||
| export function isUint8Array(value, name) { | ||
| if(!(value instanceof Uint8Array)) { | ||
| throw new TypeError(`"${name}" must be a Uint8Array.`); | ||
| } | ||
| } |
+74
| /*! | ||
| * Copyright (c) 2020-2022 Digital Bazaar, Inc. All rights reserved. | ||
| */ | ||
| import * as base64url from 'base64url-universal'; | ||
| import {gzip, ungzip} from 'pako'; | ||
| import * as assert from './assertions.js'; | ||
| export class Bitstring { | ||
| constructor({length, buffer} = {}) { | ||
| if(length && buffer) { | ||
| throw new Error('Only one of "length" or "buffer" must be given.'); | ||
| } | ||
| if(length !== undefined) { | ||
| assert.isPositiveInteger(length, 'length'); | ||
| } else { | ||
| assert.isUint8Array(buffer, 'buffer'); | ||
| } | ||
| if(length) { | ||
| this.bits = new Uint8Array(Math.ceil(length / 8)); | ||
| this.length = length; | ||
| } else { | ||
| this.bits = new Uint8Array(buffer.buffer); | ||
| this.length = buffer.length * 8; | ||
| } | ||
| } | ||
| set(position, on) { | ||
| assert.isNumber(position, 'position'); | ||
| assert.isBoolean(on, 'on'); | ||
| const {index, bit} = _parsePosition(position, this.length); | ||
| if(on) { | ||
| this.bits[index] |= bit; | ||
| } else { | ||
| this.bits[index] &= 0xFF ^ bit; | ||
| } | ||
| } | ||
| get(position) { | ||
| assert.isNumber(position, 'position'); | ||
| const {index, bit} = _parsePosition(position, this.length); | ||
| return !!(this.bits[index] & bit); | ||
| } | ||
| async encodeBits() { | ||
| return base64url.encode(gzip(this.bits)); | ||
| } | ||
| static async decodeBits({encoded}) { | ||
| assert.isString(encoded, 'encoded'); | ||
| return ungzip(base64url.decode(encoded)); | ||
| } | ||
| async compressBits() { | ||
| return gzip(this.bits); | ||
| } | ||
| static async uncompressBits({compressed}) { | ||
| assert.isUint8Array(compressed, 'compressed'); | ||
| return ungzip(compressed); | ||
| } | ||
| } | ||
| function _parsePosition(position, length) { | ||
| assert.isNonNegativeInteger(position, 'position'); | ||
| assert.isPositiveInteger(length, 'length'); | ||
| if(position >= length) { | ||
| throw new Error( | ||
| `Position "${position}" is out of range "0-${length - 1}".`); | ||
| } | ||
| const index = Math.floor(position / 8); | ||
| const bit = 1 << (position % 8); | ||
| return {index, bit}; | ||
| } |
+32
-38
| { | ||
| "name": "@digitalbazaar/bitstring", | ||
| "version": "1.2.1", | ||
| "version": "2.0.0", | ||
| "description": "Bitstring module for universal JavaScript", | ||
| "license": "BSD-3-Clause", | ||
| "main": "index.js", | ||
| "module": "main.js", | ||
| "type": "module", | ||
| "exports": "./lib/index.js", | ||
| "files": [ | ||
| "lib/**/*.js" | ||
| ], | ||
| "scripts": { | ||
| "test": "npm run test-node", | ||
| "test-node": "cross-env NODE_ENV=test mocha -r esm --preserve-symlinks -t 30000 -A -R ${REPORTER:-spec} --require tests/test-mocha.js tests/*.spec.js", | ||
| "test-karma": "karma start karma.conf.js", | ||
| "coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text-summary npm run test-node", | ||
| "coverage-ci": "cross-env NODE_ENV=test nyc --reporter=lcovonly npm run test-node", | ||
| "coverage-report": "nyc report", | ||
| "test-node": "cross-env NODE_ENV=test mocha --preserve-symlinks -t 30000 -A -R ${REPORTER:-spec} --require tests/test-mocha.js tests/*.spec.js", | ||
| "test-karma": "karma start karma.conf.cjs", | ||
| "coverage": "cross-env NODE_ENV=test c8 npm run test-node", | ||
| "coverage-ci": "cross-env NODE_ENV=test c8 --reporter=lcovonly --reporter=text-summary --reporter=text npm run test-node", | ||
| "coverage-report": "c8 report", | ||
| "lint": "eslint ." | ||
| }, | ||
| "files": [ | ||
| "main.js", | ||
| "index.js", | ||
| "assertions.js" | ||
| ], | ||
| "dependencies": { | ||
| "base64url-universal": "^1.1.0", | ||
| "esm": "^3.2.25", | ||
| "pako": "^1.0.11" | ||
| "base64url-universal": "^2.0.0", | ||
| "pako": "^2.0.4" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/core": "^7.4.3", | ||
| "@babel/plugin-transform-modules-commonjs": "^7.4.3", | ||
| "@babel/plugin-transform-runtime": "^7.4.3", | ||
| "@babel/preset-env": "^7.4.3", | ||
| "@babel/runtime": "^7.4.3", | ||
| "babel-loader": "^8.0.5", | ||
| "chai": "^4.2.0", | ||
| "c8": "^7.11.3", | ||
| "chai": "^4.3.6", | ||
| "chai-bytes": "^0.1.2", | ||
| "cross-env": "^6.0.3", | ||
| "eslint": "^7.9.0", | ||
| "eslint-config-digitalbazaar": "^2.0.0", | ||
| "karma": "^4.0.1", | ||
| "karma-babel-preprocessor": "^8.0.0", | ||
| "cross-env": "^7.0.3", | ||
| "eslint": "^8.16.0", | ||
| "eslint-config-digitalbazaar": "^3.0.0", | ||
| "eslint-plugin-jsdoc": "^39.3.2", | ||
| "eslint-plugin-unicorn": "^42.0.0", | ||
| "karma": "^6.3.20", | ||
| "karma-chai": "^0.1.0", | ||
| "karma-chrome-launcher": "^3.1.0", | ||
| "karma-chrome-launcher": "^3.1.1", | ||
| "karma-mocha": "^2.0.1", | ||
| "karma-mocha-reporter": "^2.2.5", | ||
| "karma-sourcemap-loader": "^0.3.7", | ||
| "karma-webpack": "^4.0.2", | ||
| "mocha": "^8.0.1", | ||
| "karma-sourcemap-loader": "^0.3.8", | ||
| "karma-webpack": "^5.0.0", | ||
| "mocha": "^10.0.0", | ||
| "mocha-lcov-reporter": "^1.3.0", | ||
| "nyc": "^15.0.0", | ||
| "webpack": "^4.29.6" | ||
| "webpack": "^5.72.1" | ||
| }, | ||
@@ -69,9 +61,11 @@ "repository": { | ||
| "engines": { | ||
| "node": ">=10.0.0" | ||
| "node": ">=14" | ||
| }, | ||
| "nyc": { | ||
| "exclude": [ | ||
| "tests" | ||
| "c8": { | ||
| "reporter": [ | ||
| "lcov", | ||
| "text-summary", | ||
| "text" | ||
| ] | ||
| } | ||
| } |
| /*! | ||
| * Copyright (c) 2020 Digital Bazaar, Inc. All rights reserved. | ||
| */ | ||
| export function isNumber(value, name) { | ||
| if(typeof value !== 'number') { | ||
| throw new TypeError(`"${name}" must be number.`); | ||
| } | ||
| } | ||
| export function isPositiveInteger(value, name) { | ||
| if(!(Number.isInteger(value) && value > 0)) { | ||
| throw new TypeError(`"${name}" must be a positive integer.`); | ||
| } | ||
| } | ||
| export function isString(value, name) { | ||
| if(typeof value !== 'string') { | ||
| throw new TypeError(`"${name}" must be a string.`); | ||
| } | ||
| } | ||
| export function isBoolean(value, name) { | ||
| if(typeof value !== 'boolean') { | ||
| throw new TypeError(`"${name}" must be a boolean.`); | ||
| } | ||
| } | ||
| export function isNonNegativeInteger(value, name) { | ||
| if(!(Number.isInteger(value) && value >= 0)) { | ||
| throw new TypeError(`"${name}" must be a non-negative integer.`); | ||
| } | ||
| } | ||
| export function isUint8Array(value, name) { | ||
| if(!(value instanceof Uint8Array)) { | ||
| throw new TypeError(`"${name}" must be a Uint8Array.`); | ||
| } | ||
| } |
-8
| /*! | ||
| * Copyright (c) 2020 Digital Bazaar, Inc. All rights reserved. | ||
| */ | ||
| 'use strict'; | ||
| // translate `main.js` to CommonJS | ||
| require = require('esm')(module); | ||
| module.exports = require('./main.js'); |
-76
| /*! | ||
| * Copyright (c) 2020 Digital Bazaar, Inc. All rights reserved. | ||
| */ | ||
| import base64url from 'base64url-universal'; | ||
| import pako from 'pako'; | ||
| import * as assert from './assertions.js'; | ||
| const {gzip, ungzip} = pako; | ||
| export default class Bitstring { | ||
| constructor({length, buffer} = {}) { | ||
| if(length && buffer) { | ||
| throw new Error('Only one of "length" or "buffer" must be given.'); | ||
| } | ||
| if(length !== undefined) { | ||
| assert.isPositiveInteger(length, 'length'); | ||
| } else { | ||
| assert.isUint8Array(buffer, 'buffer'); | ||
| } | ||
| if(length) { | ||
| this.bits = new Uint8Array(Math.ceil(length / 8)); | ||
| this.length = length; | ||
| } else { | ||
| this.bits = new Uint8Array(buffer.buffer); | ||
| this.length = buffer.length * 8; | ||
| } | ||
| } | ||
| set(position, on) { | ||
| assert.isNumber(position, 'position'); | ||
| assert.isBoolean(on, 'on'); | ||
| const {index, bit} = _parsePosition(position, this.length); | ||
| if(on) { | ||
| this.bits[index] |= bit; | ||
| } else { | ||
| this.bits[index] &= 0xFF ^ bit; | ||
| } | ||
| } | ||
| get(position) { | ||
| assert.isNumber(position, 'position'); | ||
| const {index, bit} = _parsePosition(position, this.length); | ||
| return !!(this.bits[index] & bit); | ||
| } | ||
| async encodeBits() { | ||
| return base64url.encode(gzip(this.bits)); | ||
| } | ||
| static async decodeBits({encoded}) { | ||
| assert.isString(encoded, 'encoded'); | ||
| return ungzip(base64url.decode(encoded)); | ||
| } | ||
| async compressBits() { | ||
| return gzip(this.bits); | ||
| } | ||
| static async uncompressBits({compressed}) { | ||
| assert.isUint8Array(compressed, 'compressed'); | ||
| return ungzip(compressed); | ||
| } | ||
| } | ||
| function _parsePosition(position, length) { | ||
| assert.isNonNegativeInteger(position, 'position'); | ||
| assert.isPositiveInteger(length, 'length'); | ||
| if(position >= length) { | ||
| throw new Error( | ||
| `Position "${position}" is out of range "0-${length - 1}".`); | ||
| } | ||
| const index = Math.floor(position / 8); | ||
| const bit = 1 << (position % 8); | ||
| return {index, bit}; | ||
| } |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2
-33.33%18
-21.74%Yes
NaN8041
-5.14%5
-16.67%98
-7.55%2
100%+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
Updated
Updated