@gmod/bbi 1.0.28 → 1.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/range.js ADDED
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ /* eslint prefer-rest-params:0, no-nested-ternary:0 */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ /**
5
+ * Adapted from a combination of Range and _Compound in the
6
+ * Dalliance Genome Explorer, (c) Thomas Down 2006-2010.
7
+ */
8
+ class Range {
9
+ constructor(arg1, arg2) {
10
+ this.ranges =
11
+ arguments.length === 2
12
+ ? [{ min: arg1, max: arg2 }]
13
+ : 0 in arg1
14
+ ? Object.assign({}, arg1)
15
+ : [arg1];
16
+ }
17
+ min() {
18
+ return this.ranges[0].min;
19
+ }
20
+ max() {
21
+ return this.ranges[this.ranges.length - 1].max;
22
+ }
23
+ contains(pos) {
24
+ for (let s = 0; s < this.ranges.length; s += 1) {
25
+ const r = this.ranges[s];
26
+ if (r.min <= pos && r.max >= pos) {
27
+ return true;
28
+ }
29
+ }
30
+ return false;
31
+ }
32
+ isContiguous() {
33
+ return this.ranges.length > 1;
34
+ }
35
+ getRanges() {
36
+ return this.ranges.map((r) => new Range(r.min, r.max));
37
+ }
38
+ toString() {
39
+ return this.ranges.map((r) => `[${r.min}-${r.max}]`).join(',');
40
+ }
41
+ union(s1) {
42
+ const ranges = this.getRanges().concat(s1.getRanges()).sort(this.rangeOrder);
43
+ const oranges = [];
44
+ let current = ranges[0];
45
+ for (let i = 1; i < ranges.length; i += 1) {
46
+ const nxt = ranges[i];
47
+ if (nxt.min() > current.max() + 1) {
48
+ oranges.push(current);
49
+ current = nxt;
50
+ }
51
+ else if (nxt.max() > current.max()) {
52
+ current = new Range(current.min(), nxt.max());
53
+ }
54
+ }
55
+ oranges.push(current);
56
+ if (oranges.length === 1) {
57
+ return oranges[0];
58
+ }
59
+ return new Range(oranges);
60
+ }
61
+ intersection(arg) {
62
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
63
+ let s0 = this;
64
+ let s1 = arg;
65
+ const r0 = this.ranges();
66
+ const r1 = s1.ranges();
67
+ const l0 = r0.length;
68
+ const l1 = r1.length;
69
+ let i0 = 0;
70
+ let i1 = 0;
71
+ const or = [];
72
+ while (i0 < l0 && i1 < l1) {
73
+ s0 = r0[i0];
74
+ s1 = r1[i1];
75
+ const lapMin = Math.max(s0.min(), s1.min());
76
+ const lapMax = Math.min(s0.max(), s1.max());
77
+ if (lapMax >= lapMin) {
78
+ or.push(new Range(lapMin, lapMax));
79
+ }
80
+ if (s0.max() > s1.max()) {
81
+ i1 += 1;
82
+ }
83
+ else {
84
+ i0 += 1;
85
+ }
86
+ }
87
+ if (or.length === 0) {
88
+ throw new Error('found range of length 0');
89
+ }
90
+ if (or.length === 1) {
91
+ return or[0];
92
+ }
93
+ return new Range(or);
94
+ }
95
+ coverage() {
96
+ let tot = 0;
97
+ const rl = this.ranges();
98
+ for (let ri = 0; ri < rl.length; ri += 1) {
99
+ const r = rl[ri];
100
+ tot += r.max() - r.min() + 1;
101
+ }
102
+ return tot;
103
+ }
104
+ rangeOrder(tmpa, tmpb) {
105
+ let a = tmpa;
106
+ let b = tmpb;
107
+ if (arguments.length < 2) {
108
+ b = a;
109
+ a = this;
110
+ }
111
+ if (a.min() < b.min()) {
112
+ return -1;
113
+ }
114
+ if (a.min() > b.min()) {
115
+ return 1;
116
+ }
117
+ if (a.max() < b.max()) {
118
+ return -1;
119
+ }
120
+ if (b.max() > a.max()) {
121
+ return 1;
122
+ }
123
+ return 0;
124
+ }
125
+ }
126
+ exports.default = Range;
@@ -0,0 +1,2 @@
1
+ /// <reference types="node" />
2
+ export declare function unzip(input: Buffer): Buffer;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unzip = void 0;
4
+ const pako_1 = require("pako");
5
+ function unzip(input) {
6
+ return Buffer.from((0, pako_1.inflate)(input));
7
+ }
8
+ exports.unzip = unzip;
package/esm/unzip.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { inflateSync } from 'zlib';
2
+ export { inflateSync as unzip };
package/esm/unzip.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unzip = void 0;
4
+ const zlib_1 = require("zlib");
5
+ Object.defineProperty(exports, "unzip", { enumerable: true, get: function () { return zlib_1.inflateSync; } });
package/esm/util.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ export declare class AbortError extends Error {
2
+ code: string;
3
+ constructor(message: string);
4
+ }
5
+ export declare function groupBlocks(blocks: any[]): any[];
6
+ /**
7
+ * Properly check if the given AbortSignal is aborted.
8
+ * Per the standard, if the signal reads as aborted,
9
+ * this function throws either a DOMException AbortError, or a regular error
10
+ * with a `code` attribute set to `ERR_ABORTED`.
11
+ *
12
+ * For convenience, passing `undefined` is a no-op
13
+ *
14
+ * @param {AbortSignal} [signal] an AbortSignal, or anything with an `aborted` attribute
15
+ * @returns nothing
16
+ */
17
+ export declare function checkAbortSignal(signal?: AbortSignal): void;
18
+ /**
19
+ * Skips to the next tick, then runs `checkAbortSignal`.
20
+ * Await this to inside an otherwise synchronous loop to
21
+ * provide a place to break when an abort signal is received.
22
+ * @param {AbortSignal} signal
23
+ */
24
+ export declare function abortBreakPoint(signal?: AbortSignal): Promise<void>;
package/esm/util.js ADDED
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.abortBreakPoint = exports.checkAbortSignal = exports.groupBlocks = exports.AbortError = void 0;
4
+ /* eslint no-bitwise: ["error", { "allow": ["|"] }] */
5
+ class AbortError extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ this.code = 'ERR_ABORTED';
9
+ }
10
+ }
11
+ exports.AbortError = AbortError;
12
+ // sort blocks by file offset and
13
+ // group blocks that are within 2KB of eachother
14
+ function groupBlocks(blocks) {
15
+ blocks.sort((b0, b1) => (b0.offset | 0) - (b1.offset | 0));
16
+ const blockGroups = [];
17
+ let lastBlock;
18
+ let lastBlockEnd;
19
+ for (let i = 0; i < blocks.length; i += 1) {
20
+ if (lastBlock && blocks[i].offset - lastBlockEnd <= 2000) {
21
+ lastBlock.length += blocks[i].length - lastBlockEnd + blocks[i].offset;
22
+ lastBlock.blocks.push(blocks[i]);
23
+ }
24
+ else {
25
+ blockGroups.push((lastBlock = {
26
+ blocks: [blocks[i]],
27
+ length: blocks[i].length,
28
+ offset: blocks[i].offset,
29
+ }));
30
+ }
31
+ lastBlockEnd = lastBlock.offset + lastBlock.length;
32
+ }
33
+ return blockGroups;
34
+ }
35
+ exports.groupBlocks = groupBlocks;
36
+ /**
37
+ * Properly check if the given AbortSignal is aborted.
38
+ * Per the standard, if the signal reads as aborted,
39
+ * this function throws either a DOMException AbortError, or a regular error
40
+ * with a `code` attribute set to `ERR_ABORTED`.
41
+ *
42
+ * For convenience, passing `undefined` is a no-op
43
+ *
44
+ * @param {AbortSignal} [signal] an AbortSignal, or anything with an `aborted` attribute
45
+ * @returns nothing
46
+ */
47
+ function checkAbortSignal(signal) {
48
+ if (!signal) {
49
+ return;
50
+ }
51
+ if (signal.aborted) {
52
+ // console.log('bam aborted!')
53
+ if (typeof DOMException !== 'undefined') {
54
+ throw new DOMException('aborted', 'AbortError');
55
+ }
56
+ else {
57
+ const e = new AbortError('aborted');
58
+ e.code = 'ERR_ABORTED';
59
+ throw e;
60
+ }
61
+ }
62
+ }
63
+ exports.checkAbortSignal = checkAbortSignal;
64
+ /**
65
+ * Skips to the next tick, then runs `checkAbortSignal`.
66
+ * Await this to inside an otherwise synchronous loop to
67
+ * provide a place to break when an abort signal is received.
68
+ * @param {AbortSignal} signal
69
+ */
70
+ async function abortBreakPoint(signal) {
71
+ await Promise.resolve();
72
+ checkAbortSignal(signal);
73
+ }
74
+ exports.abortBreakPoint = abortBreakPoint;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@gmod/bbi",
3
- "version": "1.0.28",
3
+ "version": "1.0.32",
4
4
  "description": "Parser for BigWig/BigBed files",
5
5
  "license": "MIT",
6
6
  "repository": "GMOD/bbi-js",
7
7
  "main": "dist/index.js",
8
+ "module": "esm/index.js",
8
9
  "author": {
9
10
  "name": "Colin Diesh",
10
11
  "email": "colin.diesh@gmail.com",
@@ -14,20 +15,21 @@
14
15
  "node": ">=6"
15
16
  },
16
17
  "files": [
17
- "dist"
18
+ "dist",
19
+ "esm"
18
20
  ],
19
21
  "scripts": {
20
22
  "test": "jest",
21
23
  "coverage": "npm test -- --coverage",
22
24
  "lint": "eslint --report-unused-disable-directives --max-warnings 0 --ext .js,.ts src",
23
- "clean": "rimraf dist",
25
+ "clean": "rimraf dist esm",
24
26
  "prebuild": "npm run clean",
25
- "build:types": "tsc --emitDeclarationOnly",
26
- "build:js": "babel src --out-dir dist --extensions \".ts,.tsx\" --source-maps inline",
27
- "build": "npm run build:types && npm run build:js",
27
+ "build:esm": "tsc --target es2018 --outDir esm",
28
+ "build:es5": "tsc --target es5 --outDir dist",
29
+ "build": "npm run build:esm && npm run build:es5",
28
30
  "preversion": "npm run lint && npm test && npm run build",
29
31
  "version": "standard-changelog && git add CHANGELOG.md",
30
- "postpublish": "git push origin master --follow-tags"
32
+ "postversion": "git push origin master --follow-tags"
31
33
  },
32
34
  "keywords": [
33
35
  "bionode",
@@ -38,44 +40,40 @@
38
40
  "genomics"
39
41
  ],
40
42
  "dependencies": {
41
- "@babel/runtime": "^7.4.4",
42
- "@gmod/binary-parser": "^1.3.5",
43
- "abortable-promise-cache": "^1.0.1",
43
+ "@gmod/binary-parser": "^1.4.0",
44
+ "abortable-promise-cache": "^1.4.1",
44
45
  "buffer-crc32": "^0.2.13",
45
46
  "es6-promisify": "^6.0.1",
46
47
  "generic-filehandle": "^2.0.0",
48
+ "pako": "^1.0.0",
47
49
  "quick-lru": "^4.0.0",
48
50
  "rxjs": "^6.5.2"
49
51
  },
50
52
  "devDependencies": {
51
- "@babel/cli": "^7.4.4",
52
- "@babel/core": "^7.4.4",
53
- "@babel/plugin-proposal-class-properties": "^7.4.4",
54
- "@babel/plugin-transform-runtime": "^7.4.4",
55
- "@babel/preset-env": "^7.4.4",
56
- "@babel/preset-typescript": "^7.3.3",
57
53
  "@gmod/bed": "^2.0.0",
58
- "@types/jest": "^24.0.13",
54
+ "@types/jest": "^27.0.3",
59
55
  "@types/long": "^4.0.0",
60
56
  "@types/node": "^12.0.2",
61
- "@typescript-eslint/eslint-plugin": "^2.0.0",
62
- "@typescript-eslint/parser": "^2.0.0",
63
- "babel-eslint": "^10.0.1",
64
- "babel-preset-typescript": "^7.0.0-alpha.19",
57
+ "@types/pako": "^1.0.3",
58
+ "@typescript-eslint/eslint-plugin": "^5.10.0",
59
+ "@typescript-eslint/parser": "^5.10.0",
65
60
  "cross-fetch": "^3.0.2",
66
- "eslint": "^5.16.0",
67
- "eslint-config-airbnb-base": "^13.1.0",
68
- "eslint-config-prettier": "^4.2.0",
69
- "eslint-plugin-import": "^2.17.2",
70
- "eslint-plugin-jest": "^22.5.1",
71
- "eslint-plugin-prettier": "^3.1.0",
72
- "jest": "^24.8.0",
73
- "prettier": "^1.17.1",
74
- "rimraf": "^2.6.3",
61
+ "eslint": "^8.7.0",
62
+ "eslint-config-prettier": "^8.3.0",
63
+ "eslint-plugin-import": "^2.25.3",
64
+ "eslint-plugin-prettier": "^4.0.0",
65
+ "jest": "^27.4.3",
66
+ "prettier": "^2.5.1",
67
+ "rimraf": "^3.0.2",
75
68
  "standard-changelog": "^2.0.11",
76
- "typescript": "^3.4.5"
69
+ "ts-jest": "^27.0.7",
70
+ "typescript": "^4.5.2"
77
71
  },
78
72
  "publishConfig": {
79
73
  "access": "public"
74
+ },
75
+ "browser": {
76
+ "./esm/unzip.js": "./esm/unzip-pako.js",
77
+ "./dist/unzip.js": "./dist/unzip-pako.js"
80
78
  }
81
79
  }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZXNDb250ZW50IjpbXX0=