You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
1.1 KiB

  1. # node-range-parser
  2. Range header field parser.
  3. ## Example:
  4. ```js
  5. assert(-1 == parse(200, 'bytes=500-20'));
  6. assert(-2 == parse(200, 'bytes=malformed'));
  7. parse(200, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 199 }]));
  8. parse(1000, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 499 }]));
  9. parse(1000, 'bytes=40-80').should.eql(arr('bytes', [{ start: 40, end: 80 }]));
  10. parse(1000, 'bytes=-500').should.eql(arr('bytes', [{ start: 500, end: 999 }]));
  11. parse(1000, 'bytes=-400').should.eql(arr('bytes', [{ start: 600, end: 999 }]));
  12. parse(1000, 'bytes=500-').should.eql(arr('bytes', [{ start: 500, end: 999 }]));
  13. parse(1000, 'bytes=400-').should.eql(arr('bytes', [{ start: 400, end: 999 }]));
  14. parse(1000, 'bytes=0-0').should.eql(arr('bytes', [{ start: 0, end: 0 }]));
  15. parse(1000, 'bytes=-1').should.eql(arr('bytes', [{ start: 999, end: 999 }]));
  16. parse(1000, 'items=0-5').should.eql(arr('items', [{ start: 0, end: 5 }]));
  17. parse(1000, 'bytes=40-80,-1').should.eql(arr('bytes', [{ start: 40, end: 80 }, { start: 999, end: 999 }]));
  18. ```
  19. ## Installation
  20. ```
  21. $ npm install range-parser
  22. ```