From 2253617eaedb9c4e774faecd3e38cae801311430 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Thu, 14 Sep 2017 01:28:47 -0400 Subject: [PATCH] version bump 1.1.1: typescript definitions --- Makefile | 4 ++ README.md | 5 ++- bits/01_version.js | 2 +- crc32.flow.js | 2 +- crc32.js | 2 +- ctest/crc32.js | 2 +- demo/browser.flow.js | 2 +- demo/browser.js | 2 +- package.json | 15 ++++++-- types/bin_crc32.ts | 89 ++++++++++++++++++++++++++++++++++++++++++++ types/crc32-test.ts | 9 +++++ types/index.d.ts | 14 +++++++ types/tsconfig.json | 14 +++++++ types/tslint.json | 11 ++++++ 14 files changed, 161 insertions(+), 12 deletions(-) create mode 100755 types/bin_crc32.ts create mode 100644 types/crc32-test.ts create mode 100644 types/index.d.ts create mode 100644 types/tsconfig.json create mode 100644 types/tslint.json diff --git a/Makefile b/Makefile index 739f1d2..328f81c 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,10 @@ 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 .PHONY: flow flow: lint ## Run flow checker diff --git a/README.md b/README.md index 1546c71..0339117 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,8 @@ granted by the Apache 2.0 license are reserved by the Original Author. [![Sauce Test Status](https://saucelabs.com/browser-matrix/crc32.svg)](https://saucelabs.com/u/crc32) [![Build Status](https://travis-ci.org/SheetJS/js-crc32.svg?branch=master)](https://travis-ci.org/SheetJS/js-crc32) - [![Coverage Status](http://img.shields.io/coveralls/SheetJS/js-crc32/master.svg)](https://coveralls.io/r/SheetJS/js-crc32?branch=master) - +[![Dependencies Status](https://david-dm.org/sheetjs/js-crc32/status.svg)](https://david-dm.org/sheetjs/js-crc32) +[![NPM Downloads](https://img.shields.io/npm/dt/crc-32.svg)](https://npmjs.org/package/crc-32) +[![ghit.me](https://ghit.me/badge.svg?repo=sheetjs/js-xlsx)](https://ghit.me/repo/sheetjs/js-xlsx) [![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-crc32?pixel)](https://github.com/SheetJS/js-crc32) diff --git a/bits/01_version.js b/bits/01_version.js index 4122dea..3a33569 100644 --- a/bits/01_version.js +++ b/bits/01_version.js @@ -1 +1 @@ -CRC32.version = '1.1.0'; +CRC32.version = '1.1.1'; diff --git a/crc32.flow.js b/crc32.flow.js index d06efb5..0004d7f 100644 --- a/crc32.flow.js +++ b/crc32.flow.js @@ -23,7 +23,7 @@ var CRC32; } /*jshint ignore:end */ }(function(CRC32) { -CRC32.version = '1.1.0'; +CRC32.version = '1.1.1'; /*:: type CRC32Type = number; type ABuf = Array | Uint8Array | Buffer; diff --git a/crc32.js b/crc32.js index e40f80b..fb31412 100644 --- a/crc32.js +++ b/crc32.js @@ -21,7 +21,7 @@ var CRC32; } /*jshint ignore:end */ }(function(CRC32) { -CRC32.version = '1.1.0'; +CRC32.version = '1.1.1'; /* see perf/crc32table.js */ /*global Int32Array */ function signed_crc_table() { diff --git a/ctest/crc32.js b/ctest/crc32.js index e40f80b..fb31412 100644 --- a/ctest/crc32.js +++ b/ctest/crc32.js @@ -21,7 +21,7 @@ var CRC32; } /*jshint ignore:end */ }(function(CRC32) { -CRC32.version = '1.1.0'; +CRC32.version = '1.1.1'; /* see perf/crc32table.js */ /*global Int32Array */ function signed_crc_table() { diff --git a/demo/browser.flow.js b/demo/browser.flow.js index 1fc81bd..fc833a8 100644 --- a/demo/browser.flow.js +++ b/demo/browser.flow.js @@ -66,7 +66,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) : 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 d3d2933..c5cc1f7 100644 --- a/demo/browser.js +++ b/demo/browser.js @@ -57,7 +57,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/package.json b/package.json index 0256bd4..1c6d8bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crc-32", - "version": "1.1.0", + "version": "1.1.1", "author": "sheetjs", "description": "Pure-JS CRC-32", "keywords": [ "crc32", "checksum", "crc" ], @@ -8,24 +8,31 @@ "crc32": "./bin/crc32.njs" }, "main": "./crc32", + "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-crc32.git" }, "scripts": { - "pretest": "git submodule init && git submodule update", - "test": "make test" + "test": "make test", + "dtslint": "dtslint types" }, "config": { "blanket": { "pattern": "crc32.js" } }, + "homepage": "http://sheetjs.com/opensource", "files": ["crc32.js", "bin/crc32.njs", "LICENSE", "README.md"], "bugs": { "url": "https://github.com/SheetJS/js-crc32/issues" }, "license": "Apache-2.0", diff --git a/types/bin_crc32.ts b/types/bin_crc32.ts new file mode 100755 index 0000000..956490c --- /dev/null +++ b/types/bin_crc32.ts @@ -0,0 +1,89 @@ +/* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */ +/* eslint-env node */ +/* vim: set ts=2 ft=javascript: */ +/// +/* node type definition is missing writable stream _writev */ +interface Chunk { chunk: any; encoding: string; } +type CBType = () => void; + +import X = require("crc-32"); +import 'exit-on-epipe'; +import fs = require('fs'); +import stream = require('stream'); +import { sprintf } from "printj"; + +const help = (): number => { +[ +"usage: crc32 [options] [filename]", +"", +"Options:", +" -h, --help output usage information", +" -V, --version output the version number", +" -S, --seed= use integer seed as starting value (rolling CRC)", +" -H, --hex-seed= use hex seed as starting value (rolling CRC)", +" -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= use specified printf format", +"", +"Set filename = '-' or pipe data into crc32 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*/ = 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("crc32: unrecognized option `" + arg + "'", 22); + } +} + +if(!process.stdin.isTTY) filename = filename || "-"; +if(filename.length===0) die("crc32: must specify a filename ('-' for stdin)",1); + +let crc32 = seed; +// $FlowIgnore -- Writable is callable but type sig disagrees +const writable = new stream.Writable(); +writable._write = (chunk: any, e: string, cb: CBType) => { crc32 = X.buf(chunk, crc32); cb(); }; +(writable)._writev = (chunks: Chunk[], cb: CBType) => { + chunks.forEach(function(c) { crc32 = X.buf(c.chunk, crc32);}); cb(); +}; +writable.on('finish', () => { + console.log(fmt === "" ? crc32 : sprintf(fmt, crc32)); +}); + +if(filename === "-") process.stdin.pipe(writable); +else if(fs.existsSync(filename)) fs.createReadStream(filename).pipe(writable); +else die("crc32: " + filename + ": No such file or directory", 2); diff --git a/types/crc32-test.ts b/types/crc32-test.ts new file mode 100644 index 0000000..d4821e5 --- /dev/null +++ b/types/crc32-test.ts @@ -0,0 +1,9 @@ +import { buf, bstr, str } from 'crc-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); diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..1638690 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,14 @@ +/* crc32.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; diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..6e122c7 --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ "es5" ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": ".", + "paths": { "crc-32": ["."] }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + } +} diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 0000000..d9401a9 --- /dev/null +++ b/types/tslint.json @@ -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 + } +}