@bitarray/es6
Advanced tools
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const bitarray_1 = require("../src/bitarray"); | ||
| const util_1 = require("./util"); | ||
| const bitarray_js_1 = __importDefault(require("../src/bitarray.js")); | ||
| const util_js_1 = require("./util.js"); | ||
| const len = 33; // choose any integer value | ||
| (0, util_1.logHeader)('Randomly initializing an array'); | ||
| const randomArray = new bitarray_1.default(len); | ||
| (0, util_js_1.logHeader)('Randomly initializing an array'); | ||
| const randomArray = new bitarray_js_1.default(len); | ||
| for (let i = 0; i < len; i++) | ||
| randomArray[i] = (Math.random() > 0.5); | ||
| (0, util_1.log)('instanceof == BoolArray', randomArray instanceof bitarray_1.default); | ||
| (0, util_1.log)('array == ', randomArray); | ||
| (0, util_1.logHeader)('properties'); | ||
| (0, util_1.log)('.count', randomArray.count); | ||
| (0, util_1.logHeader)('Bitwise operations'); | ||
| const sample1 = bitarray_1.default.from([ | ||
| (0, util_js_1.log)('instanceof == BoolArray', randomArray instanceof bitarray_js_1.default); | ||
| (0, util_js_1.log)('array == ', randomArray); | ||
| (0, util_js_1.logHeader)('properties'); | ||
| (0, util_js_1.log)('.count', randomArray.count); | ||
| (0, util_js_1.logHeader)('Bitwise operations'); | ||
| const sample1 = bitarray_js_1.default.from([ | ||
| true, | ||
@@ -82,3 +85,3 @@ false, | ||
| ])); | ||
| const sample2 = bitarray_1.default.from([ | ||
| const sample2 = bitarray_js_1.default.from([ | ||
| false, | ||
@@ -150,6 +153,6 @@ true, | ||
| ])); | ||
| (0, util_1.log)('sample1 = ', sample1.toString()); | ||
| (0, util_1.log)('sample2 = ', sample2.toString()); | ||
| (0, util_1.log)('s1 | s2 = ', sample1['|'](sample2).toString()); | ||
| (0, util_1.log)('s1 ^ s2 = ', sample1['^'](sample2).toString()); | ||
| (0, util_1.log)('s1 & s2 = ', sample1['&'](sample2).toString()); | ||
| (0, util_js_1.log)('sample1 = ', sample1.toString()); | ||
| (0, util_js_1.log)('sample2 = ', sample2.toString()); | ||
| (0, util_js_1.log)('s1 | s2 = ', sample1['|'](sample2).toString()); | ||
| (0, util_js_1.log)('s1 ^ s2 = ', sample1['^'](sample2).toString()); | ||
| (0, util_js_1.log)('s1 & s2 = ', sample1['&'](sample2).toString()); |
@@ -7,2 +7,5 @@ "use strict"; | ||
| */ | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -27,11 +30,4 @@ /** | ||
| */ | ||
| const typedarray_1 = require("@bitarray/typedarray"); | ||
| // missing js extension fails dependent applications | ||
| // but adding js extension fails example/test of the library itself | ||
| // => quick and dirty solution for now: inline import. | ||
| // | ||
| // import { base64MIMEChars, base64UrlChars } from './alphabet'; | ||
| const lettersAndDigits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
| const base64MIMEChars = lettersAndDigits + '+/'; | ||
| const base64UrlChars = lettersAndDigits + '-_'; | ||
| const typedarray_1 = __importDefault(require("@bitarray/typedarray")); | ||
| const alphabet_js_1 = require("./alphabet.js"); | ||
| const alphabetLengthErrorMsg = "Alphabet's length must be a power of 2"; | ||
@@ -217,12 +213,12 @@ // I could leverage _views from @bitarray/typedarray, or create a new one here. | ||
| encodeBase64MIME() { | ||
| return this.encode(base64MIMEChars); | ||
| return this.encode(alphabet_js_1.base64MIMEChars); | ||
| } | ||
| static decodeBase64MIME(encodedString) { | ||
| return BitArray.decode(encodedString, base64MIMEChars); | ||
| return BitArray.decode(encodedString, alphabet_js_1.base64MIMEChars); | ||
| } | ||
| encodeBase64Url() { | ||
| return this.encode(base64UrlChars); | ||
| return this.encode(alphabet_js_1.base64UrlChars); | ||
| } | ||
| static decodeBase64Url(encodedString) { | ||
| return BitArray.decode(encodedString, base64UrlChars); | ||
| return BitArray.decode(encodedString, alphabet_js_1.base64UrlChars); | ||
| } | ||
@@ -229,0 +225,0 @@ } |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const suite_1 = require("./suite"); | ||
| const test_1 = require("./test"); | ||
| (0, test_1.default)(suite_1.default); | ||
| const suite_js_1 = __importDefault(require("./suite.js")); | ||
| const test_js_1 = __importDefault(require("./test.js")); | ||
| (0, test_js_1.default)(suite_js_1.default); |
+14
-11
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const bitarray_1 = require("../src/bitarray"); | ||
| const bitarray_js_1 = __importDefault(require("../src/bitarray.js")); | ||
| const len = 42; // choose whatever value | ||
@@ -9,5 +12,5 @@ // we fill randomly, but we could choose fixed values, or whatever, | ||
| const arr2 = new Array(len + 10).fill(false).map((x) => Math.random() > 0.5); | ||
| const sample1 = bitarray_1.default.from(arr1); | ||
| const sample2 = bitarray_1.default.of(...arr2); | ||
| const sample3 = bitarray_1.default.from('0110'); | ||
| const sample1 = bitarray_js_1.default.from(arr1); | ||
| const sample2 = bitarray_js_1.default.of(...arr2); | ||
| const sample3 = bitarray_js_1.default.from('0110'); | ||
| // Returns true if the block throws | ||
@@ -35,4 +38,4 @@ function expectThrow(fn) { | ||
| const instantiating = { | ||
| 'BitArray.from': sample1 instanceof bitarray_1.default, | ||
| 'BitArray.of': sample2 instanceof bitarray_1.default, | ||
| 'BitArray.from': sample1 instanceof bitarray_js_1.default, | ||
| 'BitArray.of': sample2 instanceof bitarray_js_1.default, | ||
| }; | ||
@@ -76,10 +79,10 @@ /** suite 2 */ | ||
| const character_encode_decode = { | ||
| '.decode_1bit': bitarray_1.default.decode('abba', 'ab').toString() === sample3.toString(), | ||
| '.decode_1bit': bitarray_js_1.default.decode('abba', 'ab').toString() === sample3.toString(), | ||
| // Note: the substring is needed because when deserializing, we have some number of padding 0s that we can't know were | ||
| // in the original string or not | ||
| '.decode_3bit': bitarray_1.default.decode('da', 'abcdefgh').toString().substring(0, 4) === | ||
| '.decode_3bit': bitarray_js_1.default.decode('da', 'abcdefgh').toString().substring(0, 4) === | ||
| sample3.toString(), | ||
| '.decode_empty': bitarray_1.default.decode('', 'ab').toString() === '', | ||
| '.decode_invalid': expectThrow(() => bitarray_1.default.decode('abc', 'ab')), | ||
| '.decode_': expectThrow(() => bitarray_1.default.decode('abba', '')), | ||
| '.decode_empty': bitarray_js_1.default.decode('', 'ab').toString() === '', | ||
| '.decode_invalid': expectThrow(() => bitarray_js_1.default.decode('abc', 'ab')), | ||
| '.decode_': expectThrow(() => bitarray_js_1.default.decode('abba', '')), | ||
| }; | ||
@@ -86,0 +89,0 @@ exports.default = { |
@@ -1,3 +0,3 @@ | ||
| import BoolArray from '../src/bitarray'; | ||
| import { log as _, logHeader as _$ } from './util'; | ||
| import BoolArray from '../src/bitarray.js'; | ||
| import { log as _, logHeader as _$ } from './util.js'; | ||
| const len = 33; // choose any integer value | ||
@@ -4,0 +4,0 @@ _$('Randomly initializing an array'); |
@@ -25,10 +25,3 @@ /** | ||
| import BitTypedArray from '@bitarray/typedarray'; | ||
| // missing js extension fails dependent applications | ||
| // but adding js extension fails example/test of the library itself | ||
| // => quick and dirty solution for now: inline import. | ||
| // | ||
| // import { base64MIMEChars, base64UrlChars } from './alphabet'; | ||
| const lettersAndDigits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
| const base64MIMEChars = lettersAndDigits + '+/'; | ||
| const base64UrlChars = lettersAndDigits + '-_'; | ||
| import { base64MIMEChars, base64UrlChars } from './alphabet.js'; | ||
| const alphabetLengthErrorMsg = "Alphabet's length must be a power of 2"; | ||
@@ -35,0 +28,0 @@ // I could leverage _views from @bitarray/typedarray, or create a new one here. |
@@ -1,3 +0,3 @@ | ||
| import suite from './suite'; | ||
| import test from './test'; | ||
| import suite from './suite.js'; | ||
| import test from './test.js'; | ||
| test(suite); |
@@ -1,2 +0,2 @@ | ||
| import BitArray from '../src/bitarray'; | ||
| import BitArray from '../src/bitarray.js'; | ||
| const len = 42; // choose whatever value | ||
@@ -3,0 +3,0 @@ // we fill randomly, but we could choose fixed values, or whatever, |
+8
-6
| { | ||
| "name": "@bitarray/es6", | ||
| "version": "1.1.2", | ||
| "version": "1.2.0", | ||
| "description": "An ES6 BitArray class for easy and native-like operations on sequences of bits", | ||
| "typings": "./dist/esm/bitarray.d.ts", | ||
| "type": "module", | ||
| "typings": "./dist/esm/src/bitarray.d.ts", | ||
| "exports": { | ||
@@ -27,3 +28,3 @@ ".": { | ||
| "build:types": "tsc --emitDeclarationOnly -p tsconfig.json", | ||
| "example": "node --loader ts-node/esm example", | ||
| "example": "ts-node --esm --project ./tsconfig.esm.json ./example/index.ts", | ||
| "postbuild": "bash ./scripts/postbuild.sh", | ||
@@ -34,3 +35,4 @@ "prepare": "npm run build", | ||
| "style:check": "prettier {example,src,test}/**/*.ts --check", | ||
| "test": "node --loader ts-node/esm test" | ||
| "test": "ts-node --esm --project ./tsconfig.esm.json ./test/index.ts", | ||
| "test:ci": "set TS_NODE_PROJECT=./tsconfig.esm.json && node --no-warnings=ExperimentalWarning --loader ts-node/esm ./test/index.ts" | ||
| }, | ||
@@ -43,5 +45,5 @@ "author": "swiing", | ||
| "devDependencies": { | ||
| "prettier": "^2.6.2", | ||
| "prettier": "^3.0.3", | ||
| "ts-node": "^10.7.0", | ||
| "typescript": "^4.7.4" | ||
| "typescript": "^5.0.3" | ||
| }, | ||
@@ -48,0 +50,0 @@ "keywords": [ |
47888
0.61%Yes
NaN1183
-0.17%