From 02caecf54f5f8cd9fbcbc295cbf3d6553db97e58 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Wed, 17 Jan 2018 16:27:59 -0500 Subject: [PATCH] version bump 1.2.0: infrastructure --- .eslintrc | 12 ++++++------ .spelling | 10 ++++++++++ .travis.yml | 1 + Makefile | 14 ++++++++++++-- README.md | 21 ++++++++++----------- bin/crc32.njs | 2 ++ bits/00_header.js | 18 ++++++++++-------- bits/01_version.js | 2 +- bits/10_types.js | 2 +- bits/90_exports.js | 3 +++ crc32.flow.js | 25 +++++++++++++++---------- crc32.js | 7 ++++++- ctest/crc32.js | 7 ++++++- ctest/fixtures.js | 9 +++------ demo/browser.flow.js | 9 +++++++-- demo/browser.js | 5 +++-- index.html | 7 ++++--- misc/flow.js | 9 +++------ package.json | 8 +++++--- types/bin_crc32.ts | 1 + 20 files changed, 109 insertions(+), 63 deletions(-) create mode 100644 .spelling diff --git a/.eslintrc b/.eslintrc index 3ae0c77..8dc3744 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,14 +5,14 @@ "ecmaVersion": 3, }, "plugins": [ "html", "json" ], - "!extends": "eslint:recommended", + "extends": "eslint:recommended", "rules": { - "no-console": 0, - "no-bitwise": 0, - "curly": 0, "comma-style": [ 2, "last" ], + "comma-dangle": [ 2, "never" ], + "curly": 0, + "no-bitwise": 0, + "no-console": 0, "no-trailing-spaces": 2, - "semi": [ 2, "always" ], - "comma-dangle": [ 2, "never" ] + "semi": [ 2, "always" ] } } diff --git a/.spelling b/.spelling new file mode 100644 index 0000000..eab634b --- /dev/null +++ b/.spelling @@ -0,0 +1,10 @@ +# crc32.js (C) 2014-present SheetJS -- http://sheetjs.com +SheetJS +32-bit +CRC-32 +UCS-2 +UTF-8 +crc32 +checksum +nodejs +npm diff --git a/.travis.yml b/.travis.yml index c529897..fc97c87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js node_js: + - "9" - "8" - "7" - "6" diff --git a/Makefile b/Makefile index 328f81c..d5ab2a9 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,9 @@ clean-baseline: ## Remove test baselines ## Code Checking +.PHONY: fullint +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 @@ -74,7 +77,8 @@ old-lint: $(TARGET) $(AUXTARGETS) ## Run jshint and jscs checks .PHONY: tslint tslint: $(TARGET) ## Run typescript checks #@npm install dtslint typescript - @npm run-script dtslint + #@npm run-script dtslint + dtslint types .PHONY: flow flow: lint ## Run flow checker @@ -84,12 +88,18 @@ flow: lint ## Run flow checker cov: misc/coverage.html ## Run coverage test misc/coverage.html: $(TARGET) test.js - mocha --require blanket -R html-cov -t 20000 > $@ + mocha --require blanket -R html-cov -t 30000 > $@ .PHONY: coveralls coveralls: ## Coverage Test + Send to coveralls.io mocha --require blanket --reporter mocha-lcov-reporter -t 20000 | node ./node_modules/coveralls/bin/coveralls.js +MDLINT=README.md +.PHONY: mdlint +mdlint: $(MDLINT) ## Check markdown documents + alex $^ + mdspell -a -n -x -r --en-us $^ + .PHONY: perf perf: ## Run Performance Tests @bash perf/perf.sh diff --git a/README.md b/README.md index 0339117..38445de 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,8 @@ The browser exposes a variable `CRC32`. When installed globally, npm installs a script `crc32` that computes the checksum for a specified file or standard input. -The script will manipulate `module.exports` if available (e.g. in a CommonJS -`require` context). This is not always desirable. To prevent the behavior, -define `DO_NOT_EXPORT_CRC`. +The script will manipulate `module.exports` if available . This is not always +desirable. To prevent the behavior, define `DO_NOT_EXPORT_CRC`. ## Usage @@ -34,13 +33,13 @@ optional second argument representing the starting "seed" (for rolling CRC). The return value is a signed 32-bit integer. - `CRC32.buf(byte array or buffer[, seed])` assumes the argument is a sequence - of 8-bit unsigned integers (e.g. nodejs `Buffer` or simple array of ints). + of 8-bit unsigned integers (nodejs `Buffer`, `Uint8Array` or array of bytes). -- `CRC32.bstr(binary string[, seed])` assumes the argument is a "binary" string +- `CRC32.bstr(binary string[, seed])` assumes the argument is a binary string where byte `i` is the low byte of the UCS-2 char: `str.charCodeAt(i) & 0xFF` -- `CRC32.str(string[, seed])` assumes the argument is a standard string and - calculates the CRC32 of the UTF-8 encoding. +- `CRC32.str(string[, seed])` assumes the argument is a standard JS string and + calculates the hash of the UTF-8 encoding. For example: @@ -68,7 +67,7 @@ To run the in-browser tests, run a local server and go to the `ctest` directory. To update the browser artifacts, run `make ctest`. -To generate the bits file, use the `crc32` function from python zlib: +To generate the bits file, use the `crc32` function from python `zlib`: ```python >>> from zlib import crc32 @@ -81,7 +80,7 @@ To generate the bits file, use the `crc32` function from python zlib: 1834240887 ``` -The included `crc32.njs` script can process files or stdin: +The included `crc32.njs` script can process files or standard input: ```bash $ echo "this is a test" > t.txt @@ -89,7 +88,7 @@ $ bin/crc32.njs t.txt 1912935186 ``` -For comparison, the included `crc32.py` script uses python zlib: +For comparison, the included `crc32.py` script uses python `zlib`: ```bash $ bin/crc32.py t.txt @@ -110,7 +109,7 @@ $ crc32 --unsigned ~/Downloads/IE8.Win7.For.Windows.VMware.zip `make perf` will run algorithmic performance tests (which should justify certain decisions in the code). -[js-adler32](http://git.io/adler32) has more performance notes +The [`adler-32` project](http://git.io/adler32) has more performance notes ## License diff --git a/bin/crc32.njs b/bin/crc32.njs index 62bffb7..657291a 100755 --- a/bin/crc32.njs +++ b/bin/crc32.njs @@ -1,6 +1,8 @@ #!/usr/bin/env node /* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */ +/* eslint-env node */ /* vim: set ts=2 ft=javascript: */ +/*jshint node:true */ var X/*:CRC32Module*/; try { X = require('../'); } catch(e) { X = require('crc-32'); } diff --git a/bits/00_header.js b/bits/00_header.js index 7362e9d..102cdad 100644 --- a/bits/00_header.js +++ b/bits/00_header.js @@ -1,25 +1,27 @@ /* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */ /* vim: set ts=2: */ /*exported CRC32 */ -var CRC32; -/*:: declare var DO_NOT_EXPORT_CRC: any; */ -/*:: declare var define: any; */ -(function (factory) { +/*:: declare var DO_NOT_EXPORT_CRC:?boolean; */ +/*:: declare function define(cb:()=>any):void; */ +var CRC32/*:CRC32Module*/; +(function (factory/*:(a:any)=>void*/)/*:void*/ { /*jshint ignore:start */ + /*eslint-disable */ if(typeof DO_NOT_EXPORT_CRC === 'undefined') { if('object' === typeof exports) { factory(exports); } else if ('function' === typeof define && define.amd) { define(function () { - var module = {}; + var module/*:CRC32Module*/ = /*::(*/{}/*:: :any)*/; factory(module); return module; }); } else { - factory(CRC32 = {}); + factory(CRC32 = /*::(*/{}/*:: :any)*/); } } else { - factory(CRC32 = {}); + factory(CRC32 = /*::(*/{}/*:: :any)*/); } + /*eslint-enable */ /*jshint ignore:end */ -}(function(CRC32) { +}(function(CRC32/*:CRC32Module*/) { diff --git a/bits/01_version.js b/bits/01_version.js index 3a33569..782ea1d 100644 --- a/bits/01_version.js +++ b/bits/01_version.js @@ -1 +1 @@ -CRC32.version = '1.1.1'; +CRC32.version = '1.2.0'; diff --git a/bits/10_types.js b/bits/10_types.js index 6abb587..1105bed 100644 --- a/bits/10_types.js +++ b/bits/10_types.js @@ -1,5 +1,5 @@ /*:: type CRC32Type = number; -type ABuf = Array | Uint8Array | Buffer; +type ABuf = Array | Buffer | Uint8Array; type CRC32TableType = Array | Int32Array; */ diff --git a/bits/90_exports.js b/bits/90_exports.js index 083f8d7..76e4ccf 100644 --- a/bits/90_exports.js +++ b/bits/90_exports.js @@ -1,4 +1,7 @@ CRC32.table = T; +// $FlowIgnore CRC32.bstr = crc32_bstr; +// $FlowIgnore CRC32.buf = crc32_buf; +// $FlowIgnore CRC32.str = crc32_str; diff --git a/crc32.flow.js b/crc32.flow.js index 0004d7f..145b7a6 100644 --- a/crc32.flow.js +++ b/crc32.flow.js @@ -1,32 +1,34 @@ /* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */ /* vim: set ts=2: */ /*exported CRC32 */ -var CRC32; -/*:: declare var DO_NOT_EXPORT_CRC: any; */ -/*:: declare var define: any; */ -(function (factory) { +/*:: declare var DO_NOT_EXPORT_CRC:?boolean; */ +/*:: declare function define(cb:()=>any):void; */ +var CRC32/*:CRC32Module*/; +(function (factory/*:(a:any)=>void*/)/*:void*/ { /*jshint ignore:start */ + /*eslint-disable */ if(typeof DO_NOT_EXPORT_CRC === 'undefined') { if('object' === typeof exports) { factory(exports); } else if ('function' === typeof define && define.amd) { define(function () { - var module = {}; + var module/*:CRC32Module*/ = /*::(*/{}/*:: :any)*/; factory(module); return module; }); } else { - factory(CRC32 = {}); + factory(CRC32 = /*::(*/{}/*:: :any)*/); } } else { - factory(CRC32 = {}); + factory(CRC32 = /*::(*/{}/*:: :any)*/); } + /*eslint-enable */ /*jshint ignore:end */ -}(function(CRC32) { -CRC32.version = '1.1.1'; +}(function(CRC32/*:CRC32Module*/) { +CRC32.version = '1.2.0'; /*:: type CRC32Type = number; -type ABuf = Array | Uint8Array | Buffer; +type ABuf = Array | Buffer | Uint8Array; type CRC32TableType = Array | Int32Array; */ /* see perf/crc32table.js */ @@ -116,7 +118,10 @@ function crc32_str(str/*:string*/, seed/*:?CRC32Type*/)/*:CRC32Type*/ { return C ^ -1; } CRC32.table = T; +// $FlowIgnore CRC32.bstr = crc32_bstr; +// $FlowIgnore CRC32.buf = crc32_buf; +// $FlowIgnore CRC32.str = crc32_str; })); diff --git a/crc32.js b/crc32.js index fb31412..6bcecef 100644 --- a/crc32.js +++ b/crc32.js @@ -4,6 +4,7 @@ var CRC32; (function (factory) { /*jshint ignore:start */ + /*eslint-disable */ if(typeof DO_NOT_EXPORT_CRC === 'undefined') { if('object' === typeof exports) { factory(exports); @@ -19,9 +20,10 @@ var CRC32; } else { factory(CRC32 = {}); } + /*eslint-enable */ /*jshint ignore:end */ }(function(CRC32) { -CRC32.version = '1.1.1'; +CRC32.version = '1.2.0'; /* see perf/crc32table.js */ /*global Int32Array */ function signed_crc_table() { @@ -107,7 +109,10 @@ function crc32_str(str, seed) { return C ^ -1; } CRC32.table = T; +// $FlowIgnore CRC32.bstr = crc32_bstr; +// $FlowIgnore CRC32.buf = crc32_buf; +// $FlowIgnore CRC32.str = crc32_str; })); diff --git a/ctest/crc32.js b/ctest/crc32.js index fb31412..6bcecef 100644 --- a/ctest/crc32.js +++ b/ctest/crc32.js @@ -4,6 +4,7 @@ var CRC32; (function (factory) { /*jshint ignore:start */ + /*eslint-disable */ if(typeof DO_NOT_EXPORT_CRC === 'undefined') { if('object' === typeof exports) { factory(exports); @@ -19,9 +20,10 @@ var CRC32; } else { factory(CRC32 = {}); } + /*eslint-enable */ /*jshint ignore:end */ }(function(CRC32) { -CRC32.version = '1.1.1'; +CRC32.version = '1.2.0'; /* see perf/crc32table.js */ /*global Int32Array */ function signed_crc_table() { @@ -107,7 +109,10 @@ function crc32_str(str, seed) { return C ^ -1; } CRC32.table = T; +// $FlowIgnore CRC32.bstr = crc32_bstr; +// $FlowIgnore CRC32.buf = crc32_buf; +// $FlowIgnore CRC32.str = crc32_str; })); diff --git a/ctest/fixtures.js b/ctest/fixtures.js index b84d6c8..375d2b8 100644 --- a/ctest/fixtures.js +++ b/ctest/fixtures.js @@ -22,14 +22,11 @@ var bits = [ ]; if(typeof module !== "undefined") module.exports = bits; /*:: -type ArrayLike = any; -type Stringifier = {(d:ArrayLike):string}; - declare class CRC32Module { table:CRC32TableType; - bstr(s:string, seed:?CRC32Type):CRC32Type; - buf(b:ABuf, seed:?CRC32Type):CRC32Type; - str(s:string, seed:?CRC32Type):CRC32Type; + bstr(s:string, seed?:CRC32Type):CRC32Type; + buf(b:ABuf, seed?:CRC32Type):CRC32Type; + str(s:string, seed?:CRC32Type):CRC32Type; version:string; }; */ diff --git a/demo/browser.flow.js b/demo/browser.flow.js index fc833a8..39142fb 100644 --- a/demo/browser.flow.js +++ b/demo/browser.flow.js @@ -1,5 +1,6 @@ /*jshint browser:true */ -/*global CRC32, console */ +/*eslint-env browser */ +/*global CRC32, console, Uint8Array */ /*:: declare var CRC32: CRC32Module; */ var X = CRC32; @@ -17,6 +18,10 @@ function is_defined(val/*:any*/, keys/*:Array*/)/*:boolean*/ { } /*# buffer to string; IE String.fromCharCode.apply limit, manual chunk */ +/*:: +type ArrayLike = any; +type Stringifier = {(d:ArrayLike):string}; +*/ function make_chunk_buf_to_str(BType/*:function*/)/*:Stringifier*/ { return function(data/*:any*/)/*:string*/ { var o = "", l = 0, w = 10240, L = data.byteLength/w; @@ -66,7 +71,7 @@ var readcb = function(e/*:Event*/) { console_log("onload", new Date(), rABS, false); var target/*:FileReader*/ = (e.target/*:any*/); var data = target.result; - var val/*:CRC32Type*/ = rABS ? X.bstr((data/*:any*/)) : X.str(bstrify(data)); + var val/*:CRC32Type*/ = rABS ? X.bstr(/*::(*/data/*:: :any)*/) : X.str(bstrify(data)); process_value(val); }; diff --git a/demo/browser.js b/demo/browser.js index c5cc1f7..930e509 100644 --- a/demo/browser.js +++ b/demo/browser.js @@ -1,5 +1,6 @@ /*jshint browser:true */ -/*global CRC32, console */ +/*eslint-env browser */ +/*global CRC32, console, Uint8Array */ var X = CRC32; function console_log() { if(typeof console !== 'undefined') console.log.apply(console, [].slice.call(arguments)); } @@ -57,7 +58,7 @@ var readcb = function(e) { console_log("onload", new Date(), rABS, false); var target = (e.target); var data = target.result; - var val = rABS ? X.bstr((data)) : X.str(bstrify(data)); + var val = rABS ? X.bstr(data) : X.str(bstrify(data)); process_value(val); }; diff --git a/index.html b/index.html index 836ff7a..bd472b0 100644 --- a/index.html +++ b/index.html @@ -27,8 +27,8 @@ a { text-decoration: none } (text works back to IE6; drag and drop works back to IE10) (This demo loads the entire file at once! For newer browsers, try the large file demo) -Source Code Repo -Issues? Something look weird? Click here and report an issue +Source Code Repo +Issues? Something look weird? Click here and report an issue
Drop a text file to compute the CRC-32 checksum
... or click here to select a file @@ -36,7 +36,7 @@ a { text-decoration: none }
Advanced Demo Options: -Use readAsBinaryString: (when available) +Use readAsBinaryString: (when available)

 
@@ -45,6 +45,7 @@ Use readAsBinaryString: (when available)