Spaces:
Paused
Paused
Include updated package-lock.json (part 12)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/strip-comments/CHANGELOG.md +136 -0
- node_modules/strip-comments/LICENSE +21 -0
- node_modules/strip-comments/README.md +237 -0
- node_modules/strip-comments/index.js +116 -0
- node_modules/strip-comments/lib/Node.js +28 -0
- node_modules/strip-comments/lib/compile.js +63 -0
- node_modules/strip-comments/lib/languages.js +85 -0
- node_modules/strip-comments/lib/parse.js +141 -0
- node_modules/strip-comments/package.json +102 -0
- node_modules/strip-indent/index.d.ts +21 -0
- node_modules/strip-indent/index.js +14 -0
- node_modules/strip-indent/license +9 -0
- node_modules/strip-indent/package.json +42 -0
- node_modules/strip-indent/readme.md +44 -0
- node_modules/strip-json-comments/index.js +70 -0
- node_modules/strip-json-comments/license +21 -0
- node_modules/strip-json-comments/package.json +42 -0
- node_modules/strip-json-comments/readme.md +64 -0
- node_modules/strnum/CHANGELOG.md +51 -0
- node_modules/strnum/LICENSE +21 -0
- node_modules/strnum/README.md +113 -0
- node_modules/strnum/package.json +35 -0
- node_modules/strnum/strnum.js +171 -0
- node_modules/strtok3/LICENSE.txt +21 -0
- node_modules/strtok3/README.md +399 -0
- node_modules/strtok3/lib/AbstractTokenizer.d.ts +76 -0
- node_modules/strtok3/lib/AbstractTokenizer.js +111 -0
- node_modules/strtok3/lib/BlobTokenizer.d.ts +29 -0
- node_modules/strtok3/lib/BlobTokenizer.js +53 -0
- node_modules/strtok3/lib/BufferTokenizer.d.ts +29 -0
- node_modules/strtok3/lib/BufferTokenizer.js +52 -0
- node_modules/strtok3/lib/FileTokenizer.d.ts +37 -0
- node_modules/strtok3/lib/FileTokenizer.js +61 -0
- node_modules/strtok3/lib/ReadStreamTokenizer.d.ts +34 -0
- node_modules/strtok3/lib/ReadStreamTokenizer.js +107 -0
- node_modules/strtok3/lib/core.d.ts +40 -0
- node_modules/strtok3/lib/core.js +62 -0
- node_modules/strtok3/lib/index.d.ts +16 -0
- node_modules/strtok3/lib/index.js +22 -0
- node_modules/strtok3/lib/stream/AbstractStreamReader.d.ts +54 -0
- node_modules/strtok3/lib/stream/AbstractStreamReader.js +71 -0
- node_modules/strtok3/lib/stream/Deferred.d.ts +6 -0
- node_modules/strtok3/lib/stream/Deferred.js +10 -0
- node_modules/strtok3/lib/stream/Errors.d.ts +10 -0
- node_modules/strtok3/lib/stream/Errors.js +16 -0
- node_modules/strtok3/lib/stream/StreamReader.d.ts +29 -0
- node_modules/strtok3/lib/stream/StreamReader.js +83 -0
- node_modules/strtok3/lib/stream/WebStreamByobReader.d.ts +14 -0
- node_modules/strtok3/lib/stream/WebStreamByobReader.js +27 -0
- node_modules/strtok3/lib/stream/WebStreamDefaultReader.d.ts +19 -0
node_modules/strip-comments/CHANGELOG.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Release history
|
| 2 |
+
|
| 3 |
+
All notable changes to this project will be documented in this file.
|
| 4 |
+
|
| 5 |
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
| 6 |
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
| 7 |
+
|
| 8 |
+
<details>
|
| 9 |
+
<summary><strong>Guiding Principles</strong></summary>
|
| 10 |
+
|
| 11 |
+
- Changelogs are for humans, not machines.
|
| 12 |
+
- There should be an entry for every single version.
|
| 13 |
+
- The same types of changes should be grouped.
|
| 14 |
+
- Versions and sections should be linkable.
|
| 15 |
+
- The latest version comes first.
|
| 16 |
+
- The release date of each versions is displayed.
|
| 17 |
+
- Mention whether you follow Semantic Versioning.
|
| 18 |
+
|
| 19 |
+
</details>
|
| 20 |
+
|
| 21 |
+
<details>
|
| 22 |
+
<summary><strong>Types of changes</strong></summary>
|
| 23 |
+
|
| 24 |
+
Changelog entries are classified using the following labels _(from [keep-a-changelog](http://keepachangelog.com/)_):
|
| 25 |
+
|
| 26 |
+
- `Added` for new features.
|
| 27 |
+
- `Changed` for changes in existing functionality.
|
| 28 |
+
- `Deprecated` for soon-to-be removed features.
|
| 29 |
+
- `Removed` for now removed features.
|
| 30 |
+
- `Fixed` for any bug fixes.
|
| 31 |
+
- `Security` in case of vulnerabilities.
|
| 32 |
+
|
| 33 |
+
</details>
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
## [2.0.0] - 2019-09-14
|
| 37 |
+
|
| 38 |
+
**Changed**
|
| 39 |
+
|
| 40 |
+
- Refactored again to use a custom parser that is much faster and supports a number of different languages.
|
| 41 |
+
|
| 42 |
+
## [1.0.2] - 2018-05-03
|
| 43 |
+
|
| 44 |
+
- refactored
|
| 45 |
+
- Remove default objectRestSpread plugin #40 allows for user configured plugins
|
| 46 |
+
- Merge pull request #42 from tallarium/remove-default-transform
|
| 47 |
+
- Merge remote-tracking branch 'origin/master' into refactor
|
| 48 |
+
- Merge remote-tracking branch 'origin/master' into refactor
|
| 49 |
+
- Merge pull request #44 from jonschlinkert/refactor
|
| 50 |
+
|
| 51 |
+
## [1.0.1] - 2018-03-24
|
| 52 |
+
|
| 53 |
+
- feat: Allow users to specify their own babylon plugins
|
| 54 |
+
- Merge pull request #40 from briandipalma/patch-1
|
| 55 |
+
- adds `allowReturnOutsideFunction` to defaults
|
| 56 |
+
|
| 57 |
+
## [1.0.0] - 2018-03-24
|
| 58 |
+
|
| 59 |
+
- adds object-rest-spread plugin
|
| 60 |
+
|
| 61 |
+
## [0.4.4] - 2016-02-14
|
| 62 |
+
|
| 63 |
+
- refactor to use babylon
|
| 64 |
+
|
| 65 |
+
## [0.4.3] - 2015-12-25
|
| 66 |
+
|
| 67 |
+
- minor tweak
|
| 68 |
+
|
| 69 |
+
## [0.4.2] - 2015-12-11
|
| 70 |
+
|
| 71 |
+
- bump extract-comments per issue https://github.com/jonschlinkert/strip-comments/issues/29
|
| 72 |
+
- Merge branch 'master' of https://github.com/lebbe/strip-comments into lebbe-master
|
| 73 |
+
- Merge branch 'lebbe-master'
|
| 74 |
+
|
| 75 |
+
## [0.4.0] - 2015-11-04
|
| 76 |
+
|
| 77 |
+
- adds more test cases
|
| 78 |
+
- closes https://github.com/jonschlinkert/strip-comments/issues/18
|
| 79 |
+
- Handles comments that are substrings of a later comment
|
| 80 |
+
- Merge pull request #28 from epicoxymoron/bugfix/27-discard-is-too-greedy
|
| 81 |
+
- adds example
|
| 82 |
+
- adds json test
|
| 83 |
+
|
| 84 |
+
## [0.3.4] - 2015-10-22
|
| 85 |
+
|
| 86 |
+
- refactored
|
| 87 |
+
- expose `first` method. code comments, minor formatting
|
| 88 |
+
- allow line/block to be specified as options
|
| 89 |
+
- Merge pull request #23 from jonschlinkert/dev
|
| 90 |
+
- fixes examples
|
| 91 |
+
- adds editorconfig
|
| 92 |
+
|
| 93 |
+
## [0.3.0] - 2014-09-02
|
| 94 |
+
|
| 95 |
+
- merge fix from origin
|
| 96 |
+
- Merge pull request #13 from mk-pmb/tests_literals_nocomment
|
| 97 |
+
- Merge pull request #15 from mk-pmb/tests_literals_snake
|
| 98 |
+
- Merge pull request #22 from kgryte/patch-1
|
| 99 |
+
- Merge pull request #9 from tunnckoCore/master
|
| 100 |
+
- Merge remote-tracking branch 'origin/line-comments'
|
| 101 |
+
- Merge remote-tracking branch 'origin/master'
|
| 102 |
+
- tests: not a comment: snake-y ASCII art
|
| 103 |
+
- tests: string and regexp literals
|
| 104 |
+
- adds tests for URLs
|
| 105 |
+
- fix globstars
|
| 106 |
+
- lint
|
| 107 |
+
|
| 108 |
+
## [0.2.0] - 2014-08-10
|
| 109 |
+
|
| 110 |
+
- fixes `use strict` statement
|
| 111 |
+
|
| 112 |
+
## [0.1.6] - 2014-02-13
|
| 113 |
+
|
| 114 |
+
- Merge branch 'master' of https://github.com/tunnckoCore/strip-comments into tunnckoCore-master
|
| 115 |
+
- Merge branch 'tunnckoCore-master'
|
| 116 |
+
- minor formatting
|
| 117 |
+
|
| 118 |
+
## [0.1.0] - 2014-02-10
|
| 119 |
+
|
| 120 |
+
- first commit
|
| 121 |
+
|
| 122 |
+
[1.0.2]: https://github.com/jonschlinkert/strip-comments/compare/1.0.1...1.0.2
|
| 123 |
+
[1.0.1]: https://github.com/jonschlinkert/strip-comments/compare/1.0.0...1.0.1
|
| 124 |
+
[1.0.0]: https://github.com/jonschlinkert/strip-comments/compare/0.4.4...1.0.0
|
| 125 |
+
[0.4.4]: https://github.com/jonschlinkert/strip-comments/compare/0.4.3...0.4.4
|
| 126 |
+
[0.4.3]: https://github.com/jonschlinkert/strip-comments/compare/0.4.2...0.4.3
|
| 127 |
+
[0.4.2]: https://github.com/jonschlinkert/strip-comments/compare/0.4.0...0.4.2
|
| 128 |
+
[0.4.0]: https://github.com/jonschlinkert/strip-comments/compare/0.3.4...0.4.0
|
| 129 |
+
[0.3.4]: https://github.com/jonschlinkert/strip-comments/compare/0.3.0...0.3.4
|
| 130 |
+
[0.3.0]: https://github.com/jonschlinkert/strip-comments/compare/0.2.0...0.3.0
|
| 131 |
+
[0.2.0]: https://github.com/jonschlinkert/strip-comments/compare/0.1.6...0.2.0
|
| 132 |
+
[0.1.6]: https://github.com/jonschlinkert/strip-comments/compare/0.1.0...0.1.6
|
| 133 |
+
|
| 134 |
+
[Unreleased]: https://github.com/jonschlinkert/strip-comments/compare/0.1.0...HEAD
|
| 135 |
+
[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog
|
| 136 |
+
|
node_modules/strip-comments/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2014-present, Jon Schlinkert.
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in
|
| 13 |
+
all copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 21 |
+
THE SOFTWARE.
|
node_modules/strip-comments/README.md
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# strip-comments [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [](https://www.npmjs.com/package/strip-comments) [](https://npmjs.org/package/strip-comments) [](https://npmjs.org/package/strip-comments) [](https://travis-ci.org/jonschlinkert/strip-comments)
|
| 2 |
+
|
| 3 |
+
> Strip line and/or block comments from a string. Blazing fast, and works with JavaScript, Sass, CSS, Less.js, and a number of other languages.
|
| 4 |
+
|
| 5 |
+
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
| 6 |
+
|
| 7 |
+
- [Install](#install)
|
| 8 |
+
- [What does this do?](#what-does-this-do)
|
| 9 |
+
- [Usage](#usage)
|
| 10 |
+
- [API](#api)
|
| 11 |
+
- [About](#about)
|
| 12 |
+
|
| 13 |
+
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
|
| 14 |
+
|
| 15 |
+
## Install
|
| 16 |
+
|
| 17 |
+
Install with [npm](https://www.npmjs.com/) (requires [Node.js](https://nodejs.org/en/) >=10):
|
| 18 |
+
|
| 19 |
+
```sh
|
| 20 |
+
$ npm install --save strip-comments
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
## What does this do?
|
| 24 |
+
|
| 25 |
+
Takes a string and returns a new string with comments removed. Works with line comments and/or block comments. Optionally removes the first comment only or ignores protected comments.
|
| 26 |
+
|
| 27 |
+
Works with:
|
| 28 |
+
|
| 29 |
+
* ada
|
| 30 |
+
* apl
|
| 31 |
+
* applescript
|
| 32 |
+
* c
|
| 33 |
+
* csharp
|
| 34 |
+
* css
|
| 35 |
+
* hashbang
|
| 36 |
+
* haskell
|
| 37 |
+
* html
|
| 38 |
+
* java
|
| 39 |
+
* javascript
|
| 40 |
+
* less
|
| 41 |
+
* lua
|
| 42 |
+
* matlab
|
| 43 |
+
* ocaml
|
| 44 |
+
* pascal
|
| 45 |
+
* perl
|
| 46 |
+
* php
|
| 47 |
+
* python
|
| 48 |
+
* ruby
|
| 49 |
+
* sass
|
| 50 |
+
* shebang
|
| 51 |
+
* sql
|
| 52 |
+
* swift
|
| 53 |
+
* typscript
|
| 54 |
+
* xml
|
| 55 |
+
|
| 56 |
+
## Usage
|
| 57 |
+
|
| 58 |
+
By default all comments are stripped.
|
| 59 |
+
|
| 60 |
+
```js
|
| 61 |
+
const strip = require('strip-comments');
|
| 62 |
+
const str = strip('const foo = "bar";// this is a comment\n /* me too *\/');
|
| 63 |
+
console.log(str);
|
| 64 |
+
// => 'const foo = "bar";\n'
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
For more use-cases see the [tests](./test/test.js)
|
| 68 |
+
|
| 69 |
+
## API
|
| 70 |
+
|
| 71 |
+
### [strip](index.js#L33)
|
| 72 |
+
|
| 73 |
+
Strip all code comments from the given `input`, including protected comments that start with `!`, unless disabled by setting `options.keepProtected` to true.
|
| 74 |
+
|
| 75 |
+
**Params**
|
| 76 |
+
|
| 77 |
+
* `input` **{String}**: string from which to strip comments
|
| 78 |
+
* `options` **{Object}**: optional options, passed to [extract-comments](https://github.com/jonschlinkert/extract-comments)
|
| 79 |
+
|
| 80 |
+
- `line` **{Boolean}**: if `false` strip only block comments, default `true`
|
| 81 |
+
- `block` **{Boolean}**: if `false` strip only line comments, default `true`
|
| 82 |
+
- `keepProtected` **{Boolean}**: Keep ignored comments (e.g. `/*!` and `//!`)
|
| 83 |
+
- `preserveNewlines` **{Boolean}**: Preserve newlines after comments are stripped
|
| 84 |
+
* `returns` **{String}**: modified input
|
| 85 |
+
|
| 86 |
+
**Example**
|
| 87 |
+
|
| 88 |
+
```js
|
| 89 |
+
const str = strip('const foo = "bar";// this is a comment\n /* me too */');
|
| 90 |
+
console.log(str);
|
| 91 |
+
// => 'const foo = "bar";'
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### [.block](index.js#L54)
|
| 95 |
+
|
| 96 |
+
Strip only block comments.
|
| 97 |
+
|
| 98 |
+
**Params**
|
| 99 |
+
|
| 100 |
+
* `input` **{String}**: string from which to strip comments
|
| 101 |
+
* `options` **{Object}**: pass `opts.keepProtected: true` to keep ignored comments (e.g. `/*!`)
|
| 102 |
+
* `returns` **{String}**: modified string
|
| 103 |
+
|
| 104 |
+
**Example**
|
| 105 |
+
|
| 106 |
+
```js
|
| 107 |
+
const strip = require('..');
|
| 108 |
+
const str = strip.block('const foo = "bar";// this is a comment\n /* me too */');
|
| 109 |
+
console.log(str);
|
| 110 |
+
// => 'const foo = "bar";// this is a comment'
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
### [.line](index.js#L74)
|
| 114 |
+
|
| 115 |
+
Strip only line comments.
|
| 116 |
+
|
| 117 |
+
**Params**
|
| 118 |
+
|
| 119 |
+
* `input` **{String}**: string from which to strip comments
|
| 120 |
+
* `options` **{Object}**: pass `opts.keepProtected: true` to keep ignored comments (e.g. `//!`)
|
| 121 |
+
* `returns` **{String}**: modified string
|
| 122 |
+
|
| 123 |
+
**Example**
|
| 124 |
+
|
| 125 |
+
```js
|
| 126 |
+
const str = strip.line('const foo = "bar";// this is a comment\n /* me too */');
|
| 127 |
+
console.log(str);
|
| 128 |
+
// => 'const foo = "bar";\n/* me too */'
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
### [.first](index.js#L95)
|
| 132 |
+
|
| 133 |
+
Strip the first comment from the given `input`. Or, if `opts.keepProtected` is true, the first non-protected comment will be stripped.
|
| 134 |
+
|
| 135 |
+
**Params**
|
| 136 |
+
|
| 137 |
+
* `input` **{String}**
|
| 138 |
+
* `options` **{Object}**: pass `opts.keepProtected: true` to keep comments with `!`
|
| 139 |
+
* `returns` **{String}**
|
| 140 |
+
|
| 141 |
+
**Example**
|
| 142 |
+
|
| 143 |
+
```js
|
| 144 |
+
const output = strip.first(input, { keepProtected: true });
|
| 145 |
+
console.log(output);
|
| 146 |
+
// => '//! first comment\nfoo; '
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
### [.block](index.js#L116)
|
| 150 |
+
|
| 151 |
+
Parses a string and returns a basic CST (Concrete Syntax Tree).
|
| 152 |
+
|
| 153 |
+
**Params**
|
| 154 |
+
|
| 155 |
+
* `input` **{String}**: string from which to strip comments
|
| 156 |
+
* `options` **{Object}**: pass `opts.keepProtected: true` to keep ignored comments (e.g. `/*!`)
|
| 157 |
+
* `returns` **{String}**: modified string
|
| 158 |
+
|
| 159 |
+
**Example**
|
| 160 |
+
|
| 161 |
+
```js
|
| 162 |
+
const strip = require('..');
|
| 163 |
+
const str = strip.block('const foo = "bar";// this is a comment\n /* me too */');
|
| 164 |
+
console.log(str);
|
| 165 |
+
// => 'const foo = "bar";// this is a comment'
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
## About
|
| 169 |
+
|
| 170 |
+
<details>
|
| 171 |
+
<summary><strong>Contributing</strong></summary>
|
| 172 |
+
|
| 173 |
+
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
| 174 |
+
|
| 175 |
+
</details>
|
| 176 |
+
|
| 177 |
+
<details>
|
| 178 |
+
<summary><strong>Running Tests</strong></summary>
|
| 179 |
+
|
| 180 |
+
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
| 181 |
+
|
| 182 |
+
```sh
|
| 183 |
+
$ npm install && npm test
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
</details>
|
| 187 |
+
|
| 188 |
+
<details>
|
| 189 |
+
<summary><strong>Building docs</strong></summary>
|
| 190 |
+
|
| 191 |
+
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
| 192 |
+
|
| 193 |
+
To generate the readme, run the following command:
|
| 194 |
+
|
| 195 |
+
```sh
|
| 196 |
+
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
| 197 |
+
```
|
| 198 |
+
|
| 199 |
+
</details>
|
| 200 |
+
|
| 201 |
+
### Related projects
|
| 202 |
+
|
| 203 |
+
You might also be interested in these projects:
|
| 204 |
+
|
| 205 |
+
* [code-context](https://www.npmjs.com/package/code-context): Parse a string of javascript to determine the context for functions, variables and comments based… [more](https://github.com/jonschlinkert/code-context) | [homepage](https://github.com/jonschlinkert/code-context "Parse a string of javascript to determine the context for functions, variables and comments based on the code that follows.")
|
| 206 |
+
* [extract-comments](https://www.npmjs.com/package/extract-comments): Uses esprima to extract line and block comments from a string of JavaScript. Also optionally… [more](https://github.com/jonschlinkert/extract-comments) | [homepage](https://github.com/jonschlinkert/extract-comments "Uses esprima to extract line and block comments from a string of JavaScript. Also optionally parses code context (the next line of code after a comment).")
|
| 207 |
+
* [parse-code-context](https://www.npmjs.com/package/parse-code-context): Fast and simple way to parse code context for use with documentation from code comments… [more](https://github.com/jonschlinkert/parse-code-context) | [homepage](https://github.com/jonschlinkert/parse-code-context "Fast and simple way to parse code context for use with documentation from code comments. Parses context from a single line of JavaScript, for functions, variable declarations, methods, prototype properties, prototype methods etc.")
|
| 208 |
+
* [parse-comments](https://www.npmjs.com/package/parse-comments): Parse code comments from JavaScript or any language that uses the same format. | [homepage](https://github.com/jonschlinkert/parse-comments "Parse code comments from JavaScript or any language that uses the same format.")
|
| 209 |
+
|
| 210 |
+
### Contributors
|
| 211 |
+
|
| 212 |
+
| **Commits** | **Contributor** |
|
| 213 |
+
| --- | --- |
|
| 214 |
+
| 82 | [jonschlinkert](https://github.com/jonschlinkert) |
|
| 215 |
+
| 4 | [tunnckoCore](https://github.com/tunnckoCore) |
|
| 216 |
+
| 2 | [mk-pmb](https://github.com/mk-pmb) |
|
| 217 |
+
| 1 | [kgryte](https://github.com/kgryte) |
|
| 218 |
+
| 1 | [briandipalma](https://github.com/briandipalma) |
|
| 219 |
+
| 1 | [epicoxymoron](https://github.com/epicoxymoron) |
|
| 220 |
+
| 1 | [XuluWarrior](https://github.com/XuluWarrior) |
|
| 221 |
+
|
| 222 |
+
### Author
|
| 223 |
+
|
| 224 |
+
**Jon Schlinkert**
|
| 225 |
+
|
| 226 |
+
* [GitHub Profile](https://github.com/jonschlinkert)
|
| 227 |
+
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
| 228 |
+
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
| 229 |
+
|
| 230 |
+
### License
|
| 231 |
+
|
| 232 |
+
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
|
| 233 |
+
Released under the [MIT License](LICENSE).
|
| 234 |
+
|
| 235 |
+
***
|
| 236 |
+
|
| 237 |
+
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 13, 2019._
|
node_modules/strip-comments/index.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*!
|
| 2 |
+
* strip-comments <https://github.com/jonschlinkert/strip-comments>
|
| 3 |
+
* Copyright (c) 2014-present, Jon Schlinkert.
|
| 4 |
+
* Released under the MIT License.
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
'use strict';
|
| 8 |
+
|
| 9 |
+
const compile = require('./lib/compile');
|
| 10 |
+
const parse = require('./lib/parse');
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Strip all code comments from the given `input`, including protected
|
| 14 |
+
* comments that start with `!`, unless disabled by setting `options.keepProtected`
|
| 15 |
+
* to true.
|
| 16 |
+
*
|
| 17 |
+
* ```js
|
| 18 |
+
* const str = strip('const foo = "bar";// this is a comment\n /* me too *\/');
|
| 19 |
+
* console.log(str);
|
| 20 |
+
* // => 'const foo = "bar";'
|
| 21 |
+
* ```
|
| 22 |
+
* @name strip
|
| 23 |
+
* @param {String} `input` string from which to strip comments
|
| 24 |
+
* @param {Object} `options` optional options, passed to [extract-comments][extract-comments]
|
| 25 |
+
* @option {Boolean} [options] `line` if `false` strip only block comments, default `true`
|
| 26 |
+
* @option {Boolean} [options] `block` if `false` strip only line comments, default `true`
|
| 27 |
+
* @option {Boolean} [options] `keepProtected` Keep ignored comments (e.g. `/*!` and `//!`)
|
| 28 |
+
* @option {Boolean} [options] `preserveNewlines` Preserve newlines after comments are stripped
|
| 29 |
+
* @return {String} modified input
|
| 30 |
+
* @api public
|
| 31 |
+
*/
|
| 32 |
+
|
| 33 |
+
const strip = module.exports = (input, options) => {
|
| 34 |
+
const opts = { ...options, block: true, line: true };
|
| 35 |
+
return compile(parse(input, opts), opts);
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Strip only block comments.
|
| 40 |
+
*
|
| 41 |
+
* ```js
|
| 42 |
+
* const strip = require('..');
|
| 43 |
+
* const str = strip.block('const foo = "bar";// this is a comment\n /* me too *\/');
|
| 44 |
+
* console.log(str);
|
| 45 |
+
* // => 'const foo = "bar";// this is a comment'
|
| 46 |
+
* ```
|
| 47 |
+
* @name .block
|
| 48 |
+
* @param {String} `input` string from which to strip comments
|
| 49 |
+
* @param {Object} `options` pass `opts.keepProtected: true` to keep ignored comments (e.g. `/*!`)
|
| 50 |
+
* @return {String} modified string
|
| 51 |
+
* @api public
|
| 52 |
+
*/
|
| 53 |
+
|
| 54 |
+
strip.block = (input, options) => {
|
| 55 |
+
const opts = { ...options, block: true };
|
| 56 |
+
return compile(parse(input, opts), opts);
|
| 57 |
+
};
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* Strip only line comments.
|
| 61 |
+
*
|
| 62 |
+
* ```js
|
| 63 |
+
* const str = strip.line('const foo = "bar";// this is a comment\n /* me too *\/');
|
| 64 |
+
* console.log(str);
|
| 65 |
+
* // => 'const foo = "bar";\n/* me too *\/'
|
| 66 |
+
* ```
|
| 67 |
+
* @name .line
|
| 68 |
+
* @param {String} `input` string from which to strip comments
|
| 69 |
+
* @param {Object} `options` pass `opts.keepProtected: true` to keep ignored comments (e.g. `//!`)
|
| 70 |
+
* @return {String} modified string
|
| 71 |
+
* @api public
|
| 72 |
+
*/
|
| 73 |
+
|
| 74 |
+
strip.line = (input, options) => {
|
| 75 |
+
const opts = { ...options, line: true };
|
| 76 |
+
return compile(parse(input, opts), opts);
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Strip the first comment from the given `input`. Or, if `opts.keepProtected` is true,
|
| 81 |
+
* the first non-protected comment will be stripped.
|
| 82 |
+
*
|
| 83 |
+
* ```js
|
| 84 |
+
* const output = strip.first(input, { keepProtected: true });
|
| 85 |
+
* console.log(output);
|
| 86 |
+
* // => '//! first comment\nfoo; '
|
| 87 |
+
* ```
|
| 88 |
+
* @name .first
|
| 89 |
+
* @param {String} `input`
|
| 90 |
+
* @param {Object} `options` pass `opts.keepProtected: true` to keep comments with `!`
|
| 91 |
+
* @return {String}
|
| 92 |
+
* @api public
|
| 93 |
+
*/
|
| 94 |
+
|
| 95 |
+
strip.first = (input, options) => {
|
| 96 |
+
const opts = { ...options, block: true, line: true, first: true };
|
| 97 |
+
return compile(parse(input, opts), opts);
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* Parses a string and returns a basic CST (Concrete Syntax Tree).
|
| 102 |
+
*
|
| 103 |
+
* ```js
|
| 104 |
+
* const strip = require('..');
|
| 105 |
+
* const str = strip.block('const foo = "bar";// this is a comment\n /* me too *\/');
|
| 106 |
+
* console.log(str);
|
| 107 |
+
* // => 'const foo = "bar";// this is a comment'
|
| 108 |
+
* ```
|
| 109 |
+
* @name .block
|
| 110 |
+
* @param {String} `input` string from which to strip comments
|
| 111 |
+
* @param {Object} `options` pass `opts.keepProtected: true` to keep ignored comments (e.g. `/*!`)
|
| 112 |
+
* @return {String} modified string
|
| 113 |
+
* @api public
|
| 114 |
+
*/
|
| 115 |
+
|
| 116 |
+
strip.parse = parse;
|
node_modules/strip-comments/lib/Node.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
class Node {
|
| 4 |
+
constructor(node) {
|
| 5 |
+
this.type = node.type;
|
| 6 |
+
if (node.value) this.value = node.value;
|
| 7 |
+
if (node.match) this.match = node.match;
|
| 8 |
+
this.newline = node.newline || '';
|
| 9 |
+
}
|
| 10 |
+
get protected() {
|
| 11 |
+
return Boolean(this.match) && this.match[1] === '!';
|
| 12 |
+
}
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
class Block extends Node {
|
| 16 |
+
constructor(node) {
|
| 17 |
+
super(node);
|
| 18 |
+
this.nodes = node.nodes || [];
|
| 19 |
+
}
|
| 20 |
+
push(node) {
|
| 21 |
+
this.nodes.push(node);
|
| 22 |
+
}
|
| 23 |
+
get protected() {
|
| 24 |
+
return this.nodes.length > 0 && this.nodes[0].protected === true;
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
module.exports = { Node, Block };
|
node_modules/strip-comments/lib/compile.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const compile = (cst, options = {}) => {
|
| 4 |
+
const keepProtected = options.safe === true || options.keepProtected === true;
|
| 5 |
+
let firstSeen = false;
|
| 6 |
+
|
| 7 |
+
const walk = (node, parent) => {
|
| 8 |
+
let output = '';
|
| 9 |
+
let inner;
|
| 10 |
+
let lines;
|
| 11 |
+
|
| 12 |
+
for (const child of node.nodes) {
|
| 13 |
+
switch (child.type) {
|
| 14 |
+
case 'block':
|
| 15 |
+
if (options.first && firstSeen === true) {
|
| 16 |
+
output += walk(child, node);
|
| 17 |
+
break;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
if (options.preserveNewlines === true) {
|
| 21 |
+
inner = walk(child, node);
|
| 22 |
+
lines = inner.split('\n');
|
| 23 |
+
output += '\n'.repeat(lines.length - 1);
|
| 24 |
+
break;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
if (keepProtected === true && child.protected === true) {
|
| 28 |
+
output += walk(child, node);
|
| 29 |
+
break;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
firstSeen = true;
|
| 33 |
+
break;
|
| 34 |
+
case 'line':
|
| 35 |
+
if (options.first && firstSeen === true) {
|
| 36 |
+
output += child.value;
|
| 37 |
+
break;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
if (keepProtected === true && child.protected === true) {
|
| 41 |
+
output += child.value;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
firstSeen = true;
|
| 45 |
+
break;
|
| 46 |
+
case 'open':
|
| 47 |
+
case 'close':
|
| 48 |
+
case 'text':
|
| 49 |
+
case 'newline':
|
| 50 |
+
default: {
|
| 51 |
+
output += child.value || '';
|
| 52 |
+
break;
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
return output;
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
return walk(cst);
|
| 61 |
+
};
|
| 62 |
+
|
| 63 |
+
module.exports = compile;
|
node_modules/strip-comments/lib/languages.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
exports.ada = { LINE_REGEX: /^--.*/ };
|
| 4 |
+
exports.apl = { LINE_REGEX: /^⍝.*/ };
|
| 5 |
+
|
| 6 |
+
exports.applescript = {
|
| 7 |
+
BLOCK_OPEN_REGEX: /^\(\*/,
|
| 8 |
+
BLOCK_CLOSE_REGEX: /^\*\)/
|
| 9 |
+
};
|
| 10 |
+
|
| 11 |
+
exports.csharp = {
|
| 12 |
+
LINE_REGEX: /^\/\/.*/
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
exports.haskell = {
|
| 16 |
+
BLOCK_OPEN_REGEX: /^\{-/,
|
| 17 |
+
BLOCK_CLOSE_REGEX: /^-\}/,
|
| 18 |
+
LINE_REGEX: /^--.*/
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
exports.html = {
|
| 22 |
+
BLOCK_OPEN_REGEX: /^\n*<!--(?!-?>)/,
|
| 23 |
+
BLOCK_CLOSE_REGEX: /^(?<!(?:<!-))-->/,
|
| 24 |
+
BLOCK_CLOSE_LOOSE_REGEX: /^(?<!(?:<!-))--\s*>/,
|
| 25 |
+
BLOCK_CLOSE_STRICT_NEWLINE_REGEX: /^(?<!(?:<!-))-->(\s*\n+|\n*)/,
|
| 26 |
+
BLOCK_CLOSE_STRICT_LOOSE_REGEX: /^(?<!(?:<!-))--\s*>(\s*\n+|\n*)/
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
exports.javascript = {
|
| 30 |
+
BLOCK_OPEN_REGEX: /^\/\*\*?(!?)/,
|
| 31 |
+
BLOCK_CLOSE_REGEX: /^\*\/(\n?)/,
|
| 32 |
+
LINE_REGEX: /^\/\/(!?).*/
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
exports.lua = {
|
| 36 |
+
BLOCK_OPEN_REGEX: /^--\[\[/,
|
| 37 |
+
BLOCK_CLOSE_REGEX: /^\]\]/,
|
| 38 |
+
LINE_REGEX: /^--.*/
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
exports.matlab = {
|
| 42 |
+
BLOCK_OPEN_REGEX: /^%{/,
|
| 43 |
+
BLOCK_CLOSE_REGEX: /^%}/,
|
| 44 |
+
LINE_REGEX: /^%.*/
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
exports.perl = {
|
| 48 |
+
LINE_REGEX: /^#.*/
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
exports.php = {
|
| 52 |
+
...exports.javascript,
|
| 53 |
+
LINE_REGEX: /^(#|\/\/).*?(?=\?>|\n)/
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
exports.python = {
|
| 57 |
+
BLOCK_OPEN_REGEX: /^"""/,
|
| 58 |
+
BLOCK_CLOSE_REGEX: /^"""/,
|
| 59 |
+
LINE_REGEX: /^#.*/
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
exports.ruby = {
|
| 63 |
+
BLOCK_OPEN_REGEX: /^=begin/,
|
| 64 |
+
BLOCK_CLOSE_REGEX: /^=end/,
|
| 65 |
+
LINE_REGEX: /^#.*/
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
exports.shebang = exports.hashbang = {
|
| 69 |
+
LINE_REGEX: /^#!.*/
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
exports.c = exports.javascript;
|
| 73 |
+
exports.csharp = exports.javascript;
|
| 74 |
+
exports.css = exports.javascript;
|
| 75 |
+
exports.java = exports.javascript;
|
| 76 |
+
exports.js = exports.javascript;
|
| 77 |
+
exports.less = exports.javascript;
|
| 78 |
+
exports.pascal = exports.applescript;
|
| 79 |
+
exports.ocaml = exports.applescript;
|
| 80 |
+
exports.sass = exports.javascript;
|
| 81 |
+
exports.sql = exports.ada;
|
| 82 |
+
exports.swift = exports.javascript;
|
| 83 |
+
exports.ts = exports.javascript;
|
| 84 |
+
exports.typscript = exports.javascript;
|
| 85 |
+
exports.xml = exports.html;
|
node_modules/strip-comments/lib/parse.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const { Node, Block } = require('./Node');
|
| 4 |
+
const languages = require('./languages');
|
| 5 |
+
|
| 6 |
+
const constants = {
|
| 7 |
+
ESCAPED_CHAR_REGEX: /^\\./,
|
| 8 |
+
QUOTED_STRING_REGEX: /^(['"`])((?:\\.|[^\1])+?)(\1)/,
|
| 9 |
+
NEWLINE_REGEX: /^\r*\n/
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
const parse = (input, options = {}) => {
|
| 13 |
+
if (typeof input !== 'string') {
|
| 14 |
+
throw new TypeError('Expected input to be a string');
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
const cst = new Block({ type: 'root', nodes: [] });
|
| 18 |
+
const stack = [cst];
|
| 19 |
+
const name = (options.language || 'javascript').toLowerCase();
|
| 20 |
+
const lang = languages[name];
|
| 21 |
+
|
| 22 |
+
if (typeof lang === 'undefined') {
|
| 23 |
+
throw new Error(`Language "${name}" is not supported by strip-comments`);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
const { LINE_REGEX, BLOCK_OPEN_REGEX, BLOCK_CLOSE_REGEX } = lang;
|
| 27 |
+
let block = cst;
|
| 28 |
+
let remaining = input;
|
| 29 |
+
let token;
|
| 30 |
+
let prev;
|
| 31 |
+
|
| 32 |
+
const source = [BLOCK_OPEN_REGEX, BLOCK_CLOSE_REGEX].filter(Boolean);
|
| 33 |
+
let tripleQuotes = false;
|
| 34 |
+
|
| 35 |
+
if (source.every(regex => regex.source === '^"""')) {
|
| 36 |
+
tripleQuotes = true;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Helpers
|
| 41 |
+
*/
|
| 42 |
+
|
| 43 |
+
const consume = (value = remaining[0] || '') => {
|
| 44 |
+
remaining = remaining.slice(value.length);
|
| 45 |
+
return value;
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
const scan = (regex, type = 'text') => {
|
| 49 |
+
const match = regex.exec(remaining);
|
| 50 |
+
if (match) {
|
| 51 |
+
consume(match[0]);
|
| 52 |
+
return { type, value: match[0], match };
|
| 53 |
+
}
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
const push = node => {
|
| 57 |
+
if (prev && prev.type === 'text' && node.type === 'text') {
|
| 58 |
+
prev.value += node.value;
|
| 59 |
+
return;
|
| 60 |
+
}
|
| 61 |
+
block.push(node);
|
| 62 |
+
if (node.nodes) {
|
| 63 |
+
stack.push(node);
|
| 64 |
+
block = node;
|
| 65 |
+
}
|
| 66 |
+
prev = node;
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
const pop = () => {
|
| 70 |
+
if (block.type === 'root') {
|
| 71 |
+
throw new SyntaxError('Unclosed block comment');
|
| 72 |
+
}
|
| 73 |
+
stack.pop();
|
| 74 |
+
block = stack[stack.length - 1];
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* Parse input string
|
| 79 |
+
*/
|
| 80 |
+
|
| 81 |
+
while (remaining !== '') {
|
| 82 |
+
// escaped characters
|
| 83 |
+
if ((token = scan(constants.ESCAPED_CHAR_REGEX, 'text'))) {
|
| 84 |
+
push(new Node(token));
|
| 85 |
+
continue;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
// quoted strings
|
| 89 |
+
if (block.type !== 'block' && (!prev || !/\w$/.test(prev.value)) && !(tripleQuotes && remaining.startsWith('"""'))) {
|
| 90 |
+
if ((token = scan(constants.QUOTED_STRING_REGEX, 'text'))) {
|
| 91 |
+
push(new Node(token));
|
| 92 |
+
continue;
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// newlines
|
| 97 |
+
if ((token = scan(constants.NEWLINE_REGEX, 'newline'))) {
|
| 98 |
+
push(new Node(token));
|
| 99 |
+
continue;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
// block comment open
|
| 103 |
+
if (BLOCK_OPEN_REGEX && options.block && !(tripleQuotes && block.type === 'block')) {
|
| 104 |
+
if ((token = scan(BLOCK_OPEN_REGEX, 'open'))) {
|
| 105 |
+
push(new Block({ type: 'block' }));
|
| 106 |
+
push(new Node(token));
|
| 107 |
+
continue;
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
// block comment close
|
| 112 |
+
if (BLOCK_CLOSE_REGEX && block.type === 'block' && options.block) {
|
| 113 |
+
if ((token = scan(BLOCK_CLOSE_REGEX, 'close'))) {
|
| 114 |
+
token.newline = token.match[1] || '';
|
| 115 |
+
push(new Node(token));
|
| 116 |
+
pop();
|
| 117 |
+
continue;
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
// line comment
|
| 122 |
+
if (LINE_REGEX && block.type !== 'block' && options.line) {
|
| 123 |
+
if ((token = scan(LINE_REGEX, 'line'))) {
|
| 124 |
+
push(new Node(token));
|
| 125 |
+
continue;
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// Plain text (skip "C" since some languages use "C" to start comments)
|
| 130 |
+
if ((token = scan(/^[a-zABD-Z0-9\t ]+/, 'text'))) {
|
| 131 |
+
push(new Node(token));
|
| 132 |
+
continue;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
push(new Node({ type: 'text', value: consume(remaining[0]) }));
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
return cst;
|
| 139 |
+
};
|
| 140 |
+
|
| 141 |
+
module.exports = parse;
|
node_modules/strip-comments/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "strip-comments",
|
| 3 |
+
"description": "Strip line and/or block comments from a string. Blazing fast, and works with JavaScript, Sass, CSS, Less.js, and a number of other languages.",
|
| 4 |
+
"version": "2.0.1",
|
| 5 |
+
"homepage": "https://github.com/jonschlinkert/strip-comments",
|
| 6 |
+
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
| 7 |
+
"repository": "jonschlinkert/strip-comments",
|
| 8 |
+
"bugs": {
|
| 9 |
+
"url": "https://github.com/jonschlinkert/strip-comments/issues"
|
| 10 |
+
},
|
| 11 |
+
"license": "MIT",
|
| 12 |
+
"files": [
|
| 13 |
+
"index.js",
|
| 14 |
+
"lib"
|
| 15 |
+
],
|
| 16 |
+
"main": "index.js",
|
| 17 |
+
"engines": {
|
| 18 |
+
"node": ">=10"
|
| 19 |
+
},
|
| 20 |
+
"scripts": {
|
| 21 |
+
"test": "mocha",
|
| 22 |
+
"cover": "nyc --reporter=text --reporter=html mocha"
|
| 23 |
+
},
|
| 24 |
+
"devDependencies": {
|
| 25 |
+
"gulp-format-md": "^2.0.0",
|
| 26 |
+
"mocha": "^6.2.2",
|
| 27 |
+
"nyc": "^14.1.1"
|
| 28 |
+
},
|
| 29 |
+
"keywords": [
|
| 30 |
+
"ada comments",
|
| 31 |
+
"apl comments",
|
| 32 |
+
"applescript comments",
|
| 33 |
+
"block comment",
|
| 34 |
+
"block",
|
| 35 |
+
"block-comment",
|
| 36 |
+
"c comments",
|
| 37 |
+
"code comment",
|
| 38 |
+
"comment",
|
| 39 |
+
"comments",
|
| 40 |
+
"csharp comments",
|
| 41 |
+
"css comments",
|
| 42 |
+
"css",
|
| 43 |
+
"hashbang comments",
|
| 44 |
+
"haskell comments",
|
| 45 |
+
"html comments",
|
| 46 |
+
"java comments",
|
| 47 |
+
"javascript comments",
|
| 48 |
+
"javascript",
|
| 49 |
+
"js",
|
| 50 |
+
"less comments",
|
| 51 |
+
"less css",
|
| 52 |
+
"less",
|
| 53 |
+
"less.js",
|
| 54 |
+
"lessjs",
|
| 55 |
+
"line comment",
|
| 56 |
+
"line comments",
|
| 57 |
+
"line",
|
| 58 |
+
"line-comment",
|
| 59 |
+
"line-comments",
|
| 60 |
+
"lua comments",
|
| 61 |
+
"matlab comments",
|
| 62 |
+
"ocaml comments",
|
| 63 |
+
"pascal comments",
|
| 64 |
+
"perl comments",
|
| 65 |
+
"php comments",
|
| 66 |
+
"python comments",
|
| 67 |
+
"remove",
|
| 68 |
+
"ruby comments",
|
| 69 |
+
"sass comments",
|
| 70 |
+
"sass",
|
| 71 |
+
"shebang comments",
|
| 72 |
+
"sql comments",
|
| 73 |
+
"strip",
|
| 74 |
+
"swift comments",
|
| 75 |
+
"typscript comments",
|
| 76 |
+
"xml comments"
|
| 77 |
+
],
|
| 78 |
+
"verb": {
|
| 79 |
+
"toc": true,
|
| 80 |
+
"layout": "default",
|
| 81 |
+
"tasks": [
|
| 82 |
+
"readme"
|
| 83 |
+
],
|
| 84 |
+
"plugins": [
|
| 85 |
+
"gulp-format-md"
|
| 86 |
+
],
|
| 87 |
+
"helpers": [
|
| 88 |
+
"./examples/support/helpers.js"
|
| 89 |
+
],
|
| 90 |
+
"related": {
|
| 91 |
+
"list": [
|
| 92 |
+
"code-context",
|
| 93 |
+
"extract-comments",
|
| 94 |
+
"parse-code-context",
|
| 95 |
+
"parse-comments"
|
| 96 |
+
]
|
| 97 |
+
},
|
| 98 |
+
"lint": {
|
| 99 |
+
"reflinks": true
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
}
|
node_modules/strip-indent/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
Strip leading whitespace from each line in a string.
|
| 3 |
+
|
| 4 |
+
The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove.
|
| 5 |
+
|
| 6 |
+
@example
|
| 7 |
+
```
|
| 8 |
+
import stripIndent = require('strip-indent');
|
| 9 |
+
|
| 10 |
+
const string = '\tunicorn\n\t\tcake';
|
| 11 |
+
// unicorn
|
| 12 |
+
// cake
|
| 13 |
+
|
| 14 |
+
stripIndent(string);
|
| 15 |
+
//unicorn
|
| 16 |
+
// cake
|
| 17 |
+
```
|
| 18 |
+
*/
|
| 19 |
+
declare function stripIndent(string: string): string;
|
| 20 |
+
|
| 21 |
+
export = stripIndent;
|
node_modules/strip-indent/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
const minIndent = require('min-indent');
|
| 3 |
+
|
| 4 |
+
module.exports = string => {
|
| 5 |
+
const indent = minIndent(string);
|
| 6 |
+
|
| 7 |
+
if (indent === 0) {
|
| 8 |
+
return string;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
const regex = new RegExp(`^[ \\t]{${indent}}`, 'gm');
|
| 12 |
+
|
| 13 |
+
return string.replace(regex, '');
|
| 14 |
+
};
|
node_modules/strip-indent/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 6 |
+
|
| 7 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 8 |
+
|
| 9 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/strip-indent/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "strip-indent",
|
| 3 |
+
"version": "3.0.0",
|
| 4 |
+
"description": "Strip leading whitespace from each line in a string",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"repository": "sindresorhus/strip-indent",
|
| 7 |
+
"author": {
|
| 8 |
+
"name": "Sindre Sorhus",
|
| 9 |
+
"email": "sindresorhus@gmail.com",
|
| 10 |
+
"url": "sindresorhus.com"
|
| 11 |
+
},
|
| 12 |
+
"engines": {
|
| 13 |
+
"node": ">=8"
|
| 14 |
+
},
|
| 15 |
+
"scripts": {
|
| 16 |
+
"test": "xo && ava && tsd"
|
| 17 |
+
},
|
| 18 |
+
"files": [
|
| 19 |
+
"index.js",
|
| 20 |
+
"index.d.ts"
|
| 21 |
+
],
|
| 22 |
+
"keywords": [
|
| 23 |
+
"strip",
|
| 24 |
+
"indent",
|
| 25 |
+
"indentation",
|
| 26 |
+
"normalize",
|
| 27 |
+
"remove",
|
| 28 |
+
"delete",
|
| 29 |
+
"whitespace",
|
| 30 |
+
"space",
|
| 31 |
+
"tab",
|
| 32 |
+
"string"
|
| 33 |
+
],
|
| 34 |
+
"dependencies": {
|
| 35 |
+
"min-indent": "^1.0.0"
|
| 36 |
+
},
|
| 37 |
+
"devDependencies": {
|
| 38 |
+
"ava": "^1.4.1",
|
| 39 |
+
"tsd": "^0.7.2",
|
| 40 |
+
"xo": "^0.24.0"
|
| 41 |
+
}
|
| 42 |
+
}
|
node_modules/strip-indent/readme.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# strip-indent [](https://travis-ci.org/sindresorhus/strip-indent)
|
| 2 |
+
|
| 3 |
+
> Strip leading whitespace from each line in a string
|
| 4 |
+
|
| 5 |
+
The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove.
|
| 6 |
+
|
| 7 |
+
Useful for removing redundant indentation.
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
## Install
|
| 11 |
+
|
| 12 |
+
```
|
| 13 |
+
$ npm install strip-indent
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
## Usage
|
| 18 |
+
|
| 19 |
+
```js
|
| 20 |
+
const stripIndent = require('strip-indent');
|
| 21 |
+
|
| 22 |
+
const string = '\tunicorn\n\t\tcake';
|
| 23 |
+
/*
|
| 24 |
+
unicorn
|
| 25 |
+
cake
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
stripIndent(string);
|
| 29 |
+
/*
|
| 30 |
+
unicorn
|
| 31 |
+
cake
|
| 32 |
+
*/
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
## Related
|
| 37 |
+
|
| 38 |
+
- [strip-indent-cli](https://github.com/sindresorhus/strip-indent-cli) - CLI for this module
|
| 39 |
+
- [indent-string](https://github.com/sindresorhus/indent-string) - Indent each line in a string
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
## License
|
| 43 |
+
|
| 44 |
+
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
node_modules/strip-json-comments/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
var singleComment = 1;
|
| 3 |
+
var multiComment = 2;
|
| 4 |
+
|
| 5 |
+
function stripWithoutWhitespace() {
|
| 6 |
+
return '';
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
function stripWithWhitespace(str, start, end) {
|
| 10 |
+
return str.slice(start, end).replace(/\S/g, ' ');
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
module.exports = function (str, opts) {
|
| 14 |
+
opts = opts || {};
|
| 15 |
+
|
| 16 |
+
var currentChar;
|
| 17 |
+
var nextChar;
|
| 18 |
+
var insideString = false;
|
| 19 |
+
var insideComment = false;
|
| 20 |
+
var offset = 0;
|
| 21 |
+
var ret = '';
|
| 22 |
+
var strip = opts.whitespace === false ? stripWithoutWhitespace : stripWithWhitespace;
|
| 23 |
+
|
| 24 |
+
for (var i = 0; i < str.length; i++) {
|
| 25 |
+
currentChar = str[i];
|
| 26 |
+
nextChar = str[i + 1];
|
| 27 |
+
|
| 28 |
+
if (!insideComment && currentChar === '"') {
|
| 29 |
+
var escaped = str[i - 1] === '\\' && str[i - 2] !== '\\';
|
| 30 |
+
if (!escaped) {
|
| 31 |
+
insideString = !insideString;
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
if (insideString) {
|
| 36 |
+
continue;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
if (!insideComment && currentChar + nextChar === '//') {
|
| 40 |
+
ret += str.slice(offset, i);
|
| 41 |
+
offset = i;
|
| 42 |
+
insideComment = singleComment;
|
| 43 |
+
i++;
|
| 44 |
+
} else if (insideComment === singleComment && currentChar + nextChar === '\r\n') {
|
| 45 |
+
i++;
|
| 46 |
+
insideComment = false;
|
| 47 |
+
ret += strip(str, offset, i);
|
| 48 |
+
offset = i;
|
| 49 |
+
continue;
|
| 50 |
+
} else if (insideComment === singleComment && currentChar === '\n') {
|
| 51 |
+
insideComment = false;
|
| 52 |
+
ret += strip(str, offset, i);
|
| 53 |
+
offset = i;
|
| 54 |
+
} else if (!insideComment && currentChar + nextChar === '/*') {
|
| 55 |
+
ret += str.slice(offset, i);
|
| 56 |
+
offset = i;
|
| 57 |
+
insideComment = multiComment;
|
| 58 |
+
i++;
|
| 59 |
+
continue;
|
| 60 |
+
} else if (insideComment === multiComment && currentChar + nextChar === '*/') {
|
| 61 |
+
i++;
|
| 62 |
+
insideComment = false;
|
| 63 |
+
ret += strip(str, offset, i + 1);
|
| 64 |
+
offset = i + 1;
|
| 65 |
+
continue;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
return ret + (insideComment ? strip(str.substr(offset)) : str.substr(offset));
|
| 70 |
+
};
|
node_modules/strip-json-comments/license
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in
|
| 13 |
+
all copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 21 |
+
THE SOFTWARE.
|
node_modules/strip-json-comments/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "strip-json-comments",
|
| 3 |
+
"version": "2.0.1",
|
| 4 |
+
"description": "Strip comments from JSON. Lets you use comments in your JSON files!",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"repository": "sindresorhus/strip-json-comments",
|
| 7 |
+
"author": {
|
| 8 |
+
"name": "Sindre Sorhus",
|
| 9 |
+
"email": "sindresorhus@gmail.com",
|
| 10 |
+
"url": "sindresorhus.com"
|
| 11 |
+
},
|
| 12 |
+
"engines": {
|
| 13 |
+
"node": ">=0.10.0"
|
| 14 |
+
},
|
| 15 |
+
"scripts": {
|
| 16 |
+
"test": "xo && ava"
|
| 17 |
+
},
|
| 18 |
+
"files": [
|
| 19 |
+
"index.js"
|
| 20 |
+
],
|
| 21 |
+
"keywords": [
|
| 22 |
+
"json",
|
| 23 |
+
"strip",
|
| 24 |
+
"remove",
|
| 25 |
+
"delete",
|
| 26 |
+
"trim",
|
| 27 |
+
"comments",
|
| 28 |
+
"multiline",
|
| 29 |
+
"parse",
|
| 30 |
+
"config",
|
| 31 |
+
"configuration",
|
| 32 |
+
"conf",
|
| 33 |
+
"settings",
|
| 34 |
+
"util",
|
| 35 |
+
"env",
|
| 36 |
+
"environment"
|
| 37 |
+
],
|
| 38 |
+
"devDependencies": {
|
| 39 |
+
"ava": "*",
|
| 40 |
+
"xo": "*"
|
| 41 |
+
}
|
| 42 |
+
}
|
node_modules/strip-json-comments/readme.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# strip-json-comments [](https://travis-ci.org/sindresorhus/strip-json-comments)
|
| 2 |
+
|
| 3 |
+
> Strip comments from JSON. Lets you use comments in your JSON files!
|
| 4 |
+
|
| 5 |
+
This is now possible:
|
| 6 |
+
|
| 7 |
+
```js
|
| 8 |
+
{
|
| 9 |
+
// rainbows
|
| 10 |
+
"unicorn": /* ❤ */ "cake"
|
| 11 |
+
}
|
| 12 |
+
```
|
| 13 |
+
|
| 14 |
+
It will replace single-line comments `//` and multi-line comments `/**/` with whitespace. This allows JSON error positions to remain as close as possible to the original source.
|
| 15 |
+
|
| 16 |
+
Also available as a [gulp](https://github.com/sindresorhus/gulp-strip-json-comments)/[grunt](https://github.com/sindresorhus/grunt-strip-json-comments)/[broccoli](https://github.com/sindresorhus/broccoli-strip-json-comments) plugin.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
## Install
|
| 20 |
+
|
| 21 |
+
```
|
| 22 |
+
$ npm install --save strip-json-comments
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
## Usage
|
| 27 |
+
|
| 28 |
+
```js
|
| 29 |
+
const json = '{/*rainbows*/"unicorn":"cake"}';
|
| 30 |
+
|
| 31 |
+
JSON.parse(stripJsonComments(json));
|
| 32 |
+
//=> {unicorn: 'cake'}
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
## API
|
| 37 |
+
|
| 38 |
+
### stripJsonComments(input, [options])
|
| 39 |
+
|
| 40 |
+
#### input
|
| 41 |
+
|
| 42 |
+
Type: `string`
|
| 43 |
+
|
| 44 |
+
Accepts a string with JSON and returns a string without comments.
|
| 45 |
+
|
| 46 |
+
#### options
|
| 47 |
+
|
| 48 |
+
##### whitespace
|
| 49 |
+
|
| 50 |
+
Type: `boolean`
|
| 51 |
+
Default: `true`
|
| 52 |
+
|
| 53 |
+
Replace comments with whitespace instead of stripping them entirely.
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
## Related
|
| 57 |
+
|
| 58 |
+
- [strip-json-comments-cli](https://github.com/sindresorhus/strip-json-comments-cli) - CLI for this module
|
| 59 |
+
- [strip-css-comments](https://github.com/sindresorhus/strip-css-comments) - Strip comments from CSS
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
## License
|
| 63 |
+
|
| 64 |
+
MIT © [Sindre Sorhus](http://sindresorhus.com)
|
node_modules/strnum/CHANGELOG.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
**2.4.0 / 2026-06-09**
|
| 3 |
+
- support unicode numerals using 'anynum'
|
| 4 |
+
|
| 5 |
+
**2.3.0 / 2026-05-07**
|
| 6 |
+
- support octal and binary, test with @byspec/numbers
|
| 7 |
+
- test with @byspec/numbers
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
**2.2.3 / 2026-04-07**
|
| 11 |
+
- remove unnecessary files from npm package
|
| 12 |
+
|
| 13 |
+
**2.2.2 / 2026-03-23**
|
| 14 |
+
- fix for space string
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
**2.2.1 / 2026-03-19**
|
| 18 |
+
- fix false positive for eNotation when no leading zeros
|
| 19 |
+
|
| 20 |
+
**2.2.0 / 2026-02-28**
|
| 21 |
+
- support infinity
|
| 22 |
+
|
| 23 |
+
**2.1.0 / 2025-05-01**
|
| 24 |
+
- fix e-notation
|
| 25 |
+
- to return string when invalid enotation is found. Eg `E24`
|
| 26 |
+
- to return valid number when only leading zero before e char is present
|
| 27 |
+
|
| 28 |
+
**2.0.5 / 2025-02-27**
|
| 29 |
+
- changes done in 1.1.2
|
| 30 |
+
|
| 31 |
+
**1.1.2 / 2025-02-27**
|
| 32 |
+
- fix skiplike for 0
|
| 33 |
+
|
| 34 |
+
**1.1.1 / 2025-02-21**
|
| 35 |
+
- All recent fixes of version 2
|
| 36 |
+
|
| 37 |
+
**2.0.4 / 2025-02-20**
|
| 38 |
+
- remove console log
|
| 39 |
+
|
| 40 |
+
**2.0.3 / 2025-02-20**
|
| 41 |
+
- fix for string which are falsly identified as e-notation
|
| 42 |
+
|
| 43 |
+
**2.0.1 / 2025-02-20**
|
| 44 |
+
- fix: handle only zeros
|
| 45 |
+
- fix: return original string when NaN
|
| 46 |
+
|
| 47 |
+
**2.0.0 / 2025-02-20**
|
| 48 |
+
- Migrating to ESM modules. No functional change
|
| 49 |
+
|
| 50 |
+
**1.1.0 / 2025-02-20**
|
| 51 |
+
- fix (#9): support missing floating point and e notations
|
node_modules/strnum/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2021 Natural Intelligence
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
node_modules/strnum/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# strnum
|
| 2 |
+
Parse string into Number based on configuration
|
| 3 |
+
|
| 4 |
+
[](https://npm-compare.com/strnum)
|
| 5 |
+
[](https://www.npmjs.com/package/strnum)
|
| 6 |
+
[](https://github.com/NaturalIntelligence/strnum)
|
| 7 |
+
|
| 8 |
+
## Users
|
| 9 |
+
|
| 10 |
+
<a href="https://github.com/aws-amplify" target="_blank"><img src="https://avatars.githubusercontent.com/u/41077760?s=100&v=4"></a>
|
| 11 |
+
<a href="https://github.com/astrapay" target="_blank"><img src="https://avatars.githubusercontent.com/u/90901882?s=100&v=4"></a>
|
| 12 |
+
<a href="https://github.com/process-analytics" target="_blank"><img src="https://avatars.githubusercontent.com/u/60110287?s=100&v=4"></a>
|
| 13 |
+
<a href="https://github.com/NaturalIntelligence" target="_blank"><img src="https://avatars.githubusercontent.com/u/16322633?s=100&v=4"></a>
|
| 14 |
+
Many React Native projects and plugins
|
| 15 |
+
|
| 16 |
+
## Usage
|
| 17 |
+
|
| 18 |
+
```bash
|
| 19 |
+
npm install strnum
|
| 20 |
+
```
|
| 21 |
+
```js
|
| 22 |
+
const toNumber = require("strnum");
|
| 23 |
+
|
| 24 |
+
toNumber(undefined) // undefined
|
| 25 |
+
toNumber(null)) //null
|
| 26 |
+
toNumber("")) // ""
|
| 27 |
+
toNumber("string"); //"string")
|
| 28 |
+
toNumber("12,12"); //"12,12")
|
| 29 |
+
toNumber("12 12"); //"12 12")
|
| 30 |
+
toNumber("12-12"); //"12-12")
|
| 31 |
+
toNumber("12.12.12"); //"12.12.12")
|
| 32 |
+
toNumber("0x2f"); //47)
|
| 33 |
+
toNumber("-0x2f"); //-47)
|
| 34 |
+
toNumber("0x2f", { hex : true}); //47)
|
| 35 |
+
toNumber("-0x2f", { hex : true}); //-47)
|
| 36 |
+
toNumber("0x2f", { hex : false}); //"0x2f")
|
| 37 |
+
toNumber("-0x2f", { hex : false}); //"-0x2f")
|
| 38 |
+
toNumber("06"); //6)
|
| 39 |
+
toNumber("06", { leadingZeros : true}); //6)
|
| 40 |
+
toNumber("06", { leadingZeros : false}); //"06")
|
| 41 |
+
|
| 42 |
+
toNumber("006"); //6)
|
| 43 |
+
toNumber("006", { leadingZeros : true}); //6)
|
| 44 |
+
toNumber("006", { leadingZeros : false}); //"006")
|
| 45 |
+
toNumber("0.0"); //0)
|
| 46 |
+
toNumber("00.00"); //0)
|
| 47 |
+
toNumber("0.06"); //0.06)
|
| 48 |
+
toNumber("00.6"); //0.6)
|
| 49 |
+
toNumber(".006"); //0.006)
|
| 50 |
+
toNumber("6.0"); //6)
|
| 51 |
+
toNumber("06.0"); //6)
|
| 52 |
+
|
| 53 |
+
toNumber("0.0", { leadingZeros : false}); //0)
|
| 54 |
+
toNumber("00.00", { leadingZeros : false}); //"00.00")
|
| 55 |
+
toNumber("0.06", { leadingZeros : false}); //0.06)
|
| 56 |
+
toNumber("00.6", { leadingZeros : false}); //"00.6")
|
| 57 |
+
toNumber(".006", { leadingZeros : false}); //0.006)
|
| 58 |
+
toNumber("6.0" , { leadingZeros : false}); //6)
|
| 59 |
+
toNumber("06.0" , { leadingZeros : false}); //"06.0")
|
| 60 |
+
toNumber("-06"); //-6)
|
| 61 |
+
toNumber("-06", { leadingZeros : true}); //-6)
|
| 62 |
+
toNumber("-06", { leadingZeros : false}); //"-06")
|
| 63 |
+
|
| 64 |
+
toNumber("-0.0"); //-0)
|
| 65 |
+
toNumber("-00.00"); //-0)
|
| 66 |
+
toNumber("-0.06"); //-0.06)
|
| 67 |
+
toNumber("-00.6"); //-0.6)
|
| 68 |
+
toNumber("-.006"); //-0.006)
|
| 69 |
+
toNumber("-6.0"); //-6)
|
| 70 |
+
toNumber("-06.0"); //-6)
|
| 71 |
+
|
| 72 |
+
toNumber("-0.0" , { leadingZeros : false}); //-0)
|
| 73 |
+
toNumber("-00.00", { leadingZeros : false}); //"-00.00")
|
| 74 |
+
toNumber("-0.06", { leadingZeros : false}); //-0.06)
|
| 75 |
+
toNumber("-00.6", { leadingZeros : false}); //"-00.6")
|
| 76 |
+
toNumber("-.006", {leadingZeros : false}); //-0.006)
|
| 77 |
+
toNumber("-6.0" , { leadingZeros : false}); //-6)
|
| 78 |
+
toNumber("-06.0" , { leadingZeros : false}); //"-06.0")
|
| 79 |
+
toNumber("420926189200190257681175017717") ; //4.209261892001902e+29)
|
| 80 |
+
toNumber("000000000000000000000000017717" , { leadingZeros : false}); //"000000000000000000000000017717")
|
| 81 |
+
toNumber("000000000000000000000000017717" , { leadingZeros : true}); //17717)
|
| 82 |
+
toNumber("01.0e2" , { leadingZeros : false}); //"01.0e2")
|
| 83 |
+
toNumber("-01.0e2" , { leadingZeros : false}); //"-01.0e2")
|
| 84 |
+
toNumber("01.0e2") ; //100)
|
| 85 |
+
toNumber("-01.0e2") ; //-100)
|
| 86 |
+
toNumber("1.0e2") ; //100)
|
| 87 |
+
|
| 88 |
+
toNumber("-1.0e2") ; //-100)
|
| 89 |
+
toNumber("1.0e-2"); //0.01)
|
| 90 |
+
|
| 91 |
+
toNumber("+1212121212"); // 1212121212
|
| 92 |
+
toNumber("+1212121212", { skipLike: /\+[0-9]{10}/} )); //"+1212121212"
|
| 93 |
+
|
| 94 |
+
toNumber("1e1000", { unicode: true, infinity: "original" }); //"1e1000"
|
| 95 |
+
toNumber("1000", { unicode: true }); //1000
|
| 96 |
+
toNumber("1000", { unicode: false }); //"1000"
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
Supported Options
|
| 100 |
+
```js
|
| 101 |
+
hex: true, //when hexadecimal string should be parsed
|
| 102 |
+
leadingZeros: true, //when number with leading zeros like 08 should be parsed. 0.0 is not impacted
|
| 103 |
+
eNotation: true, //when number with eNotation or number parsed in eNotation should be considered
|
| 104 |
+
skipLike: /regex/ //when string should not be parsed when it matches the specified regular expression
|
| 105 |
+
infinity: "original", // "null", "infinity" (Infinity type), "string" ("Infinity" (the string literal))
|
| 106 |
+
unicode: false, //when number with unicode numerals should be parsed
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
# Try out our other work
|
| 111 |
+
|
| 112 |
+
WishIn - You need it if negative thoughts take over all the time <br>
|
| 113 |
+
<a href="https://play.google.com/store/apps/details?id=com.solothought.wishin"> <img src="https://solothought.com/products/assets/images/wishin/YouTubeThumbnail.png" width="500px"/> </a>
|
node_modules/strnum/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "strnum",
|
| 3 |
+
"version": "2.4.0",
|
| 4 |
+
"description": "Parse String to Number based on configuration",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"main": "strnum.js",
|
| 7 |
+
"scripts": {
|
| 8 |
+
"test": "jasmine tests/*_test.js"
|
| 9 |
+
},
|
| 10 |
+
"keywords": [
|
| 11 |
+
"string",
|
| 12 |
+
"number",
|
| 13 |
+
"parse",
|
| 14 |
+
"convert"
|
| 15 |
+
],
|
| 16 |
+
"repository": {
|
| 17 |
+
"type": "git",
|
| 18 |
+
"url": "https://github.com/NaturalIntelligence/strnum"
|
| 19 |
+
},
|
| 20 |
+
"author": "Amit Gupta (https://solothought.work/)",
|
| 21 |
+
"license": "MIT",
|
| 22 |
+
"funding": [
|
| 23 |
+
{
|
| 24 |
+
"type": "github",
|
| 25 |
+
"url": "https://github.com/sponsors/NaturalIntelligence"
|
| 26 |
+
}
|
| 27 |
+
],
|
| 28 |
+
"devDependencies": {
|
| 29 |
+
"@byspec/numbers": "^0.1.1",
|
| 30 |
+
"jasmine": "^5.6.0"
|
| 31 |
+
},
|
| 32 |
+
"dependencies": {
|
| 33 |
+
"anynum": "^1.0.0"
|
| 34 |
+
}
|
| 35 |
+
}
|
node_modules/strnum/strnum.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
| 2 |
+
const binRegex = /^0b[01]+$/;
|
| 3 |
+
const octRegex = /^0o[0-7]+$/;
|
| 4 |
+
const numRegex = /^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/;
|
| 5 |
+
|
| 6 |
+
import anynum from "anynum";
|
| 7 |
+
|
| 8 |
+
const consider = {
|
| 9 |
+
hex: true,
|
| 10 |
+
binary: false,
|
| 11 |
+
octal: false,
|
| 12 |
+
leadingZeros: true,
|
| 13 |
+
decimalPoint: "\.",
|
| 14 |
+
eNotation: true,
|
| 15 |
+
//skipLike: /regex/,
|
| 16 |
+
infinity: "original", // "null", "infinity" (Infinity type), "string" ("Infinity" (the string literal))
|
| 17 |
+
unicode: false,
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
export default function toNumber(str, options = {}) {
|
| 21 |
+
options = Object.assign({}, consider, options);
|
| 22 |
+
if (!str || typeof str !== "string") return str;
|
| 23 |
+
|
| 24 |
+
let trimmedStr = str.trim();
|
| 25 |
+
|
| 26 |
+
if (trimmedStr.length === 0) return str;
|
| 27 |
+
else if (options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;
|
| 28 |
+
else if (trimmedStr === "0") return 0;
|
| 29 |
+
|
| 30 |
+
if (options.unicode) {
|
| 31 |
+
trimmedStr = anynum(trimmedStr);
|
| 32 |
+
if (trimmedStr === "0") return 0; // re-check after normalization
|
| 33 |
+
}
|
| 34 |
+
if (options.hex && hexRegex.test(trimmedStr)) {
|
| 35 |
+
return parse_int(trimmedStr, 16);
|
| 36 |
+
} else if (options.binary && binRegex.test(trimmedStr)) {
|
| 37 |
+
return parse_int(trimmedStr, 2);
|
| 38 |
+
} else if (options.octal && octRegex.test(trimmedStr)) {
|
| 39 |
+
return parse_int(trimmedStr, 8);
|
| 40 |
+
} else if (!isFinite(trimmedStr)) { //Infinity
|
| 41 |
+
return handleInfinity(str, Number(trimmedStr), options);
|
| 42 |
+
} else if (trimmedStr.includes('e') || trimmedStr.includes('E')) { //eNotation
|
| 43 |
+
return resolveEnotation(str, trimmedStr, options);
|
| 44 |
+
} else {
|
| 45 |
+
//separate negative sign, leading zeros, and rest number
|
| 46 |
+
const match = numRegex.exec(trimmedStr);
|
| 47 |
+
// +00.123 => [ , '+', '00', '.123', ..
|
| 48 |
+
if (match) {
|
| 49 |
+
const sign = match[1] || "";
|
| 50 |
+
const leadingZeros = match[2];
|
| 51 |
+
let numTrimmedByZeros = trimZeros(match[3]); //complete num without leading zeros
|
| 52 |
+
const decimalAdjacentToLeadingZeros = sign ? // 0., -00., 000.
|
| 53 |
+
str[leadingZeros.length + 1] === "."
|
| 54 |
+
: str[leadingZeros.length] === ".";
|
| 55 |
+
|
| 56 |
+
//trim ending zeros for floating number
|
| 57 |
+
if (!options.leadingZeros //leading zeros are not allowed
|
| 58 |
+
&& (leadingZeros.length > 1
|
| 59 |
+
|| (leadingZeros.length === 1 && !decimalAdjacentToLeadingZeros))) {
|
| 60 |
+
// 00, 00.3, +03.24, 03, 03.24
|
| 61 |
+
return str;
|
| 62 |
+
}
|
| 63 |
+
else {//no leading zeros or leading zeros are allowed
|
| 64 |
+
const num = Number(trimmedStr);
|
| 65 |
+
const parsedStr = String(num);
|
| 66 |
+
|
| 67 |
+
if (num === 0) return num;
|
| 68 |
+
if (parsedStr.search(/[eE]/) !== -1) { //given number is long and parsed to eNotation
|
| 69 |
+
if (options.eNotation) return num;
|
| 70 |
+
else return str;
|
| 71 |
+
} else if (trimmedStr.indexOf(".") !== -1) { //floating number
|
| 72 |
+
if (parsedStr === "0") return num; //0.0
|
| 73 |
+
else if (parsedStr === numTrimmedByZeros) return num; //0.456. 0.79000
|
| 74 |
+
else if (parsedStr === `${sign}${numTrimmedByZeros}`) return num;
|
| 75 |
+
else return str;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
let n = leadingZeros ? numTrimmedByZeros : trimmedStr;
|
| 79 |
+
if (leadingZeros) {
|
| 80 |
+
// -009 => -9
|
| 81 |
+
return (n === parsedStr) || (sign + n === parsedStr) ? num : str
|
| 82 |
+
} else {
|
| 83 |
+
// +9
|
| 84 |
+
return (n === parsedStr) || (n === sign + parsedStr) ? num : str
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
} else { //non-numeric string
|
| 88 |
+
return str;
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
const eNotationRegx = /^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;
|
| 94 |
+
function resolveEnotation(str, trimmedStr, options) {
|
| 95 |
+
if (!options.eNotation) return str;
|
| 96 |
+
const notation = trimmedStr.match(eNotationRegx);
|
| 97 |
+
if (notation) {
|
| 98 |
+
let sign = notation[1] || "";
|
| 99 |
+
const eChar = notation[3].indexOf("e") === -1 ? "E" : "e";
|
| 100 |
+
const leadingZeros = notation[2];
|
| 101 |
+
const eAdjacentToLeadingZeros = sign ? // 0E.
|
| 102 |
+
str[leadingZeros.length + 1] === eChar
|
| 103 |
+
: str[leadingZeros.length] === eChar;
|
| 104 |
+
|
| 105 |
+
if (leadingZeros.length > 1 && eAdjacentToLeadingZeros) return str;
|
| 106 |
+
else if (leadingZeros.length === 1
|
| 107 |
+
&& (notation[3].startsWith(`.${eChar}`) || notation[3][0] === eChar)) {
|
| 108 |
+
return Number(trimmedStr);
|
| 109 |
+
} else if (leadingZeros.length > 0) {
|
| 110 |
+
// Has leading zeros — only accept if leadingZeros option allows it
|
| 111 |
+
if (options.leadingZeros && !eAdjacentToLeadingZeros) {
|
| 112 |
+
trimmedStr = (notation[1] || "") + notation[3];
|
| 113 |
+
return Number(trimmedStr);
|
| 114 |
+
} else return str;
|
| 115 |
+
} else {
|
| 116 |
+
// No leading zeros — always valid e-notation, parse it
|
| 117 |
+
return Number(trimmedStr);
|
| 118 |
+
}
|
| 119 |
+
} else {
|
| 120 |
+
return str;
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/**
|
| 125 |
+
*
|
| 126 |
+
* @param {string} numStr without leading zeros
|
| 127 |
+
* @returns
|
| 128 |
+
*/
|
| 129 |
+
function trimZeros(numStr) {
|
| 130 |
+
if (numStr && numStr.indexOf(".") !== -1) {//float
|
| 131 |
+
numStr = numStr.replace(/0+$/, ""); //remove ending zeros
|
| 132 |
+
if (numStr === ".") numStr = "0";
|
| 133 |
+
else if (numStr[0] === ".") numStr = "0" + numStr;
|
| 134 |
+
else if (numStr[numStr.length - 1] === ".") numStr = numStr.substring(0, numStr.length - 1);
|
| 135 |
+
return numStr;
|
| 136 |
+
}
|
| 137 |
+
return numStr;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
function parse_int(numStr, base) {
|
| 141 |
+
const str = numStr.trim();
|
| 142 |
+
if (base === 2 || base === 8) numStr = str.substring(2);
|
| 143 |
+
|
| 144 |
+
if (parseInt) return parseInt(numStr, base);
|
| 145 |
+
else if (Number.parseInt) return Number.parseInt(numStr, base);
|
| 146 |
+
else if (window && window.parseInt) return window.parseInt(numStr, base);
|
| 147 |
+
else throw new Error("parseInt, Number.parseInt, window.parseInt are not supported");
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/**
|
| 151 |
+
* Handle infinite values based on user option
|
| 152 |
+
* @param {string} str - original input string
|
| 153 |
+
* @param {number} num - parsed number (Infinity or -Infinity)
|
| 154 |
+
* @param {object} options - user options
|
| 155 |
+
* @returns {string|number|null} based on infinity option
|
| 156 |
+
*/
|
| 157 |
+
function handleInfinity(str, num, options) {
|
| 158 |
+
const isPositive = num === Infinity;
|
| 159 |
+
|
| 160 |
+
switch (options.infinity.toLowerCase()) {
|
| 161 |
+
case "null":
|
| 162 |
+
return null;
|
| 163 |
+
case "infinity":
|
| 164 |
+
return num; // Return Infinity or -Infinity
|
| 165 |
+
case "string":
|
| 166 |
+
return isPositive ? "Infinity" : "-Infinity";
|
| 167 |
+
case "original":
|
| 168 |
+
default:
|
| 169 |
+
return str; // Return original string like "1e1000"
|
| 170 |
+
}
|
| 171 |
+
}
|
node_modules/strtok3/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright © 2026 Borewit
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
node_modules/strtok3/README.md
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[](https://github.com/Borewit/strtok3/actions/workflows/ci.yml)
|
| 2 |
+
[](https://github.com/Borewit/strtok3/actions/workflows/codeql.yml)
|
| 3 |
+
[](https://npmjs.org/package/strtok3)
|
| 4 |
+
[](https://npmcharts.com/compare/strtok3,token-types?start=1200&interval=30)
|
| 5 |
+
[](https://deepscan.io/dashboard#view=project&tid=5165&pid=8526&bid=103329)
|
| 6 |
+
[](https://snyk.io/test/github/Borewit/strtok3?targetFile=package.json)
|
| 7 |
+
[](https://www.codacy.com/app/Borewit/strtok3?utm_source=github.com&utm_medium=referral&utm_content=Borewit/strtok3&utm_campaign=Badge_Grade)
|
| 8 |
+
# strtok3
|
| 9 |
+
|
| 10 |
+
A promise based streaming [*tokenizer*](#tokenizer-object) for [Node.js](http://nodejs.org) and browsers.
|
| 11 |
+
|
| 12 |
+
The `strtok3` module provides several methods for creating a [*tokenizer*](#tokenizer-object) from various input sources.
|
| 13 |
+
Designed for:
|
| 14 |
+
* Seamless support in streaming environments.
|
| 15 |
+
* Efficiently decode binary data, strings, and numbers.
|
| 16 |
+
* Reading [predefined](https://github.com/Borewit/token-types) or custom tokens.
|
| 17 |
+
* Offering [*tokenizers*](#tokenizer-object) for reading from [files](#method-strtok3fromfile), [streams](#fromstream-function) or [Uint8Arrays](#frombuffer-function).
|
| 18 |
+
|
| 19 |
+
### Features
|
| 20 |
+
`strtok3` can read from:
|
| 21 |
+
* Files, using a file path as input.
|
| 22 |
+
* Node.js [streams](https://nodejs.org/api/stream.html).
|
| 23 |
+
* [Buffer](https://nodejs.org/api/buffer.html) or [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).
|
| 24 |
+
* HTTP chunked transfer provided by [@tokenizer/http](https://github.com/Borewit/tokenizer-http).
|
| 25 |
+
* [Amazon S3](https://aws.amazon.com/s3) chunks with [@tokenizer/s3](https://github.com/Borewit/tokenizer-s3).
|
| 26 |
+
|
| 27 |
+
## Installation
|
| 28 |
+
|
| 29 |
+
```sh
|
| 30 |
+
npm install strtok3
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
### Compatibility
|
| 34 |
+
|
| 35 |
+
Starting with version 7, the module has migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
|
| 36 |
+
The distributed JavaScript codebase is compliant with the [ECMAScript 2020 (11th Edition)](https://en.wikipedia.org/wiki/ECMAScript_version_history#11th_Edition_%E2%80%93_ECMAScript_2020) standard.
|
| 37 |
+
|
| 38 |
+
Requires a modern browser, Node.js (V8) ≥ 18 engine or Bun (JavaScriptCore) ≥ 1.2.
|
| 39 |
+
|
| 40 |
+
For TypeScript CommonJs backward compatibility, you can use [load-esm](https://github.com/Borewit/load-esm).
|
| 41 |
+
|
| 42 |
+
> [!NOTE]
|
| 43 |
+
> This module requires a [Node.js ≥ 16](https://nodejs.org/en/about/previous-releases) engine.
|
| 44 |
+
> It can also be used in a browser environment when bundled with a module bundler.
|
| 45 |
+
|
| 46 |
+
## Support the Project
|
| 47 |
+
If you find this project useful and would like to support its development, consider sponsoring or contributing:
|
| 48 |
+
|
| 49 |
+
- [Become a sponsor to Borewit](https://github.com/sponsors/Borewit)
|
| 50 |
+
|
| 51 |
+
- Buy me a coffee:
|
| 52 |
+
|
| 53 |
+
<a href="https://www.buymeacoffee.com/borewit" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy me A coffee" height="41" width="174"></a>
|
| 54 |
+
|
| 55 |
+
## API Documentation
|
| 56 |
+
|
| 57 |
+
### strtok3 methods
|
| 58 |
+
|
| 59 |
+
Use one of the methods to instantiate an [*abstract tokenizer*](#tokenizer-object):
|
| 60 |
+
- [fromBlob](#fromblob-function)
|
| 61 |
+
- [fromBuffer](#frombuffer-function)
|
| 62 |
+
- [fromFile](#fromfile-function)*
|
| 63 |
+
- [fromStream](#fromstream-function)*
|
| 64 |
+
- [fromWebStream](#fromwebstream-function)
|
| 65 |
+
|
| 66 |
+
> [!NOTE]
|
| 67 |
+
> `fromFile` and `fromStream` only available when importing this module with Node.js
|
| 68 |
+
|
| 69 |
+
All methods return a [`Tokenizer`](#tokenizer-object), either directly or via a promise.
|
| 70 |
+
|
| 71 |
+
#### `fromBlob()` function
|
| 72 |
+
|
| 73 |
+
Create a tokenizer from a [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
|
| 74 |
+
|
| 75 |
+
```ts
|
| 76 |
+
function fromBlob(blob: Blob, options?: ITokenizerOptions): BlobTokenizer
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
| Parameter | Optional | Type | Description |
|
| 80 |
+
|-----------|-----------|---------------------------------------------------|----------------------------------------------------------------------------------------|
|
| 81 |
+
| blob | no | [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) | [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [File](https://developer.mozilla.org/en-US/docs/Web/API/File) to read from |
|
| 82 |
+
| options | yes | [ITokenizerOptions](#ITokenizerOptions) | Tokenizer options |
|
| 83 |
+
|
| 84 |
+
Returns a [*tokenizer*](#tokenizer-object).
|
| 85 |
+
|
| 86 |
+
```js
|
| 87 |
+
import { fromBlob } from 'strtok3';
|
| 88 |
+
import { openAsBlob } from 'node:fs';
|
| 89 |
+
import * as Token from 'token-types';
|
| 90 |
+
|
| 91 |
+
async function parse() {
|
| 92 |
+
const blob = await openAsBlob('somefile.bin');
|
| 93 |
+
|
| 94 |
+
const tokenizer = fromBlob(blob);
|
| 95 |
+
|
| 96 |
+
const myUint8Number = await tokenizer.readToken(Token.UINT8);
|
| 97 |
+
console.log(`My number: ${myUint8Number}`);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
parse();
|
| 101 |
+
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
#### `fromBuffer()` function
|
| 105 |
+
|
| 106 |
+
Create a tokenizer from memory ([Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) or Node.js [Buffer](https://nodejs.org/api/buffer.html)).
|
| 107 |
+
|
| 108 |
+
```ts
|
| 109 |
+
function fromBuffer(uint8Array: Uint8Array, options?: ITokenizerOptions): BufferTokenizer
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
| Parameter | Optional | Type | Description |
|
| 113 |
+
|------------|----------|--------------------------------------------------|-----------------------------------|
|
| 114 |
+
| uint8Array | no | [Uint8Array](https://nodejs.org/api/buffer.html) | Buffer or Uint8Array to read from |
|
| 115 |
+
| options | yes | [ITokenizerOptions](#ITokenizerOptions) | Tokenizer options |
|
| 116 |
+
|
| 117 |
+
Returns a [*tokenizer*](#tokenizer-object).
|
| 118 |
+
|
| 119 |
+
```js
|
| 120 |
+
import { fromBuffer } from 'strtok3';
|
| 121 |
+
import * as Token from 'token-types';
|
| 122 |
+
|
| 123 |
+
const tokenizer = fromBuffer(buffer);
|
| 124 |
+
|
| 125 |
+
async function parse() {
|
| 126 |
+
const myUint8Number = await tokenizer.readToken(Token.UINT8);
|
| 127 |
+
console.log(`My number: ${myUint8Number}`);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
parse();
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
#### `fromFile` function
|
| 134 |
+
|
| 135 |
+
Creates a [*tokenizer*](#tokenizer-object) from a local file.
|
| 136 |
+
|
| 137 |
+
```ts
|
| 138 |
+
function fromFile(sourceFilePath: string): Promise<FileTokenizer>
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
| Parameter | Type | Description |
|
| 142 |
+
|----------------|----------|----------------------------|
|
| 143 |
+
| sourceFilePath | `string` | Path to file to read from |
|
| 144 |
+
|
| 145 |
+
> [!NOTE]
|
| 146 |
+
> - Only available for Node.js engines
|
| 147 |
+
> - `fromFile` automatically embeds [file-information](#file-information)
|
| 148 |
+
|
| 149 |
+
A Promise resolving to a [*tokenizer*](#tokenizer-object) which can be used to parse a file.
|
| 150 |
+
|
| 151 |
+
```js
|
| 152 |
+
import { fromFile } from 'strtok3';
|
| 153 |
+
import * as Token from 'token-types';
|
| 154 |
+
|
| 155 |
+
async function parse() {
|
| 156 |
+
const tokenizer = await fromFile('somefile.bin');
|
| 157 |
+
try {
|
| 158 |
+
const myNumber = await tokenizer.readToken(Token.UINT8);
|
| 159 |
+
console.log(`My number: ${myNumber}`);
|
| 160 |
+
} finally {
|
| 161 |
+
tokenizer.close(); // Close the file
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
parse();
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
```
|
| 169 |
+
|
| 170 |
+
#### `fromWebStream()` function
|
| 171 |
+
|
| 172 |
+
Create a tokenizer from a [WHATWG ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).
|
| 173 |
+
|
| 174 |
+
```ts
|
| 175 |
+
function fromWebStream(webStream: AnyWebByteStream, options?: ITokenizerOptions): ReadStreamTokenizer
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
| Parameter | Optional | Type | Description |
|
| 179 |
+
|----------------|----------|--------------------------------------------------------------------------|------------------------------------|
|
| 180 |
+
| webStream | no | [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) | WHATWG ReadableStream to read from |
|
| 181 |
+
| options | yes | [ITokenizerOptions](#ITokenizerOptions) | Tokenizer options |
|
| 182 |
+
|
| 183 |
+
Returns a [*tokenizer*](#tokenizer-object).
|
| 184 |
+
|
| 185 |
+
```js
|
| 186 |
+
import { fromWebStream } from 'strtok3';
|
| 187 |
+
import * as Token from 'token-types';
|
| 188 |
+
|
| 189 |
+
async function parse() {
|
| 190 |
+
const tokenizer = fromWebStream(readableStream);
|
| 191 |
+
try {
|
| 192 |
+
const myUint8Number = await tokenizer.readToken(Token.UINT8);
|
| 193 |
+
console.log(`My number: ${myUint8Number}`);
|
| 194 |
+
} finally {
|
| 195 |
+
await tokenizer.close();
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
parse();
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
### `Tokenizer` object
|
| 203 |
+
The *tokenizer* is an abstraction of a [stream](https://nodejs.org/api/stream.html), file or [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), allowing _reading_ or _peeking_ from the stream.
|
| 204 |
+
It can also be translated in chunked reads, as done in [@tokenizer/http](https://github.com/Borewit/tokenizer-http);
|
| 205 |
+
|
| 206 |
+
#### Key Features:
|
| 207 |
+
|
| 208 |
+
- Supports seeking within the stream using `tokenizer.ignore()`.
|
| 209 |
+
- Offers `peek` methods to preview data without advancing the read pointer.
|
| 210 |
+
- Maintains the read position via tokenizer.position.
|
| 211 |
+
|
| 212 |
+
#### Tokenizer functions
|
| 213 |
+
|
| 214 |
+
_Read_ methods advance the stream pointer, while _peek_ methods do not.
|
| 215 |
+
|
| 216 |
+
There are two kind of functions:
|
| 217 |
+
1. *read* methods: used to read a *token* of [Buffer](https://nodejs.org/api/buffer.html) from the [*tokenizer*](#tokenizer-object). The position of the *tokenizer-stream* will advance with the size of the token.
|
| 218 |
+
2. *peek* methods: same as the read, but it will *not* advance the pointer. It allows to read (peek) ahead.
|
| 219 |
+
|
| 220 |
+
#### `readBuffer` function
|
| 221 |
+
|
| 222 |
+
Read data from the _tokenizer_ into provided "buffer" (`Uint8Array`).
|
| 223 |
+
`readBuffer(buffer, options?)`
|
| 224 |
+
|
| 225 |
+
```ts
|
| 226 |
+
readBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 227 |
+
```
|
| 228 |
+
|
| 229 |
+
| Parameter | Type | Description |
|
| 230 |
+
|------------|----------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 231 |
+
| buffer | [Buffer](https://nodejs.org/api/buffer.html) | Uint8Array | Target buffer to write the data read to |
|
| 232 |
+
| options | [IReadChunkOptions](#ireadchunkoptions-interface) | An integer specifying the number of bytes to read |
|
| 233 |
+
|
| 234 |
+
Return promise with number of bytes read.
|
| 235 |
+
The number of bytes read may be less than requested if the `mayBeLess` flag is set.
|
| 236 |
+
|
| 237 |
+
#### `peekBuffer` function
|
| 238 |
+
|
| 239 |
+
Peek (read ahead), from [*tokenizer*](#tokenizer-object), into the buffer without advancing the stream pointer.
|
| 240 |
+
|
| 241 |
+
```ts
|
| 242 |
+
peekBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 243 |
+
```
|
| 244 |
+
|
| 245 |
+
| Parameter | Type | Description |
|
| 246 |
+
|------------|-----------------------------------------|-----------------------------------------------------|
|
| 247 |
+
| buffer | Buffer | Uint8Array | Target buffer to write the data read (peeked) to. |
|
| 248 |
+
| options | [IReadChunkOptions](#ireadchunkoptions-interface) | An integer specifying the number of bytes to read. | |
|
| 249 |
+
|
| 250 |
+
Return value `Promise<number>` Promise with number of bytes read. The number of bytes read may be less if the `mayBeLess` flag was set.
|
| 251 |
+
|
| 252 |
+
#### `readToken` function
|
| 253 |
+
|
| 254 |
+
Read a *token* from the tokenizer-stream.
|
| 255 |
+
|
| 256 |
+
```ts
|
| 257 |
+
readToken<Value>(token: IGetToken<Value>, position: number = this.position): Promise<Value>
|
| 258 |
+
```
|
| 259 |
+
|
| 260 |
+
| Parameter | Type | Description |
|
| 261 |
+
|------------|-------------------------|---------------------------------------------------------------------------------------------------------------------- |
|
| 262 |
+
| token | [IGetToken](#IGetToken) | Token to read from the tokenizer-stream. |
|
| 263 |
+
| position? | number | Offset where to begin reading within the file. If position is null, data will be read from the current file position. |
|
| 264 |
+
|
| 265 |
+
Return value `Promise<number>`. Promise with number of bytes read. The number of bytes read maybe if less, `mayBeLess` flag was set.
|
| 266 |
+
|
| 267 |
+
#### `peek` function
|
| 268 |
+
|
| 269 |
+
Peek a *token* from the [*tokenizer*](#tokenizer-object).
|
| 270 |
+
|
| 271 |
+
```ts
|
| 272 |
+
peekToken<Value>(token: IGetToken<Value>, position: number = this.position): Promise<Value>
|
| 273 |
+
```
|
| 274 |
+
|
| 275 |
+
| Parameter | Type | Description |
|
| 276 |
+
|------------|----------------------------|-------------------------------------------------------------------------------------------------------------------------|
|
| 277 |
+
| token | [IGetToken<T>](#IGetToken) | Token to read from the tokenizer-stream. |
|
| 278 |
+
| position? | number | Offset where to begin reading within the file. If position is null, data will be read from the current file position. |
|
| 279 |
+
|
| 280 |
+
Return a promise with the token value peeked from the [*tokenizer*](#tokenizer-object).
|
| 281 |
+
|
| 282 |
+
#### `readNumber` function
|
| 283 |
+
|
| 284 |
+
Read a numeric [*token*](#token) from the [*tokenizer*](#tokenizer-object).
|
| 285 |
+
|
| 286 |
+
```ts
|
| 287 |
+
readNumber(token: IToken<number>): Promise<number>
|
| 288 |
+
```
|
| 289 |
+
|
| 290 |
+
| Parameter | Type | Description |
|
| 291 |
+
|------------|---------------------------------|----------------------------------------------------|
|
| 292 |
+
| token | [IGetToken<number>](#IGetToken) | Numeric token to read from the tokenizer-stream. |
|
| 293 |
+
|
| 294 |
+
A promise resolving to a numeric value read and decoded from the *tokenizer-stream*.
|
| 295 |
+
|
| 296 |
+
#### `ignore` function
|
| 297 |
+
|
| 298 |
+
Advance the offset pointer with the token number of bytes provided.
|
| 299 |
+
|
| 300 |
+
```ts
|
| 301 |
+
ignore(length: number): Promise<number>
|
| 302 |
+
```
|
| 303 |
+
|
| 304 |
+
| Parameter | Type | Description |
|
| 305 |
+
|------------|--------|------------------------------------------------------------------|
|
| 306 |
+
| length | number | Number of bytes to ignore. Will advance the `tokenizer.position` |
|
| 307 |
+
|
| 308 |
+
A promise resolving to the number of bytes ignored from the *tokenizer-stream*.
|
| 309 |
+
|
| 310 |
+
#### `close` function
|
| 311 |
+
Clean up resources, such as closing a file pointer if applicable.
|
| 312 |
+
|
| 313 |
+
#### `Tokenizer` attributes
|
| 314 |
+
|
| 315 |
+
- `fileInfo`
|
| 316 |
+
|
| 317 |
+
Optional attribute describing the file information, see [IFileInfo](#IFileInfo)
|
| 318 |
+
|
| 319 |
+
- `position`
|
| 320 |
+
|
| 321 |
+
Pointer to the current position in the [*tokenizer*](#tokenizer-object) stream.
|
| 322 |
+
If a *position* is provided to a _read_ or _peek_ method, is should be, at least, equal or greater than this value.
|
| 323 |
+
|
| 324 |
+
### `IReadChunkOptions` interface
|
| 325 |
+
|
| 326 |
+
Each attribute is optional:
|
| 327 |
+
|
| 328 |
+
| Attribute | Type | Description |
|
| 329 |
+
|-----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 330 |
+
| length | number | Requested number of bytes to read. |
|
| 331 |
+
| position | number | Position where to peek from the file. If position is null, data will be read from the [current file position](#attribute-tokenizerposition). Position may not be less then [tokenizer.position](#attribute-tokenizerposition) |
|
| 332 |
+
| mayBeLess | boolean | If and only if set, will not throw an EOF error if less than the requested `mayBeLess` could be read. |
|
| 333 |
+
|
| 334 |
+
Example usage:
|
| 335 |
+
```js
|
| 336 |
+
tokenizer.peekBuffer(buffer, {mayBeLess: true});
|
| 337 |
+
```
|
| 338 |
+
|
| 339 |
+
### `IFileInfo` interface
|
| 340 |
+
|
| 341 |
+
Provides optional metadata about the file being tokenized.
|
| 342 |
+
|
| 343 |
+
| Attribute | Type | Description |
|
| 344 |
+
|-----------|---------|---------------------------------------------------------------------------------------------------|
|
| 345 |
+
| size | number | File size in bytes |
|
| 346 |
+
| mimeType | string | [MIME-type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of file. |
|
| 347 |
+
| path | string | File path |
|
| 348 |
+
| url | string | File URL |
|
| 349 |
+
|
| 350 |
+
### `Token` object
|
| 351 |
+
|
| 352 |
+
The *token* is basically a description of what to read from the [*tokenizer-stream*](#tokenizer-object).
|
| 353 |
+
A basic set of *token types* can be found here: [*token-types*](https://github.com/Borewit/token-types).
|
| 354 |
+
|
| 355 |
+
A token is something which implements the following interface:
|
| 356 |
+
```ts
|
| 357 |
+
export interface IGetToken<T> {
|
| 358 |
+
|
| 359 |
+
/**
|
| 360 |
+
* Length in bytes of encoded value
|
| 361 |
+
*/
|
| 362 |
+
len: number;
|
| 363 |
+
|
| 364 |
+
/**
|
| 365 |
+
* Decode value from buffer at offset
|
| 366 |
+
* @param buf Buffer to read the decoded value from
|
| 367 |
+
* @param off Decode offset
|
| 368 |
+
*/
|
| 369 |
+
get(buf: Uint8Array, off: number): T;
|
| 370 |
+
}
|
| 371 |
+
```
|
| 372 |
+
The *tokenizer* reads `token.len` bytes from the *tokenizer-stream* into a Buffer.
|
| 373 |
+
The `token.get` will be called with the Buffer. `token.get` is responsible for conversion from the buffer to the desired output type.
|
| 374 |
+
|
| 375 |
+
### Working with Web-API readable stream
|
| 376 |
+
To convert a [Web-API readable stream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader) into a [Node.js readable stream]((https://nodejs.org/api/stream.html#stream_readable_streams)), you can use [readable-web-to-node-stream](https://github.com/Borewit/readable-web-to-node-stream) to convert one in another.
|
| 377 |
+
|
| 378 |
+
```js
|
| 379 |
+
import { fromWebStream } from 'strtok3';
|
| 380 |
+
import { ReadableWebToNodeStream } from 'readable-web-to-node-stream';
|
| 381 |
+
|
| 382 |
+
(async () => {
|
| 383 |
+
|
| 384 |
+
const response = await fetch(url);
|
| 385 |
+
const readableWebStream = response.body; // Web-API readable stream
|
| 386 |
+
const webStream = new ReadableWebToNodeStream(readableWebStream); // convert to Node.js readable stream
|
| 387 |
+
|
| 388 |
+
const tokenizer = fromWebStream(webStream); // And we now have tokenizer in a web environment
|
| 389 |
+
})();
|
| 390 |
+
```
|
| 391 |
+
|
| 392 |
+
## Dependencies
|
| 393 |
+
|
| 394 |
+
Dependencies:
|
| 395 |
+
- [@tokenizer/token](https://github.com/Borewit/tokenizer-token): Provides token definitions and utilities used by `strtok3` for interpreting binary data.
|
| 396 |
+
|
| 397 |
+
## Licence
|
| 398 |
+
|
| 399 |
+
This project is licensed under the [MIT License](LICENSE.txt). Feel free to use, modify, and distribute as needed.
|
node_modules/strtok3/lib/AbstractTokenizer.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ITokenizer, IFileInfo, IReadChunkOptions, ITokenizerOptions } from './types.js';
|
| 2 |
+
import type { IGetToken, IToken } from '@tokenizer/token';
|
| 3 |
+
interface INormalizedReadChunkOptions extends IReadChunkOptions {
|
| 4 |
+
length: number;
|
| 5 |
+
position: number;
|
| 6 |
+
mayBeLess?: boolean;
|
| 7 |
+
}
|
| 8 |
+
/**
|
| 9 |
+
* Core tokenizer
|
| 10 |
+
*/
|
| 11 |
+
export declare abstract class AbstractTokenizer implements ITokenizer {
|
| 12 |
+
private onClose?;
|
| 13 |
+
private numBuffer;
|
| 14 |
+
abstract fileInfo: IFileInfo;
|
| 15 |
+
/**
|
| 16 |
+
* Tokenizer-stream position
|
| 17 |
+
*/
|
| 18 |
+
position: number;
|
| 19 |
+
/**
|
| 20 |
+
* Constructor
|
| 21 |
+
* @param options Tokenizer options
|
| 22 |
+
* @protected
|
| 23 |
+
*/
|
| 24 |
+
protected constructor(options?: ITokenizerOptions);
|
| 25 |
+
abstract supportsRandomAccess(): boolean;
|
| 26 |
+
/**
|
| 27 |
+
* Read buffer from tokenizer
|
| 28 |
+
* @param buffer - Target buffer to fill with data read from the tokenizer-stream
|
| 29 |
+
* @param options - Additional read options
|
| 30 |
+
* @returns Promise with number of bytes read
|
| 31 |
+
*/
|
| 32 |
+
abstract readBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 33 |
+
/**
|
| 34 |
+
* Peek (read ahead) buffer from tokenizer
|
| 35 |
+
* @param uint8Array - Target buffer to fill with data peeked from the tokenizer-stream
|
| 36 |
+
* @param options - Peek behaviour options
|
| 37 |
+
* @returns Promise with number of bytes read
|
| 38 |
+
*/
|
| 39 |
+
abstract peekBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 40 |
+
/**
|
| 41 |
+
* Read a token from the tokenizer-stream
|
| 42 |
+
* @param token - The token to read
|
| 43 |
+
* @param position - If provided, the desired position in the tokenizer-stream
|
| 44 |
+
* @returns Promise with token data
|
| 45 |
+
*/
|
| 46 |
+
readToken<Value>(token: IGetToken<Value>, position?: number): Promise<Value>;
|
| 47 |
+
/**
|
| 48 |
+
* Peek a token from the tokenizer-stream.
|
| 49 |
+
* @param token - Token to peek from the tokenizer-stream.
|
| 50 |
+
* @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
|
| 51 |
+
* @returns Promise with token data
|
| 52 |
+
*/
|
| 53 |
+
peekToken<Value>(token: IGetToken<Value>, position?: number): Promise<Value>;
|
| 54 |
+
/**
|
| 55 |
+
* Read a numeric token from the stream
|
| 56 |
+
* @param token - Numeric token
|
| 57 |
+
* @returns Promise with number
|
| 58 |
+
*/
|
| 59 |
+
readNumber(token: IToken<number>): Promise<number>;
|
| 60 |
+
/**
|
| 61 |
+
* Read a numeric token from the stream
|
| 62 |
+
* @param token - Numeric token
|
| 63 |
+
* @returns Promise with number
|
| 64 |
+
*/
|
| 65 |
+
peekNumber(token: IToken<number>): Promise<number>;
|
| 66 |
+
/**
|
| 67 |
+
* Ignore number of bytes, advances the pointer in under tokenizer-stream.
|
| 68 |
+
* @param length - Number of bytes to ignore. Must be ≥ 0.
|
| 69 |
+
* @return resolves the number of bytes ignored, equals length if this available, otherwise the number of bytes available
|
| 70 |
+
*/
|
| 71 |
+
ignore(length: number): Promise<number>;
|
| 72 |
+
close(): Promise<void>;
|
| 73 |
+
protected normalizeOptions(uint8Array: Uint8Array, options?: IReadChunkOptions): INormalizedReadChunkOptions;
|
| 74 |
+
abort(): Promise<void>;
|
| 75 |
+
}
|
| 76 |
+
export {};
|
node_modules/strtok3/lib/AbstractTokenizer.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { EndOfStreamError } from './stream/index.js';
|
| 2 |
+
/**
|
| 3 |
+
* Core tokenizer
|
| 4 |
+
*/
|
| 5 |
+
export class AbstractTokenizer {
|
| 6 |
+
/**
|
| 7 |
+
* Constructor
|
| 8 |
+
* @param options Tokenizer options
|
| 9 |
+
* @protected
|
| 10 |
+
*/
|
| 11 |
+
constructor(options) {
|
| 12 |
+
this.numBuffer = new Uint8Array(8);
|
| 13 |
+
/**
|
| 14 |
+
* Tokenizer-stream position
|
| 15 |
+
*/
|
| 16 |
+
this.position = 0;
|
| 17 |
+
this.onClose = options?.onClose;
|
| 18 |
+
if (options?.abortSignal) {
|
| 19 |
+
options.abortSignal.addEventListener('abort', () => {
|
| 20 |
+
this.abort();
|
| 21 |
+
});
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
/**
|
| 25 |
+
* Read a token from the tokenizer-stream
|
| 26 |
+
* @param token - The token to read
|
| 27 |
+
* @param position - If provided, the desired position in the tokenizer-stream
|
| 28 |
+
* @returns Promise with token data
|
| 29 |
+
*/
|
| 30 |
+
async readToken(token, position = this.position) {
|
| 31 |
+
const uint8Array = new Uint8Array(token.len);
|
| 32 |
+
const len = await this.readBuffer(uint8Array, { position });
|
| 33 |
+
if (len < token.len)
|
| 34 |
+
throw new EndOfStreamError();
|
| 35 |
+
return token.get(uint8Array, 0);
|
| 36 |
+
}
|
| 37 |
+
/**
|
| 38 |
+
* Peek a token from the tokenizer-stream.
|
| 39 |
+
* @param token - Token to peek from the tokenizer-stream.
|
| 40 |
+
* @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
|
| 41 |
+
* @returns Promise with token data
|
| 42 |
+
*/
|
| 43 |
+
async peekToken(token, position = this.position) {
|
| 44 |
+
const uint8Array = new Uint8Array(token.len);
|
| 45 |
+
const len = await this.peekBuffer(uint8Array, { position });
|
| 46 |
+
if (len < token.len)
|
| 47 |
+
throw new EndOfStreamError();
|
| 48 |
+
return token.get(uint8Array, 0);
|
| 49 |
+
}
|
| 50 |
+
/**
|
| 51 |
+
* Read a numeric token from the stream
|
| 52 |
+
* @param token - Numeric token
|
| 53 |
+
* @returns Promise with number
|
| 54 |
+
*/
|
| 55 |
+
async readNumber(token) {
|
| 56 |
+
const len = await this.readBuffer(this.numBuffer, { length: token.len });
|
| 57 |
+
if (len < token.len)
|
| 58 |
+
throw new EndOfStreamError();
|
| 59 |
+
return token.get(this.numBuffer, 0);
|
| 60 |
+
}
|
| 61 |
+
/**
|
| 62 |
+
* Read a numeric token from the stream
|
| 63 |
+
* @param token - Numeric token
|
| 64 |
+
* @returns Promise with number
|
| 65 |
+
*/
|
| 66 |
+
async peekNumber(token) {
|
| 67 |
+
const len = await this.peekBuffer(this.numBuffer, { length: token.len });
|
| 68 |
+
if (len < token.len)
|
| 69 |
+
throw new EndOfStreamError();
|
| 70 |
+
return token.get(this.numBuffer, 0);
|
| 71 |
+
}
|
| 72 |
+
/**
|
| 73 |
+
* Ignore number of bytes, advances the pointer in under tokenizer-stream.
|
| 74 |
+
* @param length - Number of bytes to ignore. Must be ≥ 0.
|
| 75 |
+
* @return resolves the number of bytes ignored, equals length if this available, otherwise the number of bytes available
|
| 76 |
+
*/
|
| 77 |
+
async ignore(length) {
|
| 78 |
+
if (length < 0) {
|
| 79 |
+
throw new RangeError('ignore length must be ≥ 0 bytes');
|
| 80 |
+
}
|
| 81 |
+
if (this.fileInfo.size !== undefined) {
|
| 82 |
+
const bytesLeft = this.fileInfo.size - this.position;
|
| 83 |
+
if (length > bytesLeft) {
|
| 84 |
+
this.position += bytesLeft;
|
| 85 |
+
return bytesLeft;
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
this.position += length;
|
| 89 |
+
return length;
|
| 90 |
+
}
|
| 91 |
+
async close() {
|
| 92 |
+
await this.abort();
|
| 93 |
+
await this.onClose?.();
|
| 94 |
+
}
|
| 95 |
+
normalizeOptions(uint8Array, options) {
|
| 96 |
+
if (!this.supportsRandomAccess() && options && options.position !== undefined && options.position < this.position) {
|
| 97 |
+
throw new Error('`options.position` must be equal or greater than `tokenizer.position`');
|
| 98 |
+
}
|
| 99 |
+
return {
|
| 100 |
+
...{
|
| 101 |
+
mayBeLess: false,
|
| 102 |
+
offset: 0,
|
| 103 |
+
length: uint8Array.length,
|
| 104 |
+
position: this.position
|
| 105 |
+
}, ...options
|
| 106 |
+
};
|
| 107 |
+
}
|
| 108 |
+
abort() {
|
| 109 |
+
return Promise.resolve(); // Ignore abort signal
|
| 110 |
+
}
|
| 111 |
+
}
|
node_modules/strtok3/lib/BlobTokenizer.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ITokenizerOptions, IReadChunkOptions, IRandomAccessFileInfo, IRandomAccessTokenizer } from './types.js';
|
| 2 |
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
| 3 |
+
export declare class BlobTokenizer extends AbstractTokenizer implements IRandomAccessTokenizer {
|
| 4 |
+
private blob;
|
| 5 |
+
fileInfo: IRandomAccessFileInfo;
|
| 6 |
+
/**
|
| 7 |
+
* Construct BufferTokenizer
|
| 8 |
+
* @param blob - Uint8Array to tokenize
|
| 9 |
+
* @param options Tokenizer options
|
| 10 |
+
*/
|
| 11 |
+
constructor(blob: Blob, options?: ITokenizerOptions);
|
| 12 |
+
/**
|
| 13 |
+
* Read buffer from tokenizer
|
| 14 |
+
* @param uint8Array - Uint8Array to tokenize
|
| 15 |
+
* @param options - Read behaviour options
|
| 16 |
+
* @returns {Promise<number>}
|
| 17 |
+
*/
|
| 18 |
+
readBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 19 |
+
/**
|
| 20 |
+
* Peek (read ahead) buffer from tokenizer
|
| 21 |
+
* @param buffer
|
| 22 |
+
* @param options - Read behaviour options
|
| 23 |
+
* @returns {Promise<number>}
|
| 24 |
+
*/
|
| 25 |
+
peekBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 26 |
+
close(): Promise<void>;
|
| 27 |
+
supportsRandomAccess(): boolean;
|
| 28 |
+
setPosition(position: number): void;
|
| 29 |
+
}
|
node_modules/strtok3/lib/BlobTokenizer.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { EndOfStreamError } from './stream/index.js';
|
| 2 |
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
| 3 |
+
export class BlobTokenizer extends AbstractTokenizer {
|
| 4 |
+
/**
|
| 5 |
+
* Construct BufferTokenizer
|
| 6 |
+
* @param blob - Uint8Array to tokenize
|
| 7 |
+
* @param options Tokenizer options
|
| 8 |
+
*/
|
| 9 |
+
constructor(blob, options) {
|
| 10 |
+
super(options);
|
| 11 |
+
this.blob = blob;
|
| 12 |
+
this.fileInfo = { ...options?.fileInfo ?? {}, ...{ size: blob.size, mimeType: blob.type } };
|
| 13 |
+
}
|
| 14 |
+
/**
|
| 15 |
+
* Read buffer from tokenizer
|
| 16 |
+
* @param uint8Array - Uint8Array to tokenize
|
| 17 |
+
* @param options - Read behaviour options
|
| 18 |
+
* @returns {Promise<number>}
|
| 19 |
+
*/
|
| 20 |
+
async readBuffer(uint8Array, options) {
|
| 21 |
+
if (options?.position) {
|
| 22 |
+
this.position = options.position;
|
| 23 |
+
}
|
| 24 |
+
const bytesRead = await this.peekBuffer(uint8Array, options);
|
| 25 |
+
this.position += bytesRead;
|
| 26 |
+
return bytesRead;
|
| 27 |
+
}
|
| 28 |
+
/**
|
| 29 |
+
* Peek (read ahead) buffer from tokenizer
|
| 30 |
+
* @param buffer
|
| 31 |
+
* @param options - Read behaviour options
|
| 32 |
+
* @returns {Promise<number>}
|
| 33 |
+
*/
|
| 34 |
+
async peekBuffer(buffer, options) {
|
| 35 |
+
const normOptions = this.normalizeOptions(buffer, options);
|
| 36 |
+
const bytes2read = Math.min(this.blob.size - normOptions.position, normOptions.length);
|
| 37 |
+
if ((!normOptions.mayBeLess) && bytes2read < normOptions.length) {
|
| 38 |
+
throw new EndOfStreamError();
|
| 39 |
+
}
|
| 40 |
+
const arrayBuffer = await this.blob.slice(normOptions.position, normOptions.position + bytes2read).arrayBuffer();
|
| 41 |
+
buffer.set(new Uint8Array(arrayBuffer));
|
| 42 |
+
return bytes2read;
|
| 43 |
+
}
|
| 44 |
+
close() {
|
| 45 |
+
return super.close();
|
| 46 |
+
}
|
| 47 |
+
supportsRandomAccess() {
|
| 48 |
+
return true;
|
| 49 |
+
}
|
| 50 |
+
setPosition(position) {
|
| 51 |
+
this.position = position;
|
| 52 |
+
}
|
| 53 |
+
}
|
node_modules/strtok3/lib/BufferTokenizer.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { ITokenizerOptions, IReadChunkOptions, IRandomAccessFileInfo, IRandomAccessTokenizer } from './types.js';
|
| 2 |
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
| 3 |
+
export declare class BufferTokenizer extends AbstractTokenizer implements IRandomAccessTokenizer {
|
| 4 |
+
private uint8Array;
|
| 5 |
+
fileInfo: IRandomAccessFileInfo;
|
| 6 |
+
/**
|
| 7 |
+
* Construct BufferTokenizer
|
| 8 |
+
* @param uint8Array - Uint8Array to tokenize
|
| 9 |
+
* @param options Tokenizer options
|
| 10 |
+
*/
|
| 11 |
+
constructor(uint8Array: Uint8Array, options?: ITokenizerOptions);
|
| 12 |
+
/**
|
| 13 |
+
* Read buffer from tokenizer
|
| 14 |
+
* @param uint8Array - Uint8Array to tokenize
|
| 15 |
+
* @param options - Read behaviour options
|
| 16 |
+
* @returns {Promise<number>}
|
| 17 |
+
*/
|
| 18 |
+
readBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 19 |
+
/**
|
| 20 |
+
* Peek (read ahead) buffer from tokenizer
|
| 21 |
+
* @param uint8Array
|
| 22 |
+
* @param options - Read behaviour options
|
| 23 |
+
* @returns {Promise<number>}
|
| 24 |
+
*/
|
| 25 |
+
peekBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 26 |
+
close(): Promise<void>;
|
| 27 |
+
supportsRandomAccess(): boolean;
|
| 28 |
+
setPosition(position: number): void;
|
| 29 |
+
}
|
node_modules/strtok3/lib/BufferTokenizer.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { EndOfStreamError } from './stream/index.js';
|
| 2 |
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
| 3 |
+
export class BufferTokenizer extends AbstractTokenizer {
|
| 4 |
+
/**
|
| 5 |
+
* Construct BufferTokenizer
|
| 6 |
+
* @param uint8Array - Uint8Array to tokenize
|
| 7 |
+
* @param options Tokenizer options
|
| 8 |
+
*/
|
| 9 |
+
constructor(uint8Array, options) {
|
| 10 |
+
super(options);
|
| 11 |
+
this.uint8Array = uint8Array;
|
| 12 |
+
this.fileInfo = { ...options?.fileInfo ?? {}, ...{ size: uint8Array.length } };
|
| 13 |
+
}
|
| 14 |
+
/**
|
| 15 |
+
* Read buffer from tokenizer
|
| 16 |
+
* @param uint8Array - Uint8Array to tokenize
|
| 17 |
+
* @param options - Read behaviour options
|
| 18 |
+
* @returns {Promise<number>}
|
| 19 |
+
*/
|
| 20 |
+
async readBuffer(uint8Array, options) {
|
| 21 |
+
if (options?.position) {
|
| 22 |
+
this.position = options.position;
|
| 23 |
+
}
|
| 24 |
+
const bytesRead = await this.peekBuffer(uint8Array, options);
|
| 25 |
+
this.position += bytesRead;
|
| 26 |
+
return bytesRead;
|
| 27 |
+
}
|
| 28 |
+
/**
|
| 29 |
+
* Peek (read ahead) buffer from tokenizer
|
| 30 |
+
* @param uint8Array
|
| 31 |
+
* @param options - Read behaviour options
|
| 32 |
+
* @returns {Promise<number>}
|
| 33 |
+
*/
|
| 34 |
+
async peekBuffer(uint8Array, options) {
|
| 35 |
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
| 36 |
+
const bytes2read = Math.min(this.uint8Array.length - normOptions.position, normOptions.length);
|
| 37 |
+
if ((!normOptions.mayBeLess) && bytes2read < normOptions.length) {
|
| 38 |
+
throw new EndOfStreamError();
|
| 39 |
+
}
|
| 40 |
+
uint8Array.set(this.uint8Array.subarray(normOptions.position, normOptions.position + bytes2read));
|
| 41 |
+
return bytes2read;
|
| 42 |
+
}
|
| 43 |
+
close() {
|
| 44 |
+
return super.close();
|
| 45 |
+
}
|
| 46 |
+
supportsRandomAccess() {
|
| 47 |
+
return true;
|
| 48 |
+
}
|
| 49 |
+
setPosition(position) {
|
| 50 |
+
this.position = position;
|
| 51 |
+
}
|
| 52 |
+
}
|
node_modules/strtok3/lib/FileTokenizer.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
| 2 |
+
import type { IRandomAccessTokenizer, IRandomAccessFileInfo, IReadChunkOptions, ITokenizerOptions } from './types.js';
|
| 3 |
+
import { type FileHandle } from 'node:fs/promises';
|
| 4 |
+
interface IFileTokenizerOptions extends ITokenizerOptions {
|
| 5 |
+
/**
|
| 6 |
+
* Pass additional file information to the tokenizer
|
| 7 |
+
*/
|
| 8 |
+
fileInfo: IRandomAccessFileInfo;
|
| 9 |
+
}
|
| 10 |
+
export declare class FileTokenizer extends AbstractTokenizer implements IRandomAccessTokenizer {
|
| 11 |
+
private fileHandle;
|
| 12 |
+
fileInfo: IRandomAccessFileInfo;
|
| 13 |
+
/**
|
| 14 |
+
* Create tokenizer from provided file path
|
| 15 |
+
* @param sourceFilePath File path
|
| 16 |
+
*/
|
| 17 |
+
static fromFile(sourceFilePath: string): Promise<FileTokenizer>;
|
| 18 |
+
protected constructor(fileHandle: FileHandle, options: IFileTokenizerOptions);
|
| 19 |
+
/**
|
| 20 |
+
* Read buffer from file
|
| 21 |
+
* @param uint8Array - Uint8Array to write result to
|
| 22 |
+
* @param options - Read behaviour options
|
| 23 |
+
* @returns Promise number of bytes read
|
| 24 |
+
*/
|
| 25 |
+
readBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 26 |
+
/**
|
| 27 |
+
* Peek buffer from file
|
| 28 |
+
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
| 29 |
+
* @param options - Read behaviour options
|
| 30 |
+
* @returns Promise number of bytes read
|
| 31 |
+
*/
|
| 32 |
+
peekBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 33 |
+
close(): Promise<void>;
|
| 34 |
+
setPosition(position: number): void;
|
| 35 |
+
supportsRandomAccess(): boolean;
|
| 36 |
+
}
|
| 37 |
+
export {};
|
node_modules/strtok3/lib/FileTokenizer.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
| 2 |
+
import { EndOfStreamError } from './stream/index.js';
|
| 3 |
+
import { open as fsOpen } from 'node:fs/promises';
|
| 4 |
+
export class FileTokenizer extends AbstractTokenizer {
|
| 5 |
+
/**
|
| 6 |
+
* Create tokenizer from provided file path
|
| 7 |
+
* @param sourceFilePath File path
|
| 8 |
+
*/
|
| 9 |
+
static async fromFile(sourceFilePath) {
|
| 10 |
+
const fileHandle = await fsOpen(sourceFilePath, 'r');
|
| 11 |
+
const stat = await fileHandle.stat();
|
| 12 |
+
return new FileTokenizer(fileHandle, { fileInfo: { path: sourceFilePath, size: stat.size } });
|
| 13 |
+
}
|
| 14 |
+
constructor(fileHandle, options) {
|
| 15 |
+
super(options);
|
| 16 |
+
this.fileHandle = fileHandle;
|
| 17 |
+
this.fileInfo = options.fileInfo;
|
| 18 |
+
}
|
| 19 |
+
/**
|
| 20 |
+
* Read buffer from file
|
| 21 |
+
* @param uint8Array - Uint8Array to write result to
|
| 22 |
+
* @param options - Read behaviour options
|
| 23 |
+
* @returns Promise number of bytes read
|
| 24 |
+
*/
|
| 25 |
+
async readBuffer(uint8Array, options) {
|
| 26 |
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
| 27 |
+
this.position = normOptions.position;
|
| 28 |
+
if (normOptions.length === 0)
|
| 29 |
+
return 0;
|
| 30 |
+
const res = await this.fileHandle.read(uint8Array, 0, normOptions.length, normOptions.position);
|
| 31 |
+
this.position += res.bytesRead;
|
| 32 |
+
if (res.bytesRead < normOptions.length && (!options || !options.mayBeLess)) {
|
| 33 |
+
throw new EndOfStreamError();
|
| 34 |
+
}
|
| 35 |
+
return res.bytesRead;
|
| 36 |
+
}
|
| 37 |
+
/**
|
| 38 |
+
* Peek buffer from file
|
| 39 |
+
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
| 40 |
+
* @param options - Read behaviour options
|
| 41 |
+
* @returns Promise number of bytes read
|
| 42 |
+
*/
|
| 43 |
+
async peekBuffer(uint8Array, options) {
|
| 44 |
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
| 45 |
+
const res = await this.fileHandle.read(uint8Array, 0, normOptions.length, normOptions.position);
|
| 46 |
+
if ((!normOptions.mayBeLess) && res.bytesRead < normOptions.length) {
|
| 47 |
+
throw new EndOfStreamError();
|
| 48 |
+
}
|
| 49 |
+
return res.bytesRead;
|
| 50 |
+
}
|
| 51 |
+
async close() {
|
| 52 |
+
await this.fileHandle.close();
|
| 53 |
+
return super.close();
|
| 54 |
+
}
|
| 55 |
+
setPosition(position) {
|
| 56 |
+
this.position = position;
|
| 57 |
+
}
|
| 58 |
+
supportsRandomAccess() {
|
| 59 |
+
return true;
|
| 60 |
+
}
|
| 61 |
+
}
|
node_modules/strtok3/lib/ReadStreamTokenizer.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
| 2 |
+
import { type IStreamReader } from './stream/index.js';
|
| 3 |
+
import type { IFileInfo, IReadChunkOptions, ITokenizerOptions } from './types.js';
|
| 4 |
+
export declare class ReadStreamTokenizer extends AbstractTokenizer {
|
| 5 |
+
private streamReader;
|
| 6 |
+
fileInfo: IFileInfo;
|
| 7 |
+
/**
|
| 8 |
+
* Constructor
|
| 9 |
+
* @param streamReader stream-reader to read from
|
| 10 |
+
* @param options Tokenizer options
|
| 11 |
+
*/
|
| 12 |
+
constructor(streamReader: IStreamReader, options?: ITokenizerOptions);
|
| 13 |
+
/**
|
| 14 |
+
* Read buffer from tokenizer
|
| 15 |
+
* @param uint8Array - Target Uint8Array to fill with data read from the tokenizer-stream
|
| 16 |
+
* @param options - Read behaviour options
|
| 17 |
+
* @returns Promise with number of bytes read
|
| 18 |
+
*/
|
| 19 |
+
readBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 20 |
+
/**
|
| 21 |
+
* Peek (read ahead) buffer from tokenizer
|
| 22 |
+
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
| 23 |
+
* @param options - Read behaviour options
|
| 24 |
+
* @returns Promise with number of bytes peeked
|
| 25 |
+
*/
|
| 26 |
+
peekBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
| 27 |
+
/**
|
| 28 |
+
* @param length Number of bytes to ignore. Must be ≥ 0.
|
| 29 |
+
*/
|
| 30 |
+
ignore(length: number): Promise<number>;
|
| 31 |
+
abort(): Promise<void>;
|
| 32 |
+
close(): Promise<void>;
|
| 33 |
+
supportsRandomAccess(): boolean;
|
| 34 |
+
}
|
node_modules/strtok3/lib/ReadStreamTokenizer.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
| 2 |
+
import { EndOfStreamError } from './stream/index.js';
|
| 3 |
+
const maxBufferSize = 256000;
|
| 4 |
+
export class ReadStreamTokenizer extends AbstractTokenizer {
|
| 5 |
+
/**
|
| 6 |
+
* Constructor
|
| 7 |
+
* @param streamReader stream-reader to read from
|
| 8 |
+
* @param options Tokenizer options
|
| 9 |
+
*/
|
| 10 |
+
constructor(streamReader, options) {
|
| 11 |
+
super(options);
|
| 12 |
+
this.streamReader = streamReader;
|
| 13 |
+
this.fileInfo = options?.fileInfo ?? {};
|
| 14 |
+
}
|
| 15 |
+
/**
|
| 16 |
+
* Read buffer from tokenizer
|
| 17 |
+
* @param uint8Array - Target Uint8Array to fill with data read from the tokenizer-stream
|
| 18 |
+
* @param options - Read behaviour options
|
| 19 |
+
* @returns Promise with number of bytes read
|
| 20 |
+
*/
|
| 21 |
+
async readBuffer(uint8Array, options) {
|
| 22 |
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
| 23 |
+
const skipBytes = normOptions.position - this.position;
|
| 24 |
+
if (skipBytes > 0) {
|
| 25 |
+
await this.ignore(skipBytes);
|
| 26 |
+
return this.readBuffer(uint8Array, options);
|
| 27 |
+
}
|
| 28 |
+
if (skipBytes < 0) {
|
| 29 |
+
throw new Error('`options.position` must be equal or greater than `tokenizer.position`');
|
| 30 |
+
}
|
| 31 |
+
if (normOptions.length === 0) {
|
| 32 |
+
return 0;
|
| 33 |
+
}
|
| 34 |
+
const bytesRead = await this.streamReader.read(uint8Array.subarray(0, normOptions.length), normOptions.mayBeLess);
|
| 35 |
+
this.position += bytesRead;
|
| 36 |
+
if ((!options || !options.mayBeLess) && bytesRead < normOptions.length) {
|
| 37 |
+
throw new EndOfStreamError();
|
| 38 |
+
}
|
| 39 |
+
return bytesRead;
|
| 40 |
+
}
|
| 41 |
+
/**
|
| 42 |
+
* Peek (read ahead) buffer from tokenizer
|
| 43 |
+
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
| 44 |
+
* @param options - Read behaviour options
|
| 45 |
+
* @returns Promise with number of bytes peeked
|
| 46 |
+
*/
|
| 47 |
+
async peekBuffer(uint8Array, options) {
|
| 48 |
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
| 49 |
+
let bytesRead = 0;
|
| 50 |
+
if (normOptions.position) {
|
| 51 |
+
const skipBytes = normOptions.position - this.position;
|
| 52 |
+
if (skipBytes > 0) {
|
| 53 |
+
const skipBuffer = new Uint8Array(normOptions.length + skipBytes);
|
| 54 |
+
bytesRead = await this.peekBuffer(skipBuffer, { mayBeLess: normOptions.mayBeLess });
|
| 55 |
+
uint8Array.set(skipBuffer.subarray(skipBytes));
|
| 56 |
+
return bytesRead - skipBytes;
|
| 57 |
+
}
|
| 58 |
+
if (skipBytes < 0) {
|
| 59 |
+
throw new Error('Cannot peek from a negative offset in a stream');
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
if (normOptions.length > 0) {
|
| 63 |
+
try {
|
| 64 |
+
bytesRead = await this.streamReader.peek(uint8Array.subarray(0, normOptions.length), normOptions.mayBeLess);
|
| 65 |
+
}
|
| 66 |
+
catch (err) {
|
| 67 |
+
if (options?.mayBeLess && err instanceof EndOfStreamError) {
|
| 68 |
+
return 0;
|
| 69 |
+
}
|
| 70 |
+
throw err;
|
| 71 |
+
}
|
| 72 |
+
if ((!normOptions.mayBeLess) && bytesRead < normOptions.length) {
|
| 73 |
+
throw new EndOfStreamError();
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
return bytesRead;
|
| 77 |
+
}
|
| 78 |
+
/**
|
| 79 |
+
* @param length Number of bytes to ignore. Must be ≥ 0.
|
| 80 |
+
*/
|
| 81 |
+
async ignore(length) {
|
| 82 |
+
if (length < 0) {
|
| 83 |
+
throw new RangeError('ignore length must be ≥ 0 bytes');
|
| 84 |
+
}
|
| 85 |
+
const bufSize = Math.min(maxBufferSize, length);
|
| 86 |
+
const buf = new Uint8Array(bufSize);
|
| 87 |
+
let totBytesRead = 0;
|
| 88 |
+
while (totBytesRead < length) {
|
| 89 |
+
const remaining = length - totBytesRead;
|
| 90 |
+
const bytesRead = await this.readBuffer(buf, { length: Math.min(bufSize, remaining) });
|
| 91 |
+
if (bytesRead < 0) {
|
| 92 |
+
return bytesRead;
|
| 93 |
+
}
|
| 94 |
+
totBytesRead += bytesRead;
|
| 95 |
+
}
|
| 96 |
+
return totBytesRead;
|
| 97 |
+
}
|
| 98 |
+
abort() {
|
| 99 |
+
return this.streamReader.abort();
|
| 100 |
+
}
|
| 101 |
+
async close() {
|
| 102 |
+
return this.streamReader.close();
|
| 103 |
+
}
|
| 104 |
+
supportsRandomAccess() {
|
| 105 |
+
return false;
|
| 106 |
+
}
|
| 107 |
+
}
|
node_modules/strtok3/lib/core.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Readable } from 'node:stream';
|
| 2 |
+
import { type AnyWebByteStream } from './stream/index.js';
|
| 3 |
+
import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
| 4 |
+
import { BufferTokenizer } from './BufferTokenizer.js';
|
| 5 |
+
import type { ITokenizerOptions } from './types.js';
|
| 6 |
+
import { BlobTokenizer } from './BlobTokenizer.js';
|
| 7 |
+
export { EndOfStreamError, AbortError, type AnyWebByteStream } from './stream/index.js';
|
| 8 |
+
export type { ITokenizer, IRandomAccessTokenizer, IFileInfo, IRandomAccessFileInfo, ITokenizerOptions, IReadChunkOptions, OnClose } from './types.js';
|
| 9 |
+
export type { IToken, IGetToken } from '@tokenizer/token';
|
| 10 |
+
export { AbstractTokenizer } from './AbstractTokenizer.js';
|
| 11 |
+
/**
|
| 12 |
+
* Construct ReadStreamTokenizer from given Stream.
|
| 13 |
+
* Will set fileSize, if provided given Stream has set the .path property/
|
| 14 |
+
* @param stream - Read from Node.js Stream.Readable
|
| 15 |
+
* @param options - Tokenizer options
|
| 16 |
+
* @returns ReadStreamTokenizer
|
| 17 |
+
*/
|
| 18 |
+
export declare function fromStream(stream: Readable, options?: ITokenizerOptions): ReadStreamTokenizer;
|
| 19 |
+
/**
|
| 20 |
+
* Construct ReadStreamTokenizer from given ReadableStream (WebStream API).
|
| 21 |
+
* Will set fileSize, if provided given Stream has set the .path property/
|
| 22 |
+
* @param webStream - Read from Node.js Stream.Readable (must be a byte stream)
|
| 23 |
+
* @param options - Tokenizer options
|
| 24 |
+
* @returns ReadStreamTokenizer
|
| 25 |
+
*/
|
| 26 |
+
export declare function fromWebStream(webStream: AnyWebByteStream, options?: ITokenizerOptions): ReadStreamTokenizer;
|
| 27 |
+
/**
|
| 28 |
+
* Construct ReadStreamTokenizer from given Buffer.
|
| 29 |
+
* @param uint8Array - Uint8Array to tokenize
|
| 30 |
+
* @param options - Tokenizer options
|
| 31 |
+
* @returns BufferTokenizer
|
| 32 |
+
*/
|
| 33 |
+
export declare function fromBuffer(uint8Array: Uint8Array, options?: ITokenizerOptions): BufferTokenizer;
|
| 34 |
+
/**
|
| 35 |
+
* Construct ReadStreamTokenizer from given Blob.
|
| 36 |
+
* @param blob - Uint8Array to tokenize
|
| 37 |
+
* @param options - Tokenizer options
|
| 38 |
+
* @returns BufferTokenizer
|
| 39 |
+
*/
|
| 40 |
+
export declare function fromBlob(blob: Blob, options?: ITokenizerOptions): BlobTokenizer;
|
node_modules/strtok3/lib/core.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { StreamReader, makeWebStreamReader } from './stream/index.js';
|
| 2 |
+
import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
| 3 |
+
import { BufferTokenizer } from './BufferTokenizer.js';
|
| 4 |
+
import { BlobTokenizer } from './BlobTokenizer.js';
|
| 5 |
+
export { EndOfStreamError, AbortError } from './stream/index.js';
|
| 6 |
+
export { AbstractTokenizer } from './AbstractTokenizer.js';
|
| 7 |
+
/**
|
| 8 |
+
* Construct ReadStreamTokenizer from given Stream.
|
| 9 |
+
* Will set fileSize, if provided given Stream has set the .path property/
|
| 10 |
+
* @param stream - Read from Node.js Stream.Readable
|
| 11 |
+
* @param options - Tokenizer options
|
| 12 |
+
* @returns ReadStreamTokenizer
|
| 13 |
+
*/
|
| 14 |
+
export function fromStream(stream, options) {
|
| 15 |
+
const streamReader = new StreamReader(stream);
|
| 16 |
+
const _options = options ?? {};
|
| 17 |
+
const chainedClose = _options.onClose;
|
| 18 |
+
_options.onClose = async () => {
|
| 19 |
+
await streamReader.close();
|
| 20 |
+
if (chainedClose) {
|
| 21 |
+
return chainedClose();
|
| 22 |
+
}
|
| 23 |
+
};
|
| 24 |
+
return new ReadStreamTokenizer(streamReader, _options);
|
| 25 |
+
}
|
| 26 |
+
/**
|
| 27 |
+
* Construct ReadStreamTokenizer from given ReadableStream (WebStream API).
|
| 28 |
+
* Will set fileSize, if provided given Stream has set the .path property/
|
| 29 |
+
* @param webStream - Read from Node.js Stream.Readable (must be a byte stream)
|
| 30 |
+
* @param options - Tokenizer options
|
| 31 |
+
* @returns ReadStreamTokenizer
|
| 32 |
+
*/
|
| 33 |
+
export function fromWebStream(webStream, options) {
|
| 34 |
+
const webStreamReader = makeWebStreamReader(webStream);
|
| 35 |
+
const _options = options ?? {};
|
| 36 |
+
const chainedClose = _options.onClose;
|
| 37 |
+
_options.onClose = async () => {
|
| 38 |
+
await webStreamReader.close();
|
| 39 |
+
if (chainedClose) {
|
| 40 |
+
return chainedClose();
|
| 41 |
+
}
|
| 42 |
+
};
|
| 43 |
+
return new ReadStreamTokenizer(webStreamReader, _options);
|
| 44 |
+
}
|
| 45 |
+
/**
|
| 46 |
+
* Construct ReadStreamTokenizer from given Buffer.
|
| 47 |
+
* @param uint8Array - Uint8Array to tokenize
|
| 48 |
+
* @param options - Tokenizer options
|
| 49 |
+
* @returns BufferTokenizer
|
| 50 |
+
*/
|
| 51 |
+
export function fromBuffer(uint8Array, options) {
|
| 52 |
+
return new BufferTokenizer(uint8Array, options);
|
| 53 |
+
}
|
| 54 |
+
/**
|
| 55 |
+
* Construct ReadStreamTokenizer from given Blob.
|
| 56 |
+
* @param blob - Uint8Array to tokenize
|
| 57 |
+
* @param options - Tokenizer options
|
| 58 |
+
* @returns BufferTokenizer
|
| 59 |
+
*/
|
| 60 |
+
export function fromBlob(blob, options) {
|
| 61 |
+
return new BlobTokenizer(blob, options);
|
| 62 |
+
}
|
node_modules/strtok3/lib/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Readable } from 'node:stream';
|
| 2 |
+
import type { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
| 3 |
+
import { type ITokenizerOptions } from './core.js';
|
| 4 |
+
import { FileTokenizer } from "./FileTokenizer.js";
|
| 5 |
+
export { FileTokenizer } from './FileTokenizer.js';
|
| 6 |
+
export * from './core.js';
|
| 7 |
+
export type { IToken, IGetToken } from '@tokenizer/token';
|
| 8 |
+
/**
|
| 9 |
+
* Construct ReadStreamTokenizer from given Stream.
|
| 10 |
+
* Will set fileSize, if provided given Stream has set the .path property.
|
| 11 |
+
* @param stream - Node.js Stream.Readable
|
| 12 |
+
* @param options - Pass additional file information to the tokenizer
|
| 13 |
+
* @returns Tokenizer
|
| 14 |
+
*/
|
| 15 |
+
export declare function fromStream(stream: Readable, options?: ITokenizerOptions): Promise<ReadStreamTokenizer>;
|
| 16 |
+
export declare const fromFile: typeof FileTokenizer.fromFile;
|
node_modules/strtok3/lib/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { stat as fsStat } from 'node:fs/promises';
|
| 2 |
+
import { fromStream as coreFromStream } from './core.js';
|
| 3 |
+
import { FileTokenizer } from "./FileTokenizer.js";
|
| 4 |
+
export { FileTokenizer } from './FileTokenizer.js';
|
| 5 |
+
export * from './core.js';
|
| 6 |
+
/**
|
| 7 |
+
* Construct ReadStreamTokenizer from given Stream.
|
| 8 |
+
* Will set fileSize, if provided given Stream has set the .path property.
|
| 9 |
+
* @param stream - Node.js Stream.Readable
|
| 10 |
+
* @param options - Pass additional file information to the tokenizer
|
| 11 |
+
* @returns Tokenizer
|
| 12 |
+
*/
|
| 13 |
+
export async function fromStream(stream, options) {
|
| 14 |
+
const rst = coreFromStream(stream, options);
|
| 15 |
+
if (stream.path) {
|
| 16 |
+
const stat = await fsStat(stream.path);
|
| 17 |
+
rst.fileInfo.path = stream.path;
|
| 18 |
+
rst.fileInfo.size = stat.size;
|
| 19 |
+
}
|
| 20 |
+
return rst;
|
| 21 |
+
}
|
| 22 |
+
export const fromFile = FileTokenizer.fromFile;
|
node_modules/strtok3/lib/stream/AbstractStreamReader.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export interface IStreamReader {
|
| 2 |
+
/**
|
| 3 |
+
* Peak ahead (peek) from stream. Subsequent read or peeks will return the same data.
|
| 4 |
+
* @param uint8Array - Uint8Array (or Buffer) to store data read from stream in
|
| 5 |
+
* @param mayBeLess - Allow the read to complete, without the buffer being fully filled (length may be smaller)
|
| 6 |
+
* @returns Number of bytes peeked. If `maybeLess` is set, this shall be the `uint8Array.length`.
|
| 7 |
+
*/
|
| 8 |
+
peek(uint8Array: Uint8Array, mayBeLess?: boolean): Promise<number>;
|
| 9 |
+
/**
|
| 10 |
+
* Read from stream the stream.
|
| 11 |
+
* @param uint8Array - Uint8Array (or Buffer) to store data read from stream in
|
| 12 |
+
* @param mayBeLess - Allow the read to complete, without the buffer being fully filled (length may be smaller)
|
| 13 |
+
* @returns Number of actually bytes read. If `maybeLess` is set, this shall be the `uint8Array.length`.
|
| 14 |
+
*/
|
| 15 |
+
read(uint8Array: Uint8Array, mayBeLess?: boolean): Promise<number>;
|
| 16 |
+
close(): Promise<void>;
|
| 17 |
+
/**
|
| 18 |
+
* Abort any active asynchronous operation are active, abort those before they may have completed.
|
| 19 |
+
*/
|
| 20 |
+
abort(): Promise<void>;
|
| 21 |
+
}
|
| 22 |
+
export declare abstract class AbstractStreamReader implements IStreamReader {
|
| 23 |
+
protected endOfStream: boolean;
|
| 24 |
+
protected interrupted: boolean;
|
| 25 |
+
/**
|
| 26 |
+
* Store peeked data
|
| 27 |
+
* @type {Array}
|
| 28 |
+
*/
|
| 29 |
+
protected peekQueue: Uint8Array[];
|
| 30 |
+
peek(uint8Array: Uint8Array, mayBeLess?: boolean): Promise<number>;
|
| 31 |
+
read(buffer: Uint8Array, mayBeLess?: boolean): Promise<number>;
|
| 32 |
+
/**
|
| 33 |
+
* Read chunk from stream
|
| 34 |
+
* @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
|
| 35 |
+
* @returns Number of bytes read
|
| 36 |
+
*/
|
| 37 |
+
protected readFromPeekBuffer(buffer: Uint8Array): number;
|
| 38 |
+
readRemainderFromStream(buffer: Uint8Array, mayBeLess: boolean): Promise<number>;
|
| 39 |
+
/**
|
| 40 |
+
* Read from stream
|
| 41 |
+
* @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
|
| 42 |
+
* @param mayBeLess - If true, may fill the buffer partially
|
| 43 |
+
* @protected Bytes read
|
| 44 |
+
*/
|
| 45 |
+
protected abstract readFromStream(buffer: Uint8Array, mayBeLess: boolean): Promise<number>;
|
| 46 |
+
/**
|
| 47 |
+
* abort synchronous operations
|
| 48 |
+
*/
|
| 49 |
+
abstract close(): Promise<void>;
|
| 50 |
+
/**
|
| 51 |
+
* Abort any active asynchronous operation are active, abort those before they may have completed.
|
| 52 |
+
*/
|
| 53 |
+
abstract abort(): Promise<void>;
|
| 54 |
+
}
|
node_modules/strtok3/lib/stream/AbstractStreamReader.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { EndOfStreamError, AbortError } from "./Errors.js";
|
| 2 |
+
export class AbstractStreamReader {
|
| 3 |
+
constructor() {
|
| 4 |
+
this.endOfStream = false;
|
| 5 |
+
this.interrupted = false;
|
| 6 |
+
/**
|
| 7 |
+
* Store peeked data
|
| 8 |
+
* @type {Array}
|
| 9 |
+
*/
|
| 10 |
+
this.peekQueue = [];
|
| 11 |
+
}
|
| 12 |
+
async peek(uint8Array, mayBeLess = false) {
|
| 13 |
+
const bytesRead = await this.read(uint8Array, mayBeLess);
|
| 14 |
+
this.peekQueue.push(uint8Array.subarray(0, bytesRead)); // Put read data back to peek buffer
|
| 15 |
+
return bytesRead;
|
| 16 |
+
}
|
| 17 |
+
async read(buffer, mayBeLess = false) {
|
| 18 |
+
if (buffer.length === 0) {
|
| 19 |
+
return 0;
|
| 20 |
+
}
|
| 21 |
+
let bytesRead = this.readFromPeekBuffer(buffer);
|
| 22 |
+
if (!this.endOfStream) {
|
| 23 |
+
bytesRead += await this.readRemainderFromStream(buffer.subarray(bytesRead), mayBeLess);
|
| 24 |
+
}
|
| 25 |
+
if (bytesRead === 0 && !mayBeLess) {
|
| 26 |
+
throw new EndOfStreamError();
|
| 27 |
+
}
|
| 28 |
+
return bytesRead;
|
| 29 |
+
}
|
| 30 |
+
/**
|
| 31 |
+
* Read chunk from stream
|
| 32 |
+
* @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
|
| 33 |
+
* @returns Number of bytes read
|
| 34 |
+
*/
|
| 35 |
+
readFromPeekBuffer(buffer) {
|
| 36 |
+
let remaining = buffer.length;
|
| 37 |
+
let bytesRead = 0;
|
| 38 |
+
// consume peeked data first
|
| 39 |
+
while (this.peekQueue.length > 0 && remaining > 0) {
|
| 40 |
+
const peekData = this.peekQueue.pop(); // Front of queue
|
| 41 |
+
if (!peekData)
|
| 42 |
+
throw new Error('peekData should be defined');
|
| 43 |
+
const lenCopy = Math.min(peekData.length, remaining);
|
| 44 |
+
buffer.set(peekData.subarray(0, lenCopy), bytesRead);
|
| 45 |
+
bytesRead += lenCopy;
|
| 46 |
+
remaining -= lenCopy;
|
| 47 |
+
if (lenCopy < peekData.length) {
|
| 48 |
+
// remainder back to queue
|
| 49 |
+
this.peekQueue.push(peekData.subarray(lenCopy));
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
return bytesRead;
|
| 53 |
+
}
|
| 54 |
+
async readRemainderFromStream(buffer, mayBeLess) {
|
| 55 |
+
let bytesRead = 0;
|
| 56 |
+
// Continue reading from stream if required
|
| 57 |
+
while (bytesRead < buffer.length && !this.endOfStream) {
|
| 58 |
+
if (this.interrupted) {
|
| 59 |
+
throw new AbortError();
|
| 60 |
+
}
|
| 61 |
+
const chunkLen = await this.readFromStream(buffer.subarray(bytesRead), mayBeLess);
|
| 62 |
+
if (chunkLen === 0)
|
| 63 |
+
break;
|
| 64 |
+
bytesRead += chunkLen;
|
| 65 |
+
}
|
| 66 |
+
if (!mayBeLess && bytesRead < buffer.length) {
|
| 67 |
+
throw new EndOfStreamError();
|
| 68 |
+
}
|
| 69 |
+
return bytesRead;
|
| 70 |
+
}
|
| 71 |
+
}
|
node_modules/strtok3/lib/stream/Deferred.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export declare class Deferred<T> {
|
| 2 |
+
promise: Promise<T>;
|
| 3 |
+
resolve: (value: T) => void;
|
| 4 |
+
reject: (reason: Error) => void;
|
| 5 |
+
constructor();
|
| 6 |
+
}
|
node_modules/strtok3/lib/stream/Deferred.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export class Deferred {
|
| 2 |
+
constructor() {
|
| 3 |
+
this.resolve = () => null;
|
| 4 |
+
this.reject = () => null;
|
| 5 |
+
this.promise = new Promise((resolve, reject) => {
|
| 6 |
+
this.reject = reject;
|
| 7 |
+
this.resolve = resolve;
|
| 8 |
+
});
|
| 9 |
+
}
|
| 10 |
+
}
|
node_modules/strtok3/lib/stream/Errors.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export declare const defaultMessages = "End-Of-Stream";
|
| 2 |
+
/**
|
| 3 |
+
* Thrown on read operation of the end of file or stream has been reached
|
| 4 |
+
*/
|
| 5 |
+
export declare class EndOfStreamError extends Error {
|
| 6 |
+
constructor();
|
| 7 |
+
}
|
| 8 |
+
export declare class AbortError extends Error {
|
| 9 |
+
constructor(message?: string);
|
| 10 |
+
}
|
node_modules/strtok3/lib/stream/Errors.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export const defaultMessages = 'End-Of-Stream';
|
| 2 |
+
/**
|
| 3 |
+
* Thrown on read operation of the end of file or stream has been reached
|
| 4 |
+
*/
|
| 5 |
+
export class EndOfStreamError extends Error {
|
| 6 |
+
constructor() {
|
| 7 |
+
super(defaultMessages);
|
| 8 |
+
this.name = "EndOfStreamError";
|
| 9 |
+
}
|
| 10 |
+
}
|
| 11 |
+
export class AbortError extends Error {
|
| 12 |
+
constructor(message = "The operation was aborted") {
|
| 13 |
+
super(message);
|
| 14 |
+
this.name = "AbortError";
|
| 15 |
+
}
|
| 16 |
+
}
|
node_modules/strtok3/lib/stream/StreamReader.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Readable } from 'node:stream';
|
| 2 |
+
import { AbstractStreamReader } from "./AbstractStreamReader.js";
|
| 3 |
+
/**
|
| 4 |
+
* Node.js Readable Stream Reader
|
| 5 |
+
* Ref: https://nodejs.org/api/stream.html#readable-streams
|
| 6 |
+
*/
|
| 7 |
+
export declare class StreamReader extends AbstractStreamReader {
|
| 8 |
+
private s;
|
| 9 |
+
/**
|
| 10 |
+
* Deferred used for postponed read request (as not data is yet available to read)
|
| 11 |
+
*/
|
| 12 |
+
private deferred;
|
| 13 |
+
constructor(s: Readable);
|
| 14 |
+
/**
|
| 15 |
+
* Read chunk from stream
|
| 16 |
+
* @param buffer Target Uint8Array (or Buffer) to store data read from stream in
|
| 17 |
+
* @param mayBeLess - If true, may fill the buffer partially
|
| 18 |
+
* @returns Number of bytes read
|
| 19 |
+
*/
|
| 20 |
+
protected readFromStream(buffer: Uint8Array, mayBeLess: boolean): Promise<number>;
|
| 21 |
+
/**
|
| 22 |
+
* Process deferred read request
|
| 23 |
+
* @param request Deferred read request
|
| 24 |
+
*/
|
| 25 |
+
private readDeferred;
|
| 26 |
+
private reject;
|
| 27 |
+
abort(): Promise<void>;
|
| 28 |
+
close(): Promise<void>;
|
| 29 |
+
}
|
node_modules/strtok3/lib/stream/StreamReader.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AbortError, } from './Errors.js';
|
| 2 |
+
import { Deferred } from './Deferred.js';
|
| 3 |
+
import { AbstractStreamReader } from "./AbstractStreamReader.js";
|
| 4 |
+
/**
|
| 5 |
+
* Node.js Readable Stream Reader
|
| 6 |
+
* Ref: https://nodejs.org/api/stream.html#readable-streams
|
| 7 |
+
*/
|
| 8 |
+
export class StreamReader extends AbstractStreamReader {
|
| 9 |
+
constructor(s) {
|
| 10 |
+
super();
|
| 11 |
+
this.s = s;
|
| 12 |
+
/**
|
| 13 |
+
* Deferred used for postponed read request (as not data is yet available to read)
|
| 14 |
+
*/
|
| 15 |
+
this.deferred = null;
|
| 16 |
+
if (!s.read || !s.once) {
|
| 17 |
+
throw new Error('Expected an instance of stream.Readable');
|
| 18 |
+
}
|
| 19 |
+
this.s.once('end', () => {
|
| 20 |
+
this.endOfStream = true;
|
| 21 |
+
if (this.deferred) {
|
| 22 |
+
this.deferred.resolve(0);
|
| 23 |
+
}
|
| 24 |
+
});
|
| 25 |
+
this.s.once('error', err => this.reject(err));
|
| 26 |
+
this.s.once('close', () => this.abort());
|
| 27 |
+
}
|
| 28 |
+
/**
|
| 29 |
+
* Read chunk from stream
|
| 30 |
+
* @param buffer Target Uint8Array (or Buffer) to store data read from stream in
|
| 31 |
+
* @param mayBeLess - If true, may fill the buffer partially
|
| 32 |
+
* @returns Number of bytes read
|
| 33 |
+
*/
|
| 34 |
+
async readFromStream(buffer, mayBeLess) {
|
| 35 |
+
if (buffer.length === 0)
|
| 36 |
+
return 0;
|
| 37 |
+
const readBuffer = this.s.read(buffer.length);
|
| 38 |
+
if (readBuffer) {
|
| 39 |
+
buffer.set(readBuffer);
|
| 40 |
+
return readBuffer.length;
|
| 41 |
+
}
|
| 42 |
+
const request = {
|
| 43 |
+
buffer,
|
| 44 |
+
mayBeLess,
|
| 45 |
+
deferred: new Deferred()
|
| 46 |
+
};
|
| 47 |
+
this.deferred = request.deferred;
|
| 48 |
+
this.s.once('readable', () => {
|
| 49 |
+
this.readDeferred(request);
|
| 50 |
+
});
|
| 51 |
+
return request.deferred.promise;
|
| 52 |
+
}
|
| 53 |
+
/**
|
| 54 |
+
* Process deferred read request
|
| 55 |
+
* @param request Deferred read request
|
| 56 |
+
*/
|
| 57 |
+
readDeferred(request) {
|
| 58 |
+
const readBuffer = this.s.read(request.buffer.length);
|
| 59 |
+
if (readBuffer) {
|
| 60 |
+
request.buffer.set(readBuffer);
|
| 61 |
+
request.deferred.resolve(readBuffer.length);
|
| 62 |
+
this.deferred = null;
|
| 63 |
+
}
|
| 64 |
+
else {
|
| 65 |
+
this.s.once('readable', () => {
|
| 66 |
+
this.readDeferred(request);
|
| 67 |
+
});
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
reject(err) {
|
| 71 |
+
this.interrupted = true;
|
| 72 |
+
if (this.deferred) {
|
| 73 |
+
this.deferred.reject(err);
|
| 74 |
+
this.deferred = null;
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
async abort() {
|
| 78 |
+
this.reject(new AbortError());
|
| 79 |
+
}
|
| 80 |
+
async close() {
|
| 81 |
+
return this.abort();
|
| 82 |
+
}
|
| 83 |
+
}
|
node_modules/strtok3/lib/stream/WebStreamByobReader.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { WebStreamReader } from './WebStreamReader.js';
|
| 2 |
+
/**
|
| 3 |
+
* Read from a WebStream using a BYOB reader
|
| 4 |
+
* Reference: https://nodejs.org/api/webstreams.html#class-readablestreambyobreader
|
| 5 |
+
*/
|
| 6 |
+
export declare class WebStreamByobReader extends WebStreamReader {
|
| 7 |
+
/**
|
| 8 |
+
* Read from stream
|
| 9 |
+
* @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
|
| 10 |
+
* @param mayBeLess - If true, may fill the buffer partially
|
| 11 |
+
* @protected Bytes read
|
| 12 |
+
*/
|
| 13 |
+
protected readFromStream(buffer: Uint8Array, mayBeLess: boolean): Promise<number>;
|
| 14 |
+
}
|
node_modules/strtok3/lib/stream/WebStreamByobReader.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { WebStreamReader } from './WebStreamReader.js';
|
| 2 |
+
/**
|
| 3 |
+
* Read from a WebStream using a BYOB reader
|
| 4 |
+
* Reference: https://nodejs.org/api/webstreams.html#class-readablestreambyobreader
|
| 5 |
+
*/
|
| 6 |
+
export class WebStreamByobReader extends WebStreamReader {
|
| 7 |
+
/**
|
| 8 |
+
* Read from stream
|
| 9 |
+
* @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
|
| 10 |
+
* @param mayBeLess - If true, may fill the buffer partially
|
| 11 |
+
* @protected Bytes read
|
| 12 |
+
*/
|
| 13 |
+
async readFromStream(buffer, mayBeLess) {
|
| 14 |
+
if (buffer.length === 0)
|
| 15 |
+
return 0;
|
| 16 |
+
// @ts-expect-error
|
| 17 |
+
const result = await this.reader.read(new Uint8Array(buffer.length), { min: mayBeLess ? undefined : buffer.length });
|
| 18 |
+
if (result.done) {
|
| 19 |
+
this.endOfStream = result.done;
|
| 20 |
+
}
|
| 21 |
+
if (result.value) {
|
| 22 |
+
buffer.set(result.value);
|
| 23 |
+
return result.value.length;
|
| 24 |
+
}
|
| 25 |
+
return 0;
|
| 26 |
+
}
|
| 27 |
+
}
|
node_modules/strtok3/lib/stream/WebStreamDefaultReader.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AbstractStreamReader } from "./AbstractStreamReader.js";
|
| 2 |
+
export declare class WebStreamDefaultReader extends AbstractStreamReader {
|
| 3 |
+
private reader;
|
| 4 |
+
private buffer;
|
| 5 |
+
constructor(reader: ReadableStreamDefaultReader<Uint8Array>);
|
| 6 |
+
/**
|
| 7 |
+
* Copy chunk to target, and store the remainder in this.buffer
|
| 8 |
+
*/
|
| 9 |
+
private writeChunk;
|
| 10 |
+
/**
|
| 11 |
+
* Read from stream
|
| 12 |
+
* @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
|
| 13 |
+
* @param mayBeLess - If true, may fill the buffer partially
|
| 14 |
+
* @protected Bytes read
|
| 15 |
+
*/
|
| 16 |
+
protected readFromStream(buffer: Uint8Array, mayBeLess: boolean): Promise<number>;
|
| 17 |
+
abort(): Promise<void>;
|
| 18 |
+
close(): Promise<void>;
|
| 19 |
+
}
|