Skip to content

Commit f6de179

Browse files
committed
version bump 0.10.2: infrastructure
- typescript definitions - fixed vulnerable regexes (h/t @davisjam)
1 parent 71f827c commit f6de179

20 files changed

+194
-34
lines changed

.eslintrc

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
"env": { "shared-node-browser":true },
33
"globals": {},
44
"parserOptions": {
5-
"ecmaVersion": 3,
5+
"ecmaVersion": 3
66
},
77
"plugins": [ "html", "json" ],
88
"extends": "eslint:recommended",
99
"rules": {
10+
"comma-style": [ 2, "last" ],
11+
"comma-dangle": [ 2, "never" ],
12+
"curly": 0,
13+
"no-bitwise": 0,
14+
"no-console": 0,
15+
"no-control-regex": 0,
16+
"no-empty": 0,
17+
"no-trailing-spaces": 2,
1018
"no-use-before-define": [ 1, {
1119
"functions":false, "classes":true, "variables":false
1220
}],
13-
"no-bitwise": 0,
14-
"curly": 0,
15-
"comma-style": [ 2, "last" ],
16-
"no-trailing-spaces": 2,
17-
"semi": [ 2, "always" ],
18-
"comma-dangle": [ 2, "never" ]
21+
"no-useless-escape": 0,
22+
"semi": [ 2, "always" ]
1923
}
2024
}

.flowconfig

+5
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ misc/flowdeps.js
2727
[options]
2828
module.file_ext=.js
2929
module.file_ext=.njs
30+
module.ignore_non_literal_requires=true
31+
suppress_comment= \\(.\\|\n\\)*\\$FlowIgnore
32+
33+
[lints]
34+
deprecated-declare-exports=off

.npmignore

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,27 @@ tmp
1313
*.[pP][rR][nN]
1414
*.[sS][lL][kK]
1515
*.socialcalc
16-
*.[xX][lL][sSwWcC]
17-
*.[xX][lL][sS][xXmMbB]
16+
*.[xX][lL][sSwWcCaAtTmM]
17+
*.[xX][lL][sSaAtT][xXmMbB]
1818
*.[oO][dD][sS]
1919
*.[fF][oO][dD][sS]
2020
*.[xX][mM][lL]
2121
*.[uU][oO][sS]
2222
*.[wW][kKqQbB][S1234567890]
2323
*.[qQ][pP][wW]
24+
*.[bB][iI][fF][fF][23458]
25+
*.[rR][tT][fF]
26+
*.[eE][tT][hH]
2427
*.123
2528
*.htm
2629
*.html
2730
*.sheetjs
2831
*.exe
32+
*.img
2933
.gitignore
34+
.gitattributes
35+
.fossaignore
36+
.spelling
3037
.eslintrc
3138
.jshintrc
3239
Makefile

.spelling

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ssf.js (C) 2013-present SheetJS -- http://sheetjs.com
2+
SheetJS
3+
ssf
4+
5+
ECMA-376
6+
xls
7+
xlsb
8+
9+
npm

Makefile

+16-3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ ctestserv: ## Start a test server on port 8000
6060

6161
## Code Checking
6262

63+
.PHONY: fullint
64+
fullint: lint old-lint tslint flow mdlint ## Run all checks
65+
6366
.PHONY: lint
6467
lint: $(TARGET) $(AUXTARGETS) ## Run eslint checks
6568
@eslint --ext .js,.njs,.json,.html,.htm $(TARGET) $(AUXTARGETS) $(CMDS) $(HTMLLINT) package.json bower.json
@@ -68,13 +71,18 @@ lint: $(TARGET) $(AUXTARGETS) ## Run eslint checks
6871
.PHONY: old-lint
6972
old-lint: $(TARGET) $(AUXTARGETS) ## Run jshint and jscs checks
7073
@jshint --show-non-errors $(TARGET) $(AUXTARGETS)
71-
@jshint --show-non-errors test/
7274
@jshint --show-non-errors $(CMDS)
73-
@jshint --show-non-errors package.json
75+
@jshint --show-non-errors package.json test/
7476
@jshint --show-non-errors --extract=always $(HTMLLINT)
75-
@jscs $(TARGET) $(AUXTARGETS)
77+
@jscs $(TARGET) $(AUXTARGETS) test/*.js
7678
if [ -e $(CLOSURE) ]; then java -jar $(CLOSURE) $(REQS) $(FLOWTARGET) --jscomp_warning=reportUnknownTypes >/dev/null; fi
7779

80+
.PHONY: tslint
81+
tslint: $(TARGET) ## Run typescript checks
82+
#@npm install dtslint typescript
83+
#@npm run-script dtslint
84+
dtslint types
85+
7886
.PHONY: flow
7987
flow: lint ## Run flow checker
8088
@flow check --all --show-all-errors
@@ -97,6 +105,11 @@ full_coveralls:
97105
coveralls: ## Coverage Test + Send to coveralls.io
98106
MINTEST=1 make full_coveralls
99107

108+
MDLINT=README.md
109+
.PHONY: mdlint
110+
mdlint: $(MDLINT) ## Check markdown documents
111+
alex $^
112+
mdspell -a -n -x -r --en-us $^
100113

101114
.PHONY: help
102115
help:

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# [SheetJS SSF](http://sheetjs.com)
22

3-
ssf (SpreadSheet Format) is a pure-JS library to format data using ECMA-376
3+
ssf (SpreadSheet Format) is a pure JS library to format data using ECMA-376
44
spreadsheet format codes (used in popular spreadsheet software packages).
55

66

@@ -23,9 +23,8 @@ The browser exposes a variable `SSF`
2323
When installed globally, npm installs a script `ssf` that renders the format
2424
string with the given arguments. Running the script with `-h` displays help.
2525

26-
The script will manipulate `module.exports` if available (e.g. in a CommonJS
27-
`require` context). This is not always desirable. To prevent the behavior,
28-
define `DO_NOT_EXPORT_SSF`.
26+
The script will manipulate `module.exports` if available . This is not always
27+
desirable. To prevent the behavior, define `DO_NOT_EXPORT_SSF`.
2928

3029
## Usage
3130

@@ -41,7 +40,7 @@ The options argument may contain the following keys:
4140

4241
| Option Name | Default | Description |
4342
| :---------- | :-----: | :--------------------------------------------------- |
44-
| date1904 | false | Use 1904 date system if true, 1900 system if false |
43+
| `date1904` | false | Use 1904 date system if true, 1900 system if false |
4544

4645
### Manipulating the Internal Format Table
4746

@@ -89,8 +88,9 @@ granted by the Apache 2.0 license are reserved by the Original Author.
8988
9089
## References
9190
92-
- [ECMA-376] Office Open XML File Formats
93-
- [MS-XLSB] Excel (.xlsb) Binary File Format
91+
- `ECMA-376`: Office Open XML File Formats
92+
- `MS-XLS`: Excel Binary File Format (.xls) Structure Specification
93+
- `MS-XLSB`: Excel (.xlsb) Binary File Format
9494
9595
## Badges
9696

bin/ssf.njs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* ssf.js (C) 2013-present SheetJS -- http://sheetjs.com */
33
/* eslint-env node */
44
/* eslint no-console:0 */
5+
/*jshint node:true */
56
var X = require('../');
67
var argv = process.argv.slice(2);
78
if(argv.length < 2 || argv[0] == "-h" || argv[0] == "--help") {

bits/01_version.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SSF.version = '0.10.1';
1+
SSF.version = '0.10.2';

bits/88_cond.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var cfregex = /\[[=<>]/;
2-
var cfregex2 = /\[([=<>]*)(-?\d+\.?\d*)\]/;
2+
var cfregex2 = /\[(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)\]/;
33
function chkcond(v, rr) {
44
if(rr == null) return false;
55
var thresh = parseFloat(rr[2]);

index.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<script>
2828
/*jshint browser:true */
2929
/*eslint-env browser */
30+
/*eslint no-use-before-define:0 */
3031
/*global SSF */
3132
var F = document.getElementById('fmt');
3233
var V = document.getElementById('val');
@@ -55,8 +56,6 @@
5556
}
5657

5758
update();
58-
</script>
59-
<script type="text/javascript">
6059
var _gaq = _gaq || [];
6160
_gaq.push(['_setAccount', 'UA-36810333-1']);
6261
_gaq.push(['_trackPageview']);

package.json

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
{
22
"name": "ssf",
3-
"version": "0.10.1",
3+
"version": "0.10.2",
44
"author": "sheetjs",
55
"description": "Format data using ECMA-376 spreadsheet Format Codes",
66
"keywords": [ "format", "sprintf", "spreadsheet" ],
77
"bin": {
88
"ssf": "./bin/ssf.njs"
99
},
1010
"main": "./ssf",
11+
"types": "types",
1112
"dependencies": {
12-
"frac":"~1.1.0"
13+
"frac":"~1.1.2"
1314
},
1415
"devDependencies": {
15-
"mocha":"~2.5.3",
16+
"mocha": "~2.5.3",
1617
"blanket": "~1.2.3",
17-
"@sheetjs/uglify-js":"~2.7.3"
18+
"@sheetjs/uglify-js":"~2.7.3",
19+
"@types/node":"^8.0.7",
20+
"dtslint": "^0.1.2",
21+
"typescript": "2.2.0"
1822
},
1923
"repository": { "type":"git", "url":"git://github.com/SheetJS/ssf.git" },
2024
"scripts": {
21-
"test": "make test"
25+
"test": "make test",
26+
"build": "make",
27+
"lint": "make fullint",
28+
"dtslint": "dtslint types"
2229
},
2330
"config": {
2431
"blanket": {
2532
"pattern": "ssf.js"
2633
}
2734
},
28-
"homepage": "https://oss.sheetjs.com/ssf",
35+
"homepage": "http://sheetjs.com/opensource",
2936
"bugs": { "url": "https://github.com/SheetJS/ssf/issues" },
3037
"license": "Apache-2.0",
3138
"engines": { "node": ">=0.8" }

ssf.flow.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/*:: declare var DO_NOT_EXPORT_SSF: any; */
55
var SSF/*:SSFModule*/ = ({}/*:any*/);
66
var make_ssf = function make_ssf(SSF/*:SSFModule*/){
7-
SSF.version = '0.10.1';
7+
SSF.version = '0.10.2';
88
function _strrev(x/*:string*/)/*:string*/ { var o = "", i = x.length-1; while(i>=0) o += x.charAt(i--); return o; }
99
function fill(c/*:string*/,l/*:number*/)/*:string*/ { var o = ""; while(o.length < l) o+=c; return o; }
1010
function pad0(v/*:any*/,d/*:number*/)/*:string*/{var t=""+v; return t.length>=d?t:fill('0',d-t.length)+t;}
@@ -793,7 +793,7 @@ function eval_fmt(fmt/*:string*/, v/*:any*/, opts/*:any*/, flen/*:number*/) {
793793
}
794794
SSF._eval = eval_fmt;
795795
var cfregex = /\[[=<>]/;
796-
var cfregex2 = /\[([=<>]*)(-?\d+\.?\d*)\]/;
796+
var cfregex2 = /\[(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)\]/;
797797
function chkcond(v, rr) {
798798
if(rr == null) return false;
799799
var thresh = parseFloat(rr[2]);

ssf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*jshint -W041 */
44
var SSF = ({});
55
var make_ssf = function make_ssf(SSF){
6-
SSF.version = '0.10.1';
6+
SSF.version = '0.10.2';
77
function _strrev(x) { var o = "", i = x.length-1; while(i>=0) o += x.charAt(i--); return o; }
88
function fill(c,l) { var o = ""; while(o.length < l) o+=c; return o; }
99
function pad0(v,d){var t=""+v; return t.length>=d?t:fill('0',d-t.length)+t;}
@@ -783,7 +783,7 @@ out[i].v = write_date(out[i].t.charCodeAt(0), out[i].v, dt, ss0);
783783
}
784784
SSF._eval = eval_fmt;
785785
var cfregex = /\[[=<>]/;
786-
var cfregex2 = /\[([=<>]*)(-?\d+\.?\d*)\]/;
786+
var cfregex2 = /\[(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)\]/;
787787
function chkcond(v, rr) {
788788
if(rr == null) return false;
789789
var thresh = parseFloat(rr[2]);

test/dateNF.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* vim: set ts=2: */
22
/*jshint loopfunc:true, mocha:true, node:true */
33
var SSF = require('../');
4-
var fs = require('fs'), assert = require('assert');
4+
var assert = require('assert');
55
describe('dateNF override', function() {
66
it('should override format code 14', function() {
77
assert.equal(SSF.format(14, 43880), "2/19/20");

types/.npmignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Makefile
2+
*ssf*.ts
3+
doc.ts
4+
write.ts
5+
tslint.json

types/bin_ssf.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* ssf.js (C) 2013-present SheetJS -- http://sheetjs.com */
2+
/* eslint-env node */
3+
/* eslint no-console:0 */
4+
/*jshint node:true */
5+
/// <reference types="../node_modules/@types/node/" />
6+
import X = require('ssf');
7+
const argv = process.argv.slice(2);
8+
if(argv.length < 2 || argv[0] === "-h" || argv[0] === "--help") {
9+
console.error("usage: ssf <format> <value>");
10+
console.error("output: format_as_string|format_as_number|");
11+
process.exit(0);
12+
}
13+
console.log(X.format(argv[0],argv[1]) + "|" + X.format(argv[0],+(argv[1])) + "|");

types/index.d.ts

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* ssf.js (C) 2013-present SheetJS -- http://sheetjs.com */
2+
// TypeScript Version: 2.2
3+
4+
/** Version string */
5+
export const version: string;
6+
7+
/** Render value using format string or code */
8+
export function format(fmt: string|number, val: any, opts?: any): string;
9+
10+
/** Load format string */
11+
export function load(fmt: string, idx?: number): number;
12+
13+
/** Test if the format is a Date format */
14+
export function is_date(fmt: string): boolean;
15+
16+
17+
/** Format Table */
18+
export interface SSF$Table {
19+
[key: number]: string;
20+
[key: string]: string;
21+
}
22+
23+
/** Get format table */
24+
export function get_table(): SSF$Table;
25+
26+
/** Set format table */
27+
export function load_table(tbl: SSF$Table): void;
28+
29+
30+
/** Parsed date */
31+
export interface SSF$Date {
32+
/** number of whole days since relevant epoch, 0 <= D */
33+
D: number;
34+
/** integral year portion, epoch_year <= y */
35+
y: number;
36+
/** integral month portion, 1 <= m <= 12 */
37+
m: number;
38+
/** integral day portion, subject to gregorian YMD constraints */
39+
d: number;
40+
/** integral day of week (0=Sunday .. 6=Saturday) 0 <= q <= 6 */
41+
q: number;
42+
43+
/** number of seconds since midnight, 0 <= T < 86400 */
44+
T: number;
45+
/** integral number of hours since midnight, 0 <= H < 24 */
46+
H: number;
47+
/** integral number of minutes since the last hour, 0 <= M < 60 */
48+
M: number;
49+
/** integral number of seconds since the last minute, 0 <= S < 60 */
50+
S: number;
51+
/** sub-second part of time, 0 <= u < 1 */
52+
u: number;
53+
}
54+
55+
/** Parse numeric date code */
56+
export function parse_date_code(v: number, opts?: any): SSF$Date;

types/ssf-test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { format, load, get_table, load_table, parse_date_code, is_date, SSF$Table, SSF$Date } from 'ssf';
2+
3+
const t1: string = format("General", 123.456);
4+
const t2: string = format(0, 234.567);
5+
const t3: string = format("@", "1234.567");
6+
7+
load('"This is "0.00', 70);
8+
load('"This is "0');
9+
10+
const tbl: SSF$Table = get_table();
11+
load_table(tbl);
12+
13+
const date: SSF$Date = parse_date_code(43150);
14+
const sum: number = date.D + date.T + date.y + date.m + date.d + date.H + date.M + date.S + date.q + date.u;
15+
16+
const isdate: boolean = is_date("YYYY-MM-DD");

types/tsconfig.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [ "es5" ],
5+
"noImplicitAny": true,
6+
"noImplicitThis": true,
7+
"strictNullChecks": false,
8+
"baseUrl": ".",
9+
"paths": { "ssf": ["."] },
10+
"types": [],
11+
"noEmit": true,
12+
"forceConsistentCasingInFileNames": true
13+
}
14+
}

0 commit comments

Comments
 (0)