version bump 1.1.1: typescript definitions
This commit is contained in:
parent
43cef94e0a
commit
2253617eae
4
Makefile
4
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
|
||||
|
@ -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)
|
||||
|
@ -1 +1 @@
|
||||
CRC32.version = '1.1.0';
|
||||
CRC32.version = '1.1.1';
|
||||
|
@ -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<number> | Uint8Array | Buffer;
|
||||
|
2
crc32.js
2
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() {
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
15
package.json
15
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",
|
||||
|
89
types/bin_crc32.ts
Executable file
89
types/bin_crc32.ts
Executable file
@ -0,0 +1,89 @@
|
||||
/* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */
|
||||
/* eslint-env node */
|
||||
/* vim: set ts=2 ft=javascript: */
|
||||
/// <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("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=<n> use integer seed as starting value (rolling CRC)",
|
||||
" -H, --hex-seed=<h> 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=<s> 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<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("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(); };
|
||||
(<any>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);
|
9
types/crc32-test.ts
Normal file
9
types/crc32-test.ts
Normal file
@ -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);
|
14
types/index.d.ts
vendored
Normal file
14
types/index.d.ts
vendored
Normal file
@ -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;
|
14
types/tsconfig.json
Normal file
14
types/tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [ "es5" ],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": ".",
|
||||
"paths": { "crc-32": ["."] },
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
11
types/tslint.json
Normal file
11
types/tslint.json
Normal 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user