diff --git a/Makefile b/Makefile index 2dea2e4..7218661 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ LIB=adler32 REQS= ADDONS= AUXTARGETS=demo/browser.js -CMDS=bin/adler32.njs +CMDS= HTMLLINT=index.html ULIB=$(shell echo $(LIB) | tr a-z A-Z) @@ -62,7 +62,7 @@ fullint: lint old-lint tslint flow mdlint ## Run all checks .PHONY: lint lint: $(TARGET) $(AUXTARGETS) ## Run eslint checks - @eslint --ext .js,.njs,.json,.html,.htm $(TARGET) $(AUXTARGETS) $(CMDS) $(HTMLLINT) package.json bower.json + @eslint --ext .js,.njs,.json,.html,.htm $(TARGET) $(AUXTARGETS) $(CMDS) $(HTMLLINT) package.json if [ -e $(CLOSURE) ]; then java -jar $(CLOSURE) $(REQS) $(FLOWTARGET) --jscomp_warning=reportUnknownTypes >/dev/null; fi .PHONY: old-lint diff --git a/README.md b/README.md index b859cf2..46e248f 100644 --- a/README.md +++ b/README.md @@ -80,18 +80,19 @@ To generate the bits file, use the `adler32` function from python `zlib`: 2023497376 ``` -The included `adler32.njs` script can process files or standard input: +The [`adler32-cli`](https://www.npmjs.com/package/adler32-cli) package includes +scripts for processing files or text on standard input: ```bash $ echo "this is a test" > t.txt -$ bin/adler32.njs t.txt +$ adler32-cli t.txt 726861088 ``` -For comparison, the included `adler32.py` script uses python `zlib`: +For comparison, the `adler32.py` script in the subdirectory uses python `zlib`: ```bash -$ bin/adler32.py t.txt +$ packages/adler32-cli/bin/adler32.py t.txt 726861088 ``` diff --git a/adler32.flow.js b/adler32.flow.js index 2cd9017..ba5198a 100644 --- a/adler32.flow.js +++ b/adler32.flow.js @@ -10,7 +10,7 @@ var ADLER32/*:ADLER32Module*/; if(typeof DO_NOT_EXPORT_ADLER === 'undefined') { if('object' === typeof exports) { factory(exports); - } else if ('function' === typeof define && define.amd) { + } else if ('function' === typeof define && /*::(*/define/*:: :any)*/.amd) { define(function () { var module/*:ADLER32Module*/ = /*::(*/{}/*:: :any)*/; factory(module); @@ -25,7 +25,7 @@ var ADLER32/*:ADLER32Module*/; /*eslint-enable */ /*jshint ignore:end */ }(function(ADLER32/*:ADLER32Module*/) { -ADLER32.version = '1.2.0'; +ADLER32.version = '1.3.0'; /*:: type ADLER32Type = number; type ABuf = Array | Buffer | Uint8Array; diff --git a/adler32.js b/adler32.js index 4a29ac3..2f48a90 100644 --- a/adler32.js +++ b/adler32.js @@ -23,7 +23,7 @@ var ADLER32; /*eslint-enable */ /*jshint ignore:end */ }(function(ADLER32) { -ADLER32.version = '1.2.0'; +ADLER32.version = '1.3.0'; function adler32_bstr(bstr, seed) { var a = 1, b = 0, L = bstr.length, M = 0; if(typeof seed === 'number') { a = seed & 0xFFFF; b = seed >>> 16; } diff --git a/bits/00_header.js b/bits/00_header.js index f5899d7..f6a921a 100644 --- a/bits/00_header.js +++ b/bits/00_header.js @@ -10,7 +10,7 @@ var ADLER32/*:ADLER32Module*/; if(typeof DO_NOT_EXPORT_ADLER === 'undefined') { if('object' === typeof exports) { factory(exports); - } else if ('function' === typeof define && define.amd) { + } else if ('function' === typeof define && /*::(*/define/*:: :any)*/.amd) { define(function () { var module/*:ADLER32Module*/ = /*::(*/{}/*:: :any)*/; factory(module); diff --git a/bits/01_version.js b/bits/01_version.js index b69c5d4..e09885e 100644 --- a/bits/01_version.js +++ b/bits/01_version.js @@ -1 +1 @@ -ADLER32.version = '1.2.0'; +ADLER32.version = '1.3.0'; diff --git a/ctest/adler32.js b/ctest/adler32.js index 4a29ac3..2f48a90 100644 --- a/ctest/adler32.js +++ b/ctest/adler32.js @@ -23,7 +23,7 @@ var ADLER32; /*eslint-enable */ /*jshint ignore:end */ }(function(ADLER32) { -ADLER32.version = '1.2.0'; +ADLER32.version = '1.3.0'; function adler32_bstr(bstr, seed) { var a = 1, b = 0, L = bstr.length, M = 0; if(typeof seed === 'number') { a = seed & 0xFFFF; b = seed >>> 16; } diff --git a/ctest/fixtures.js b/ctest/fixtures.js index 19d98b8..09ac2ac 100644 --- a/ctest/fixtures.js +++ b/ctest/fixtures.js @@ -34,8 +34,8 @@ type _CB = {(data:Buffer):void;}; declare module 'concat-stream' {declare function exports(f:_CB):stream$Duplex;}; declare module 'exit-on-epipe' {}; -declare module 'adler-32' { declare var exports:ADLER32Module; }; -declare module '../' { declare var exports:ADLER32Module; }; +declare module 'adler-32' { declare module.exports:ADLER32Module; }; +declare module '../' { declare module.exports:ADLER32Module; }; declare module 'printj' { declare function sprintf(fmt:string, ...args:any):string; diff --git a/ctest/test.js b/ctest/test.js index ab9c178..86798ab 100644 --- a/ctest/test.js +++ b/ctest/test.js @@ -19,6 +19,14 @@ function msieversion() return parseInt (ua.substring (msie+5, ua.indexOf (".", msie ))); } +var Buffer_from = function(){}; + +if(typeof Buffer !== 'undefined') { + var nbfs = !Buffer.from; + if(!nbfs) try { Buffer.from("foo", "utf8"); } catch(e) { nbfs = true; } + Buffer_from = nbfs ? function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); } : Buffer.from.bind(Buffer); +} + describe('adler32 bits', function() { bits.forEach(function(i) { var msg = i[0], l = i[0].length, L = i[1]|0; @@ -28,7 +36,7 @@ describe('adler32 bits', function() { it(msg, function() { if(i[2] === 1) assert.equal(X.bstr(i[0]), L); assert.equal(X.str(i[0]), i[1]|0); - if(typeof Buffer !== 'undefined') assert.equal(X.buf(new Buffer(i[0])), L); + if(typeof Buffer !== 'undefined') assert.equal(X.buf(Buffer_from(i[0])), L); var len = i[0].length, step = len < 20000 ? 1 : len < 50000 ? Math.ceil(len / 20000) : Math.ceil(len / 2000); for(var x = 0; x < len; x += step) { if(i[0].charCodeAt(x) >= 0xD800 && i[0].charCodeAt(x) < 0xE000) continue; @@ -39,7 +47,7 @@ describe('adler32 bits', function() { var stradl = X.str(i[0].substr(x), X.str(i[0].substr(0, x))); assert.equal(stradl, i[1]|0); if(typeof Buffer !== 'undefined') { - var buf = new Buffer(i[0]); + var buf = Buffer_from(i[0]); var bufadl = X.buf(buf.slice(x), X.buf(buf.slice(0, x))); assert.equal(bufadl, L); } @@ -62,9 +70,9 @@ if(typeof require !== 'undefined') describe("unicode", function() { var cc = corpus[ucidx], dd = X.str(c); assert.equal(dd, cc, ":" + ucidx + ":" + c + ":" + cc + ":" + dd); if(typeof Buffer !== 'undefined') { - var ee = X.buf(new Buffer(c, "utf8")); + var ee = X.buf(Buffer_from(c, "utf8")); assert.equal(ee, cc, ":" + ucidx + ":" + c + ":" + cc + ":" + ee); - var ff = X.bstr(String.fromCharCode.apply(null, new Buffer(c, "utf8"))); + var ff = X.bstr(String.fromCharCode.apply(null, Buffer_from(c, "utf8"))); assert.equal(ff, cc, ":" + ucidx + ":" + c + ":" + cc + ":" + ff); } }; diff --git a/demo/browser.flow.js b/demo/browser.flow.js index 5da61de..5274d5f 100644 --- a/demo/browser.flow.js +++ b/demo/browser.flow.js @@ -1,6 +1,6 @@ /*jshint browser:true */ /*eslint-env browser */ -/*global ADLER32, console, Uint8Array */ +/*global ADLER32, Uint8Array */ /*:: declare var ADLER32: ADLER32Module; */ var X = ADLER32; diff --git a/demo/browser.js b/demo/browser.js index 870d11c..26d4517 100644 --- a/demo/browser.js +++ b/demo/browser.js @@ -1,6 +1,6 @@ /*jshint browser:true */ /*eslint-env browser */ -/*global ADLER32, console, Uint8Array */ +/*global ADLER32, Uint8Array */ var X = ADLER32; function console_log() { if(typeof console !== 'undefined') console.log.apply(console, [].slice.call(arguments)); } diff --git a/demo/work.js b/demo/work.js index 7b87a28..47c7624 100644 --- a/demo/work.js +++ b/demo/work.js @@ -11,7 +11,7 @@ var readler = function(f, adler, l) { var d = f.slice(l, l + sz); var r = new FileReader(); r.onload = function(e) { - var b = new Uint8Array(e.target.result); + var b = new Uint8Array((e.target/*:any*/).result); var newadler = ADLER32.buf(b, adler); /*::self.*/postMessage({t:"data", adler:newadler, bytes:l+sz}); readler(f, newadler, l + sz); diff --git a/package.json b/package.json index 3b4de49..86320fe 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,13 @@ { "name": "adler-32", - "version": "1.2.0", + "version": "1.3.0", "author": "sheetjs", "description": "Pure-JS ADLER-32", "keywords": [ "adler32", "checksum" ], "main": "./adler32", "types": "types", "dependencies": { - "printj": "~1.1.0", - "exit-on-epipe": "~1.0.1" + "printj": "~1.2.2" }, "devDependencies": { "mocha": "~2.5.3", @@ -32,7 +31,7 @@ } }, "homepage": "http://sheetjs.com/opensource", - "files": ["adler32.js", "bin/adler32.njs", "LICENSE", "README.md", "types/index.d.ts", "types/*.json"], + "files": ["adler32.js", "LICENSE", "README.md", "types/index.d.ts", "types/*.json"], "bugs": { "url": "https://github.com/SheetJS/js-adler32/issues" }, "license": "Apache-2.0", "engines": { "node": ">=0.8" } diff --git a/packages/adler32-cli/.npmignore b/packages/adler32-cli/.npmignore new file mode 100644 index 0000000..062d394 --- /dev/null +++ b/packages/adler32-cli/.npmignore @@ -0,0 +1,2 @@ +*.tgz +*.py diff --git a/packages/adler32-cli/index.js b/packages/adler32-cli/index.js index 5f39e97..fe8b179 100644 --- a/packages/adler32-cli/index.js +++ b/packages/adler32-cli/index.js @@ -4,8 +4,7 @@ /* vim: set ts=2 ft=javascript: */ /*jshint node:true */ -/*:ADLER32Module*/ -var X = require('adler32'); +var X/*:ADLER32Module*/ = require('adler-32'); function help()/*:number*/ { [ diff --git a/packages/adler32-cli/package.json b/packages/adler32-cli/package.json index 17bae95..718ddb4 100644 --- a/packages/adler32-cli/package.json +++ b/packages/adler32-cli/package.json @@ -1,6 +1,6 @@ { "name": "adler32-cli", - "version": "1.0.2", + "version": "1.0.3", "description": "Command-line interface for adler32", "main": "index.js", "bin": { @@ -9,8 +9,7 @@ "author": "Garrett Luu", "license": "Apache-2.0", "dependencies": { - "adler32": "^0.1.7", - "exit-on-epipe": "^1.0.1", - "fs": "0.0.1-security" + "adler-32": "^1.3.0", + "printj": "~1.2.2" } } diff --git a/types/tsconfig.json b/types/tsconfig.json index 529e614..989de1d 100644 --- a/types/tsconfig.json +++ b/types/tsconfig.json @@ -9,6 +9,7 @@ "paths": { "adler-32": ["."] }, "types": [], "noEmit": true, + "strictFunctionTypes": true, "forceConsistentCasingInFileNames": true } } diff --git a/types/tslint.json b/types/tslint.json index d9401a9..0ce4c6c 100644 --- a/types/tslint.json +++ b/types/tslint.json @@ -1,11 +1,14 @@ { "extends": "dtslint/dtslint.json", "rules": { + "no-implicit-dependencies": false, "whitespace": false, "no-sparse-arrays": false, "only-arrow-functions": false, "no-consecutive-blank-lines": false, "prefer-conditional-expression": false, - "one-variable-per-declaration": false + "one-variable-per-declaration": false, + "strict-export-declare-modifiers": false, + "prefer-template": false } }