version bump 1.2.0: infrastructure

This commit is contained in:
SheetJS 2018-01-17 14:19:26 -05:00
parent 06fac2b063
commit d750710810
24 changed files with 255 additions and 60 deletions

View File

@ -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" ]
}
}

11
.spelling Normal file
View File

@ -0,0 +1,11 @@
# adler32.js (C) 2014-present SheetJS -- http://sheetjs.com
SheetJS
31-bit
32-bit
ADLER-32
UCS-2
UTF-8
adler32
checksum
nodejs
npm

View File

@ -1,5 +1,6 @@
language: node_js
node_js:
- "9"
- "8"
- "7"
- "6"

View File

@ -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
@ -71,6 +74,11 @@ old-lint: $(TARGET) $(AUXTARGETS) ## Run jshint and jscs checks
@jscs $(TARGET) $(AUXTARGETS)
if [ -e $(CLOSURE) ]; then java -jar $(CLOSURE) $(REQS) $(FLOWTARGET) --jscomp_warning=reportUnknownTypes >/dev/null; fi
.PHONY: tslint
tslint: $(TARGET) ## Run typescript checks
#@npm install dtslint typescript
#@npm run-script dtslint
dtslint types
.PHONY: flow
flow: lint ## Run flow checker
@ -86,6 +94,12 @@ misc/coverage.html: $(TARGET) test.js
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

View File

@ -14,7 +14,7 @@ $ npm install adler-32
In the browser:
```html
<script lang="javascript" src="adler32.js"></script>
<script src="adler32.js"></script>
```
The browser exposes a variable `ADLER32`.
@ -22,9 +22,8 @@ The browser exposes a variable `ADLER32`.
When installed globally, npm installs a script `adler32` 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_ADLER`.
The script will manipulate `module.exports` if available . This is not always
desirable. To prevent the behavior, define `DO_NOT_EXPORT_ADLER`.
## Usage
@ -34,12 +33,12 @@ optional second argument representing the starting "seed" (for running hash).
The return value is a signed 32-bit integer.
- `ADLER32.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).
- `ADLER32.bstr(binary string[, seed])` assumes the argument as a binary string
- `ADLER32.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`
- `ADLER32.str(string)` assumes the argument as a standard JS string and
- `ADLER32.str(string)` 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 `adler32` function from python zlib:
To generate the bits file, use the `adler32` function from python `zlib`:
```python
>>> from zlib import adler32
@ -81,7 +80,7 @@ To generate the bits file, use the `adler32` function from python zlib:
2023497376
```
The included `adler32.njs` script can process files or stdin:
The included `adler32.njs` script can process files or standard input:
```bash
$ echo "this is a test" > t.txt
@ -89,7 +88,7 @@ $ bin/adler32.njs t.txt
726861088
```
For comparison, the included `adler32.py` script uses python zlib:
For comparison, the included `adler32.py` script uses python `zlib`:
```bash
$ bin/adler32.py t.txt
@ -101,7 +100,7 @@ $ bin/adler32.py t.txt
`make perf` will run algorithmic performance tests (which should justify certain
decisions in the code).
Bit twiddling is much faster than taking the mod on Safari and older Firefoxes.
Bit twiddling is much faster than taking the mod in Safari and Firefox browsers.
Instead of taking the literal mod 65521, it is faster to keep it in the integers
by bit-shifting: `65536 ~ 15 mod 65521` so for nonnegative integer `a`:
@ -122,7 +121,7 @@ F[255] (* bstr: x \[Element] Integers && 1 <= x <= 3854 *)
F[127] (* ascii: x \[Element] Integers && 1 <= x <= 5321 *)
```
Subtract up to 4 elements for the unicode case.
Subtract up to 4 elements for the Unicode case.
## License

View File

@ -1,32 +1,34 @@
/* adler32.js (C) 2014-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
/*exported ADLER32 */
var ADLER32;
/*:: declare var DO_NOT_EXPORT_ADLER: any; */
/*:: declare var define: any; */
(function (factory) {
/*:: declare var DO_NOT_EXPORT_ADLER:?boolean; */
/*:: declare function define(cb:()=>any):void; */
var ADLER32/*:ADLER32Module*/;
(function (factory/*:(a:any)=>void*/)/*:void*/ {
/*jshint ignore:start */
/*eslint-disable */
if(typeof DO_NOT_EXPORT_ADLER === 'undefined') {
if('object' === typeof exports) {
factory(exports);
} else if ('function' === typeof define && define.amd) {
define(function () {
var module = {};
var module/*:ADLER32Module*/ = /*::(*/{}/*:: :any)*/;
factory(module);
return module;
});
} else {
factory(ADLER32 = {});
factory(ADLER32 = /*::(*/{}/*:: :any)*/);
}
} else {
factory(ADLER32 = {});
factory(ADLER32 = /*::(*/{}/*:: :any)*/);
}
/*eslint-enable */
/*jshint ignore:end */
}(function(ADLER32) {
ADLER32.version = '1.1.0';
}(function(ADLER32/*:ADLER32Module*/) {
ADLER32.version = '1.2.0';
/*::
type ADLER32Type = number;
type ABuf = Array<number> | Buffer;
type ABuf = Array<number> | Buffer | Uint8Array;
*/
/*# consult README.md for the magic number */
/*# charCodeAt is the best approach for binary strings */
@ -90,7 +92,10 @@ function adler32_str(str/*:string*/, seed/*:?ADLER32Type*/)/*:ADLER32Type*/ {
}
return ((b%65521) << 16) | (a%65521);
}
// $FlowIgnore
ADLER32.bstr = adler32_bstr;
// $FlowIgnore
ADLER32.buf = adler32_buf;
// $FlowIgnore
ADLER32.str = adler32_str;
}));

View File

@ -4,6 +4,7 @@
var ADLER32;
(function (factory) {
/*jshint ignore:start */
/*eslint-disable */
if(typeof DO_NOT_EXPORT_ADLER === 'undefined') {
if('object' === typeof exports) {
factory(exports);
@ -19,9 +20,10 @@ var ADLER32;
} else {
factory(ADLER32 = {});
}
/*eslint-enable */
/*jshint ignore:end */
}(function(ADLER32) {
ADLER32.version = '1.1.0';
ADLER32.version = '1.2.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; }
@ -81,7 +83,10 @@ function adler32_str(str, seed) {
}
return ((b%65521) << 16) | (a%65521);
}
// $FlowIgnore
ADLER32.bstr = adler32_bstr;
// $FlowIgnore
ADLER32.buf = adler32_buf;
// $FlowIgnore
ADLER32.str = adler32_str;
}));

View File

@ -1,6 +1,8 @@
#!/usr/bin/env node
/* adler32.js (C) 2014-present SheetJS -- http://sheetjs.com */
/* eslint-env node */
/* vim: set ts=2 ft=javascript: */
/*jshint node:true */
var X/*:ADLER32Module*/;
try { X = require('../'); } catch(e) { X = require('adler-32'); }

View File

@ -1,25 +1,27 @@
/* adler32.js (C) 2014-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
/*exported ADLER32 */
var ADLER32;
/*:: declare var DO_NOT_EXPORT_ADLER: any; */
/*:: declare var define: any; */
(function (factory) {
/*:: declare var DO_NOT_EXPORT_ADLER:?boolean; */
/*:: declare function define(cb:()=>any):void; */
var ADLER32/*:ADLER32Module*/;
(function (factory/*:(a:any)=>void*/)/*:void*/ {
/*jshint ignore:start */
/*eslint-disable */
if(typeof DO_NOT_EXPORT_ADLER === 'undefined') {
if('object' === typeof exports) {
factory(exports);
} else if ('function' === typeof define && define.amd) {
define(function () {
var module = {};
var module/*:ADLER32Module*/ = /*::(*/{}/*:: :any)*/;
factory(module);
return module;
});
} else {
factory(ADLER32 = {});
factory(ADLER32 = /*::(*/{}/*:: :any)*/);
}
} else {
factory(ADLER32 = {});
factory(ADLER32 = /*::(*/{}/*:: :any)*/);
}
/*eslint-enable */
/*jshint ignore:end */
}(function(ADLER32) {
}(function(ADLER32/*:ADLER32Module*/) {

View File

@ -1 +1 @@
ADLER32.version = '1.1.0';
ADLER32.version = '1.2.0';

View File

@ -1,4 +1,4 @@
/*::
type ADLER32Type = number;
type ABuf = Array<number> | Buffer;
type ABuf = Array<number> | Buffer | Uint8Array;
*/

View File

@ -1,3 +1,6 @@
// $FlowIgnore
ADLER32.bstr = adler32_bstr;
// $FlowIgnore
ADLER32.buf = adler32_buf;
// $FlowIgnore
ADLER32.str = adler32_str;

View File

@ -4,6 +4,7 @@
var ADLER32;
(function (factory) {
/*jshint ignore:start */
/*eslint-disable */
if(typeof DO_NOT_EXPORT_ADLER === 'undefined') {
if('object' === typeof exports) {
factory(exports);
@ -19,9 +20,10 @@ var ADLER32;
} else {
factory(ADLER32 = {});
}
/*eslint-enable */
/*jshint ignore:end */
}(function(ADLER32) {
ADLER32.version = '1.1.0';
ADLER32.version = '1.2.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; }
@ -81,7 +83,10 @@ function adler32_str(str, seed) {
}
return ((b%65521) << 16) | (a%65521);
}
// $FlowIgnore
ADLER32.bstr = adler32_bstr;
// $FlowIgnore
ADLER32.buf = adler32_buf;
// $FlowIgnore
ADLER32.str = adler32_str;
}));

View File

@ -22,13 +22,10 @@ var bits = [
];
if(typeof module !== "undefined") module.exports = bits;
/*::
type ArrayLike = any;
type Stringifier = {(d:ArrayLike):string};
declare class ADLER32Module {
bstr(s:string, seed:?ADLER32Type):ADLER32Type;
buf(b:ABuf, seed:?ADLER32Type):ADLER32Type;
str(s:string, seed:?ADLER32Type):ADLER32Type;
bstr(s:string, seed?:ADLER32Type):ADLER32Type;
buf(b:ABuf, seed?:ADLER32Type):ADLER32Type;
str(s:string, seed?:ADLER32Type):ADLER32Type;
version:string;
};
*/

View File

@ -1,5 +1,6 @@
/*jshint browser:true */
/*global ADLER32, console */
/*eslint-env browser */
/*global ADLER32, console, Uint8Array */
/*:: declare var ADLER32: ADLER32Module; */
var X = ADLER32;
@ -17,6 +18,10 @@ function is_defined(val/*:any*/, keys/*:Array<string>*/)/*: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/*:ADLER32Type*/ = rABS ? X.bstr(data) : X.str(bstrify(data));
var val/*:ADLER32Type*/ = rABS ? X.bstr(/*::(*/data/*:: :any)*/) : X.str(bstrify(data));
process_value(val);
};

View File

@ -1,5 +1,6 @@
/*jshint browser:true */
/*global ADLER32, console */
/*eslint-env browser */
/*global ADLER32, console, Uint8Array */
var X = ADLER32;
function console_log() { if(typeof console !== 'undefined') console.log.apply(console, [].slice.call(arguments)); }

View File

@ -45,6 +45,7 @@ Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" c
<script src="adler32.js"></script>
<script src="demo/browser.flow.js"></script>
<script type="text/javascript">
/*eslint-env browser */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36810333-1']);
_gaq.push(['_trackPageview']);

View File

@ -1,11 +1,8 @@
/*::
type ArrayLike = any;
type Stringifier = {(d:ArrayLike):string};
declare class ADLER32Module {
bstr(s:string, seed:?ADLER32Type):ADLER32Type;
buf(b:ABuf, seed:?ADLER32Type):ADLER32Type;
str(s:string, seed:?ADLER32Type):ADLER32Type;
bstr(s:string, seed?:ADLER32Type):ADLER32Type;
buf(b:ABuf, seed?:ADLER32Type):ADLER32Type;
str(s:string, seed?:ADLER32Type):ADLER32Type;
version:string;
};
*/

View File

@ -1,6 +1,6 @@
{
"name": "adler-32",
"version": "1.1.0",
"version": "1.2.0",
"author": "sheetjs",
"description": "Pure-JS ADLER-32",
"keywords": [ "adler32", "checksum" ],
@ -8,25 +8,34 @@
"adler32": "./bin/adler32.njs"
},
"main": "./adler32",
"types": "types",
"dependencies": {
"printj":"~1.1.0",
"exit-on-epipe":"~1.0.1"
},
"devDependencies": {
"mocha":"~2.5.3",
"codepage":"~1.10.0"
"blanket": "~1.2.3",
"codepage":"~1.10.0",
"@sheetjs/uglify-js":"~2.7.3",
"@types/node":"^8.0.7",
"dtslint": "^0.1.2",
"typescript": "2.2.0"
},
"repository": { "type":"git", "url":"git://github.com/SheetJS/js-adler32.git" },
"scripts": {
"pretest": "git submodule init && git submodule update",
"test": "make test"
"test": "make test",
"build": "make",
"lint": "make fullint",
"dtslint": "dtslint types"
},
"config": {
"blanket": {
"pattern": "adler32.js"
}
},
"files": ["adler32.js", "bin/adler32.njs", "LICENSE", "README.md"],
"homepage": "http://sheetjs.com/opensource",
"files": ["adler32.js", "bin/adler32.njs", "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" }

9
types/adler32-test.ts Normal file
View File

@ -0,0 +1,9 @@
import { buf, bstr, str } from 'adler-32';
const t1: number = buf([1,2,3,4,5]);
const t3: number = bstr("\u0001\u0002\u0003\u0004\u0005");
const t5: number = str("\u0001\u0002\u0003\u0004\u0005");
const t2: number = buf(new Uint8Array([1,2,3,4,5]), t3);
const t4: number = bstr("\u0001\u0002\u0003\u0004\u0005", t5);
const t6: number = str("\u0001\u0002\u0003\u0004\u0005", t1);

90
types/bin_adler32.ts Executable file
View File

@ -0,0 +1,90 @@
/* adler32.js (C) 2014-present SheetJS -- http://sheetjs.com */
/* eslint-env node */
/* vim: set ts=2 ft=javascript: */
/*jshint node:true */
/// <reference types="../node_modules/@types/node/" />
/* node type definition is missing writable stream _writev */
interface Chunk { chunk: any; encoding: string; }
type CBType = () => void;
import X = require("adler-32");
import 'exit-on-epipe';
import fs = require('fs');
import stream = require('stream');
import { sprintf } from "printj";
const help = (): number => {
[
"usage: adler32 [options] [filename]",
"",
"Options:",
" -h, --help output usage information",
" -V, --version output the version number",
" -S, --seed=<n> use integer seed as starting value (default 1)",
" -H, --hex-seed=<h> use hex seed as starting value (default 1)",
" -d, --signed print result with format `%d` (default)",
" -u, --unsigned print result with format `%u`",
" -x, --hex print result with format `%0.8x`",
" -X, --HEX print result with format `%0.8X`",
" -F, --format=<s> use specified printf format",
"",
"Set filename = '-' or pipe data into adler32 to read from stdin",
"Default output mode is signed (-d)",
""
].forEach(function(l) { console.log(l); });
return 0;
};
const version = (): number => { console.log(X.version); return 0; };
const die = (msg: string, ec?: number): void => { console.error(msg); process.exit(ec || 0); };
const args/*:Array<string>*/ = process.argv.slice(2);
let filename/*:string*/ = "";
let fmt/*:string*/ = "";
let seed = 0, r = 10;
for(let i = 0; i < args.length; ++i) {
const arg = args[i];
if(arg.charCodeAt(0) !== 45) { if(filename === "") filename = arg; continue; }
const m = arg.indexOf("=") === -1 ? arg : arg.substr(0, arg.indexOf("="));
switch(m) {
case "-": filename = "-"; break;
case "--help": case "-h": process.exit(help()); break;
case "--version": case "-V": process.exit(version()); break;
case "--signed": case "-d": fmt = "%d"; break;
case "--unsigned": case "-u": fmt = "%u"; break;
case "--hex": case "-x": fmt = "%0.8x"; break;
case "--HEX": case "-X": fmt = "%0.8X"; break;
case "--format": case "-F":
fmt = ((m!==arg) ? arg.substr(m.length+1) : args[++i])||""; break;
case "--hex-seed": case "-H": r = 16;
/* falls through */
case "--seed": case "-S":
seed=parseInt((m!==arg) ? arg.substr(m.length+1) : args[++i], r)||0; break;
default: die("adler32: unrecognized option `" + arg + "'", 22);
}
}
if(!process.stdin.isTTY) filename = filename || "-";
if(filename.length===0) die("adler32: must specify a filename ('-' for stdin)",1);
let adler32 = seed;
// $FlowIgnore -- Writable is callable but type sig disagrees
const writable = new stream.Writable();
writable._write = (chunk: any, e: string, cb: CBType) => { adler32 = X.buf(chunk, adler32); cb(); };
(<any>writable)._writev = (chunks: Chunk[], cb: CBType) => {
chunks.forEach(function(c) { adler32 = X.buf(c.chunk, adler32);}); cb();
};
writable.on('finish', () => {
console.log(fmt === "" ? adler32 : sprintf(fmt, adler32));
});
if(filename === "-") process.stdin.pipe(writable);
else if(fs.existsSync(filename)) fs.createReadStream(filename).pipe(writable);
else die("adler32: " + filename + ": No such file or directory", 2);

14
types/index.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
/* adler32.js (C) 2014-present SheetJS -- http://sheetjs.com */
// TypeScript Version: 2.2
/** Version string */
export const version: string;
/** Process a node buffer or byte array */
export function buf(data: number[] | Uint8Array, seed?: number): number;
/** Process a binary string */
export function bstr(data: string, seed?: number): number;
/** Process a JS string based on the UTF8 encoding */
export function str(data: string, seed?: number): number;

14
types/tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [ "es5" ],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"baseUrl": ".",
"paths": { "adler-32": ["."] },
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}

11
types/tslint.json Normal file
View File

@ -0,0 +1,11 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"whitespace": false,
"no-sparse-arrays": false,
"only-arrow-functions": false,
"no-consecutive-blank-lines": false,
"prefer-conditional-expression": false,
"one-variable-per-declaration": false
}
}