@vbarbarosh/node-helpers 3.4.3 → 3.4.4

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.4.3",
5
+ "version": "3.4.4",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -0,0 +1,15 @@
1
+ function parse_http_content_range(value)
2
+ {
3
+ // Content-Range: bytes 262144000-272629759/5037662208
4
+ const m = value.match(/^(\w+)\s+(\d+)-(\d+)[/](\d+)$/);
5
+ if (!m) {
6
+ throw new Error(`Invalid Content-Range: [${value}]`);
7
+ }
8
+ const type = m[1];
9
+ const first = +m[2];
10
+ const last = +m[3];
11
+ const total = +m[4];
12
+ return {type, first, last, total};
13
+ }
14
+
15
+ module.exports = parse_http_content_range;
@@ -0,0 +1,14 @@
1
+ const assert = require('assert');
2
+ const parse_http_content_range = require('./parse_http_content_range');
3
+
4
+ const items = [
5
+ ['bytes 262144000-272629759/5037662208', {type: 'bytes', first: 262144000, last: 272629759, total: 5037662208}],
6
+ ];
7
+
8
+ describe('parse_http_content_range', function () {
9
+ items.forEach(function ([expr, expected]) {
10
+ it(expr, function () {
11
+ assert.deepStrictEqual(parse_http_content_range(expr), expected);
12
+ });
13
+ });
14
+ });