diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 95c7480..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-24T00:42:43.080Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cf2b727..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/streams/node/from-strided-array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a456072..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/streams/node/from-strided-array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 9e0a00c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '41 5 * * 5' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -275,7 +272,7 @@ stream.pipe( iStream ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -346,7 +343,7 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/streams/node/from-array]: https://github.com/stdlib-js/streams-node-from-array +[@stdlib/streams/node/from-array]: https://github.com/stdlib-js/streams-node-from-array/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 178e5cd..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,97 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Readable = require( 'readable-stream' ).Readable; -var bench = require( '@stdlib/bench-harness' ); -var pkg = require( './../package.json' ).name; -var stridedArrayStream = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var s; - var i; - - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s = stridedArrayStream( arr.length, arr, 1, 0 ); - if ( typeof s !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !( s instanceof Readable ) ) { - b.fail( 'should return a readable stream' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':objectMode', function benchmark( b ) { - var arr; - var s; - var i; - - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s = stridedArrayStream.objectMode( arr.length, arr, 1, 0 ); - if ( typeof s !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !( s instanceof Readable ) ) { - b.fail( 'should return a readable stream' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::factory', function benchmark( b ) { - var createStream; - var arr; - var s; - var i; - - createStream = stridedArrayStream.factory(); - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s = createStream( arr.length, arr, 1, 0 ); - if ( typeof s !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !( s instanceof Readable ) ) { - b.fail( 'should return a readable stream' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.throughput.js b/benchmark/benchmark.throughput.js deleted file mode 100644 index 8b0863f..0000000 --- a/benchmark/benchmark.throughput.js +++ /dev/null @@ -1,269 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var WritableStream = require( 'readable-stream' ).Writable; // eslint-disable-line stdlib/no-redeclare -var bench = require( '@stdlib/bench-harness' ); -var inherit = require( '@stdlib/utils-inherit' ); -var nextTick = require( '@stdlib/utils-next-tick' ); -var pkg = require( './../package.json' ).name; -var stridedArrayStream = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::throughput,baseline', function benchmark( b ) { - var i; - - i = 0; - b.tic(); - - return next(); - - function next() { - i += 1; - if ( i <= b.iterations ) { - return nextTick( onTick ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } - - function onTick() { - if ( i !== i ) { - b.fail( 'should not be NaN' ); - } - next(); - } -}); - -bench( pkg+'::throughput:highWaterMark=', function benchmark( b ) { - var rStream; - var wStream; - var opts; - var arr; - var i; - - function Writable( opts ) { - WritableStream.call( this, opts ); - return this; - } - - inherit( Writable, WritableStream ); - Writable.prototype._write = next; // eslint-disable-line no-underscore-dangle - - arr = []; - for ( i = 0; i < b.iterations; i++ ) { - arr.push( i ); - } - - // Create a source stream: - opts = {}; - rStream = stridedArrayStream( arr.length, arr, 1, 0, opts ); - - // Create a sink stream: - opts = {}; - wStream = new Writable( opts ); - - i = 0; - b.tic(); - - return pipe(); - - function pipe() { - // Begin data flow... - rStream.pipe( wStream ); - } - - function next( chunk, encoding, clbk ) { - i += 1; - if ( i < b.iterations ) { - return clbk(); - } - b.toc(); - rStream.destroy(); - - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+'::throughput:highWaterMark=0', function benchmark( b ) { - var rStream; - var wStream; - var opts; - var arr; - var i; - - function Writable( opts ) { - WritableStream.call( this, opts ); - return this; - } - - inherit( Writable, WritableStream ); - Writable.prototype._write = next; // eslint-disable-line no-underscore-dangle - - arr = []; - for ( i = 0; i < b.iterations; i++ ) { - arr.push( i ); - } - - // Create a source stream: - opts = { - 'highWaterMark': 0 - }; - rStream = stridedArrayStream( arr.length, arr, 1, 0, opts ); - - // Create a sink stream: - opts = {}; - wStream = new Writable( opts ); - - i = 0; - b.tic(); - - return pipe(); - - function pipe() { - // Begin data flow... - rStream.pipe( wStream ); - } - - function next( chunk, encoding, clbk ) { - i += 1; - if ( i < b.iterations ) { - return clbk(); - } - b.toc(); - rStream.destroy(); - - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+'::throughput,object_mode:highWaterMark=', function benchmark( b ) { - var rStream; - var wStream; - var opts; - var arr; - var i; - - function Writable( opts ) { - WritableStream.call( this, opts ); - return this; - } - - inherit( Writable, WritableStream ); - Writable.prototype._write = next; // eslint-disable-line no-underscore-dangle - - arr = []; - for ( i = 0; i < b.iterations; i++ ) { - arr.push( i ); - } - - // Create a source stream: - opts = {}; - rStream = stridedArrayStream.objectMode( arr.length, arr, 1, 0, opts ); - - // Create a sink stream: - opts = { - 'objectMode': true - }; - wStream = new Writable( opts ); - - i = 0; - b.tic(); - - return pipe(); - - function pipe() { - // Begin data flow... - rStream.pipe( wStream ); - } - - function next( chunk, encoding, clbk ) { - i += 1; - if ( i < b.iterations ) { - return clbk(); - } - b.toc(); - rStream.destroy(); - - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+'::throughput,object_mode:highWaterMark=0', function benchmark( b ) { - var rStream; - var wStream; - var opts; - var arr; - var i; - - function Writable( opts ) { - WritableStream.call( this, opts ); - return this; - } - - inherit( Writable, WritableStream ); - Writable.prototype._write = next; // eslint-disable-line no-underscore-dangle - - arr = []; - for ( i = 0; i < b.iterations; i++ ) { - arr.push( i ); - } - - // Create a source stream: - opts = { - 'highWaterMark': 0 - }; - rStream = stridedArrayStream.objectMode( arr.length, arr, 1, 0, opts ); - - // Create a sink stream: - opts = { - 'objectMode': true - }; - wStream = new Writable( opts ); - - i = 0; - b.tic(); - - return pipe(); - - function pipe() { - // Begin data flow... - rStream.pipe( wStream ); - } - - function next( chunk, encoding, clbk ) { - i += 1; - if ( i < b.iterations ) { - return clbk(); - } - b.toc(); - rStream.destroy(); - - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index f2c21d5..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/streams/node/from-strided-array" -%% click B href "https://github.com/stdlib-js/streams-node-from-strided-array/tree/main" -%% click C href "https://github.com/stdlib-js/streams-node-from-strided-array/tree/production" -%% click D href "https://github.com/stdlib-js/streams-node-from-strided-array/tree/esm" -%% click E href "https://github.com/stdlib-js/streams-node-from-strided-array/tree/deno" -%% click F href "https://github.com/stdlib-js/streams-node-from-strided-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/streams/node/from-strided-array -[production-url]: https://github.com/stdlib-js/streams-node-from-strided-array/tree/production -[deno-url]: https://github.com/stdlib-js/streams-node-from-strided-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/streams-node-from-strided-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/streams-node-from-strided-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/streams-node-from-strided-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/streams-node-from-strided-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/streams-node-from-strided-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1662a75..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import stridedArrayStream from '../docs/types/index'; -export = stridedArrayStream; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 09a36fa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=o(function(ve,F){F.exports={objectMode:!1,encoding:null,sep:"\n"}});var _=o(function(ge,w){"use strict";var N=require("@stdlib/assert-is-plain-object"),v=require("@stdlib/assert-has-own-property"),P=require("@stdlib/assert-is-boolean").isPrimitive,W=require("@stdlib/assert-is-nonnegative-number").isPrimitive,p=require("@stdlib/assert-is-string").isPrimitive,A=require("@stdlib/assert-is-function"),d=require("@stdlib/string-format");function R(e,r){return N(r)?v(r,"sep")&&(e.sep=r.sep,!p(e.sep))?new TypeError(d("invalid option. `%s` option must be a string. Option: `%s`.","sep",e.sep)):v(r,"objectMode")&&(e.objectMode=r.objectMode,!P(e.objectMode))?new TypeError(d("invalid option. `%s` option must be a boolean. Option: `%s`.","objectMode",e.objectMode)):v(r,"encoding")&&(e.encoding=r.encoding,!p(e.encoding)&&e.encoding!==null)?new TypeError(d("invalid option. `%s` option must be a string or null. Option: `%s`.","encoding",e.encoding)):v(r,"highWaterMark")&&(e.highWaterMark=r.highWaterMark,!W(e.highWaterMark))?new TypeError(d("invalid option. `%s` option must be a nonnegative number. Option: `%s`.","highWaterMark",e.highWaterMark)):v(r,"serialize")&&(e.serialize=r.serialize,!A(e.serialize))?new TypeError(d("invalid option. `%s` option must be a function. Option: `%s`.","serialize",e.serialize)):null:new TypeError(d("invalid argument. Options argument must be an object. Value: `%s`.",r))}w.exports=R});var M=o(function(ce,j){"use strict";var B=require("debug"),I=B("from-strided-array-stream");j.exports=I});var c=o(function(me,S){"use strict";var O=require("readable-stream").Readable,J=require("@stdlib/assert-is-collection"),C=require("@stdlib/assert-is-error"),L=require("@stdlib/assert-is-buffer"),D=require("@stdlib/assert-is-integer").isPrimitive,E=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,G=require("@stdlib/object-assign"),U=require("@stdlib/utils-inherit"),f=require("@stdlib/utils-define-nonenumerable-property"),n=require("@stdlib/utils-define-nonenumerable-read-only-property"),b=require("@stdlib/buffer-from-string"),H=require("@stdlib/buffer-ctor"),g=require("@stdlib/string-format"),K=require("@stdlib/utils-next-tick"),Q=q(),X=_(),l=M();function Y(){var e,r,i;if(!this._destroyed)for(e=!0;e;){if(r=null,this._i+=1,this._i>this._N)return l("Finished iteration."),this.push(null);i=this._buffer[this._idx],l("Value: %s. Idx: %d. Iter: %d.",JSON.stringify(i),this._idx,this._i),this._idx+=this._stride,this._objectMode===!1&&(i=this._serialize(i),typeof i=="string"?this._i===1?i=b(i):i=b(this._sep+i):L(i)?this._i>1&&(i=H.concat([b(this._sep),i])):r=new Error(g("invalid operation. Serialization function must return a string or Buffer. Value: `%s`.",i))),r?this.emit("error",r):e=this.push(i)}}function Z(e){var r;if(this._destroyed)return l("Attempted to destroy an already destroyed stream."),this;return r=this,this._destroyed=!0,K(i),this;function i(){e&&(l("Stream was destroyed due to an error. Error: %s.",C(e)?e.message:JSON.stringify(e)),r.emit("error",e)),l("Closing the stream..."),r.emit("close")}}function u(e,r,i,a,s){var t,h,m;if(!(this instanceof u))return arguments.length>4?new u(e,r,i,a,s):new u(e,r,i,a);if(!E(e))throw new TypeError(g("invalid argument. First argument must be a nonnegative integer. Value: `%s`.",e));if(!J(r))throw new TypeError(g("invalid argument. Second argument must be an array-like object. Value: `%s`.",r));if(!D(i))throw new TypeError(g("invalid argument. Third argument must be an integer. Value: `%s`.",i));if(!E(a))throw new TypeError(g("invalid argument. Fourth argument must be a nonnegative integer. Value: `%s`.",a));if(e>0&&(m=a+(e-1)*i,a>=r.length||m<0||m>=r.length))throw new RangeError("invalid arguments. Strided array parameters are incompatible with the provided array-like object. Linear index exceeds array bounds.");if(t=G({},Q),arguments.length>4&&(h=X(t,s),h))throw h;return l("Creating a readable stream configured with the following options: %s.",JSON.stringify(t)),O.call(this,t),f(this,"_destroyed",!1),n(this,"_objectMode",t.objectMode),n(this,"_sep",t.sep),n(this,"_serialize",t.serialize||JSON.stringify),n(this,"_buffer",r),n(this,"_N",e),n(this,"_stride",i),n(this,"_offset",a),f(this,"_idx",a),f(this,"_i",0),this}U(u,O);n(u.prototype,"_read",Y);n(u.prototype,"destroy",Z);S.exports=u});var x=o(function(fe,T){"use strict";var $=require("@stdlib/assert-is-plain-object"),ee=require("@stdlib/string-format"),re=require("@stdlib/object-assign"),ie=c();function te(e,r,i,a,s){var t;if(arguments.length>4){if(t=s,!$(t))throw new TypeError(ee("invalid argument. Options argument must be an object. Value: `%s`.",t));t=re({},s)}else t={};return t.objectMode=!0,new ie(e,r,i,a,t)}T.exports=te});var k=o(function(be,z){"use strict";var ae=require("@stdlib/assert-is-plain-object"),ne=require("@stdlib/string-format"),se=require("@stdlib/object-assign"),ue=c();function oe(e){var r;if(arguments.length){if(!ae(e))throw new TypeError(ne("invalid argument. Options argument must be an object. Value: `%s`.",e));r=se({},e)}else r={};return i;function i(a,s,t,h){return new ue(a,s,t,h,r)}}z.exports=oe});var V=require("@stdlib/utils-define-nonenumerable-read-only-property"),y=c(),de=x(),le=k();V(y,"objectMode",de);V(y,"factory",le);module.exports=y; -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 8386ee7..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/defaults.json", "../lib/validate.js", "../lib/debug.js", "../lib/main.js", "../lib/object_mode.js", "../lib/factory.js", "../lib/index.js"], - "sourcesContent": ["{\n\t\"objectMode\": false,\n\t\"encoding\": null,\n\t\"sep\": \"\\n\"\n}\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isNonNegative = require( '@stdlib/assert-is-nonnegative-number' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {string} [options.sep] - separator used to join streamed data\n* @param {boolean} [options.objectMode] - specifies whether a stream should operate in object mode\n* @param {(string|null)} [options.encoding] - specifies how `Buffer` objects should be decoded to `strings`\n* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of bytes to store in the internal buffer before pausing streaming\n* @param {Function} [options.serialize] - custom serialization function\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'objectMode': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'objectMode' ) ) {\n\t\topts.objectMode = options.objectMode;\n\t\tif ( !isBoolean( opts.objectMode ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'objectMode', opts.objectMode ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'encoding' ) ) {\n\t\topts.encoding = options.encoding;\n\t\tif ( !isString( opts.encoding ) && opts.encoding !== null ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string or null. Option: `%s`.', 'encoding', opts.encoding ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegative( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a nonnegative number. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'serialize' ) ) {\n\t\topts.serialize = options.serialize;\n\t\tif ( !isFunction( opts.serialize ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a function. Option: `%s`.', 'serialize', opts.serialize ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar logger = require( 'debug' );\n\n\n// MAIN //\n\nvar debug = logger( 'from-strided-array-stream' );\n\n\n// EXPORTS //\n\nmodule.exports = debug;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar Readable = require( 'readable-stream' ).Readable;\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar assign = require( '@stdlib/object-assign' );\nvar inherit = require( '@stdlib/utils-inherit' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar string2buffer = require( '@stdlib/buffer-from-string' );\nvar Buffer = require( '@stdlib/buffer-ctor' ); // TODO: replace Buffer.concat usage with stdlib pkg\nvar format = require( '@stdlib/string-format' );\nvar nextTick = require( '@stdlib/utils-next-tick' );\nvar DEFAULTS = require( './defaults.json' );\nvar validate = require( './validate.js' );\nvar debug = require( './debug.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Implements the `_read` method.\n*\n* @private\n* @param {number} size - number (of bytes) to read\n* @returns {void}\n*/\nfunction read() {\n\t/* eslint-disable no-invalid-this */\n\tvar FLG;\n\tvar err;\n\tvar v;\n\n\tif ( this._destroyed ) {\n\t\treturn;\n\t}\n\tFLG = true;\n\twhile ( FLG ) {\n\t\terr = null;\n\n\t\tthis._i += 1;\n\t\tif ( this._i > this._N ) {\n\t\t\tdebug( 'Finished iteration.' );\n\t\t\treturn this.push( null );\n\t\t}\n\t\tv = this._buffer[ this._idx ];\n\t\tdebug( 'Value: %s. Idx: %d. Iter: %d.', JSON.stringify( v ), this._idx, this._i );\n\n\t\tthis._idx += this._stride;\n\t\tif ( this._objectMode === false ) {\n\t\t\tv = this._serialize( v );\n\t\t\tif ( typeof v === 'string' ) {\n\t\t\t\tif ( this._i === 1 ) {\n\t\t\t\t\tv = string2buffer( v );\n\t\t\t\t} else {\n\t\t\t\t\tv = string2buffer( this._sep+v );\n\t\t\t\t}\n\t\t\t} else if ( isBuffer( v ) ) {\n\t\t\t\tif ( this._i > 1 ) {\n\t\t\t\t\tv = Buffer.concat( [ string2buffer( this._sep ), v ] );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\terr = new Error( format( 'invalid operation. Serialization function must return a string or Buffer. Value: `%s`.', v ) );\n\t\t\t}\n\t\t}\n\t\tif ( err ) {\n\t\t\tthis.emit( 'error', err );\n\t\t} else {\n\t\t\tFLG = this.push( v );\n\t\t}\n\t}\n\n\t/* eslint-enable no-invalid-this */\n}\n\n/**\n* Gracefully destroys a stream, providing backward compatibility.\n*\n* @private\n* @param {(string|Object|Error)} [error] - error\n* @returns {StridedArrayStream} Stream instance\n*/\nfunction destroy( error ) {\n\t/* eslint-disable no-invalid-this */\n\tvar self;\n\tif ( this._destroyed ) {\n\t\tdebug( 'Attempted to destroy an already destroyed stream.' );\n\t\treturn this;\n\t}\n\tself = this;\n\tthis._destroyed = true;\n\n\tnextTick( close );\n\n\treturn this;\n\n\t/**\n\t* Closes a stream.\n\t*\n\t* @private\n\t*/\n\tfunction close() {\n\t\tif ( error ) {\n\t\t\tdebug( 'Stream was destroyed due to an error. Error: %s.', ( isError( error ) ) ? error.message : JSON.stringify( error ) );\n\t\t\tself.emit( 'error', error );\n\t\t}\n\t\tdebug( 'Closing the stream...' );\n\t\tself.emit( 'close' );\n\t}\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// MAIN //\n\n/**\n* Stream constructor for generating a readable stream from an array-like object.\n*\n* @constructor\n* @param {NonNegativeInteger} N - number of values to stream\n* @param {Collection} buffer - source value\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @param {Options} [options] - stream options\n* @param {boolean} [options.objectMode=false] - specifies whether the stream should operate in object mode\n* @param {(string|null)} [options.encoding=null] - specifies how `Buffer` objects should be decoded to strings\n* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of bytes to store in an internal buffer before pausing streaming\n* @param {string} [options.sep='\\n'] - separator used to join streamed data\n* @param {Function} [options.serialize] - custom serialization function\n* @throws {TypeError} first argument must be a nonnegative integer\n* @throws {TypeError} second argument must be an array-like object\n* @throws {TypeError} third argument must be an integer\n* @throws {TypeError} fourth argument must be a nonnegative integer\n* @throws {RangeError} linear index cannot exceed array bounds\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {StridedArrayStream} Stream instance\n*\n* @example\n* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var randu = require( '@stdlib/random-base-randu' );\n*\n* function log( chunk ) {\n* console.log( chunk.toString() );\n* }\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var stream = new StridedArrayStream( arr.length, arr, 1, 0 );\n*\n* stream.pipe( inspectStream( log ) );\n*/\nfunction StridedArrayStream( N, buffer, stride, offset, options ) {\n\tvar opts;\n\tvar err;\n\tvar i;\n\tif ( !( this instanceof StridedArrayStream ) ) {\n\t\tif ( arguments.length > 4 ) {\n\t\t\treturn new StridedArrayStream( N, buffer, stride, offset, options );\n\t\t}\n\t\treturn new StridedArrayStream( N, buffer, stride, offset );\n\t}\n\tif ( !isNonNegativeInteger( N ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', N ) );\n\t}\n\tif ( !isCollection( buffer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', buffer ) );\n\t}\n\tif ( !isInteger( stride ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', stride ) );\n\t}\n\tif ( !isNonNegativeInteger( offset ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%s`.', offset ) );\n\t}\n\tif ( N > 0 ) {\n\t\ti = offset + ((N-1)*stride);\n\t\tif ( offset >= buffer.length || i < 0 || i >= buffer.length ) {\n\t\t\tthrow new RangeError( 'invalid arguments. Strided array parameters are incompatible with the provided array-like object. Linear index exceeds array bounds.' );\n\t\t}\n\t}\n\topts = assign( {}, DEFAULTS );\n\tif ( arguments.length > 4 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Make the stream a readable stream:\n\tdebug( 'Creating a readable stream configured with the following options: %s.', JSON.stringify( opts ) );\n\tReadable.call( this, opts );\n\n\t// Destruction state:\n\tsetNonEnumerable( this, '_destroyed', false );\n\n\t// Cache whether the stream is operating in object mode:\n\tsetNonEnumerableReadOnly( this, '_objectMode', opts.objectMode );\n\n\t// Cache the separator:\n\tsetNonEnumerableReadOnly( this, '_sep', opts.sep );\n\n\t// Define the serialization function:\n\tsetNonEnumerableReadOnly( this, '_serialize', opts.serialize || JSON.stringify );\n\n\t// Cache the data source:\n\tsetNonEnumerableReadOnly( this, '_buffer', buffer );\n\n\t// Cache the strided array parameters:\n\tsetNonEnumerableReadOnly( this, '_N', N );\n\tsetNonEnumerableReadOnly( this, '_stride', stride );\n\tsetNonEnumerableReadOnly( this, '_offset', offset );\n\tsetNonEnumerable( this, '_idx', offset );\n\n\t// Initialize an iteration counter:\n\tsetNonEnumerable( this, '_i', 0 );\n\n\treturn this;\n}\n\n/*\n* Inherit from the `Readable` prototype.\n*/\ninherit( StridedArrayStream, Readable );\n\n/**\n* Implements the `_read` method.\n*\n* @private\n* @name _read\n* @memberof StridedArrayStream.prototype\n* @type {Function}\n* @param {number} size - number (of bytes) to read\n* @returns {void}\n*/\nsetNonEnumerableReadOnly( StridedArrayStream.prototype, '_read', read );\n\n/**\n* Gracefully destroys a stream, providing backward compatibility.\n*\n* @name destroy\n* @memberof StridedArrayStream.prototype\n* @type {Function}\n* @param {(string|Object|Error)} [error] - error\n* @returns {StridedArrayStream} Stream instance\n*/\nsetNonEnumerableReadOnly( StridedArrayStream.prototype, 'destroy', destroy );\n\n\n// EXPORTS //\n\nmodule.exports = StridedArrayStream;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar format = require( '@stdlib/string-format' );\nvar assign = require( '@stdlib/object-assign' );\nvar StridedArrayStream = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns an \"objectMode\" readable stream from an array-like value.\n*\n* @param {NonNegativeInteger} N - number of values to stream\n* @param {Collection} buffer - source value\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @param {Options} [options] - stream options\n* @param {(string|null)} [options.encoding=null] - specifies how `Buffer` objects should be decoded to `strings`\n* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of objects to store in an internal buffer before pausing streaming\n* @throws {TypeError} first argument must be a nonnegative integer\n* @throws {TypeError} second argument must be an array-like object\n* @throws {TypeError} third argument must be an integer\n* @throws {TypeError} fourth argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {StridedArrayStream} Stream instance\n*\n* @example\n* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var randu = require( '@stdlib/random-base-randu' );\n*\n* function log( v ) {\n* console.log( v );\n* }\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var stream = objectMode( arr.length, arr, 1, 0 );\n*\n* stream.pipe( inspectStream.objectMode( log ) );\n*/\nfunction objectMode( N, buffer, stride, offset, options ) {\n\tvar opts;\n\tif ( arguments.length > 4 ) {\n\t\topts = options;\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\topts = assign( {}, options );\n\t} else {\n\t\topts = {};\n\t}\n\topts.objectMode = true;\n\treturn new StridedArrayStream( N, buffer, stride, offset, opts );\n}\n\n\n// EXPORTS //\n\nmodule.exports = objectMode;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar format = require( '@stdlib/string-format' );\nvar assign = require( '@stdlib/object-assign' );\nvar StridedArrayStream = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating readable streams from strided array-like values.\n*\n* @param {Options} [options] - stream options\n* @param {boolean} [options.objectMode=false] - specifies whether a stream should operate in object mode\n* @param {(string|null)} [options.encoding=null] - specifies how `Buffer` objects should be decoded to `strings`\n* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of bytes to store in an internal buffer before pausing streaming\n* @param {string} [options.sep='\\n'] - separator used to join streamed data\n* @param {Function} [options.serialize] - custom serialization function\n* @throws {TypeError} options argument must be an object\n* @returns {Function} stream factory\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var randu = require( '@stdlib/random-base-randu' );\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var opts = {\n* 'sep': ',',\n* 'objectMode': false,\n* 'encoding': 'utf8',\n* 'highWaterMark': 64\n* };\n*\n* var createStream = factory( opts );\n*\n* // Create 10 identically configured streams...\n* var streams = [];\n* for ( i = 0; i < 10; i++ ) {\n* streams.push( createStream( arr.length, arr, 1, 0 ) );\n* }\n*/\nfunction factory( options ) {\n\tvar opts;\n\tif ( arguments.length ) {\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\topts = assign( {}, options );\n\t} else {\n\t\topts = {};\n\t}\n\treturn createStream;\n\n\t/**\n\t* Returns a readable stream from an array-like object.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} N - number of values to stream\n\t* @param {Collection} buffer - source array-like object\n\t* @param {integer} stride - stride length\n\t* @param {NonNegativeInteger} offset - starting index\n\t* @throws {TypeError} must provide an array-like object\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {StridedArrayStream} Stream instance\n\t*/\n\tfunction createStream( N, buffer, stride, offset ) {\n\t\treturn new StridedArrayStream( N, buffer, stride, offset, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create a readable stream from a strided array-like value.\n*\n* @module @stdlib/streams-node-from-strided-array\n*\n* @example\n* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var randu = require( '@stdlib/random-base-randu' );\n* var stridedArrayStream = require( '@stdlib/streams-node-from-strided-array' );\n*\n* function log( chunk ) {\n* console.log( chunk.toString() );\n* }\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var stream = stridedArrayStream( arr.length, arr, 1, 0 );\n*\n* stream.pipe( inspectStream( log ) );\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var randu = require( '@stdlib/random-base-randu' );\n* var stridedArrayStream = require( '@stdlib/streams-node-from-strided-array' );\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var opts = {\n* 'sep': ',',\n* 'objectMode': false,\n* 'encoding': 'utf8',\n* 'highWaterMark': 64\n* };\n*\n* var createStream = stridedArrayStream.factory( opts );\n*\n* // Create 10 identically configured streams...\n* var streams = [];\n* for ( i = 0; i < 10; i++ ) {\n* streams.push( createStream( arr.length, arr, 1, 0 ) );\n* }\n*\n* @example\n* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var randu = require( '@stdlib/random-base-randu' );\n* var stridedArrayStream = require( '@stdlib/streams-node-from-strided-array' );\n*\n* function log( v ) {\n* console.log( v );\n* }\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var stream = stridedArrayStream.objectMode( arr.length, arr, 1, 0 );\n*\n* stream.pipe( inspectStream.objectMode( log ) );\n*/\n\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar objectMode = require( './object_mode.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'objectMode', objectMode );\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,WAAc,GACd,SAAY,KACZ,IAAO,IACR,ICJA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,sCAAuC,EAAE,YAClEC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMT,EAAUS,CAAQ,EAGnBR,EAAYQ,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACL,EAAUI,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG5GP,EAAYQ,EAAS,YAAa,IACtCD,EAAK,WAAaC,EAAQ,WACrB,CAACP,EAAWM,EAAK,UAAW,GACzB,IAAI,UAAWF,EAAQ,+DAAgE,aAAcE,EAAK,UAAW,CAAE,EAG3HP,EAAYQ,EAAS,UAAW,IACpCD,EAAK,SAAWC,EAAQ,SACnB,CAACL,EAAUI,EAAK,QAAS,GAAKA,EAAK,WAAa,MAC7C,IAAI,UAAWF,EAAQ,sEAAuE,WAAYE,EAAK,QAAS,CAAE,EAG9HP,EAAYQ,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACN,EAAeK,EAAK,aAAc,GAChC,IAAI,UAAWF,EAAQ,0EAA2E,gBAAiBE,EAAK,aAAc,CAAE,EAG5IP,EAAYQ,EAAS,WAAY,IACrCD,EAAK,UAAYC,EAAQ,UACpB,CAACJ,EAAYG,EAAK,SAAU,GACzB,IAAI,UAAWF,EAAQ,gEAAiE,YAAaE,EAAK,SAAU,CAAE,EAGxH,KAhCC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAiChH,CAKAV,EAAO,QAAUQ,IChGjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,OAAQ,EAK1BC,EAAQD,EAAQ,2BAA4B,EAKhDD,EAAO,QAAUE,IChCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,iBAAkB,EAAE,SACxCC,EAAe,QAAS,8BAA+B,EACvDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAW,QAAS,0BAA2B,EAC/CC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAC1CC,EAAU,QAAS,uBAAwB,EAC3CC,EAAmB,QAAS,6CAA8C,EAC1EC,EAA2B,QAAS,uDAAwD,EAC5FC,EAAgB,QAAS,4BAA6B,EACtDC,EAAS,QAAS,qBAAsB,EACxCC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,yBAA0B,EAC9CC,EAAW,IACXC,EAAW,IACXC,EAAQ,IAYZ,SAASC,GAAO,CAEf,IAAIC,EACAC,EACAC,EAEJ,GAAK,MAAK,WAIV,IADAF,EAAM,GACEA,GAAM,CAIb,GAHAC,EAAM,KAEN,KAAK,IAAM,EACN,KAAK,GAAK,KAAK,GACnB,OAAAH,EAAO,qBAAsB,EACtB,KAAK,KAAM,IAAK,EAExBI,EAAI,KAAK,QAAS,KAAK,IAAK,EAC5BJ,EAAO,gCAAiC,KAAK,UAAWI,CAAE,EAAG,KAAK,KAAM,KAAK,EAAG,EAEhF,KAAK,MAAQ,KAAK,QACb,KAAK,cAAgB,KACzBA,EAAI,KAAK,WAAYA,CAAE,EAClB,OAAOA,GAAM,SACZ,KAAK,KAAO,EAChBA,EAAIV,EAAeU,CAAE,EAErBA,EAAIV,EAAe,KAAK,KAAKU,CAAE,EAErBjB,EAAUiB,CAAE,EAClB,KAAK,GAAK,IACdA,EAAIT,EAAO,OAAQ,CAAED,EAAe,KAAK,IAAK,EAAGU,CAAE,CAAE,GAGtDD,EAAM,IAAI,MAAOP,EAAQ,yFAA0FQ,CAAE,CAAE,GAGpHD,EACJ,KAAK,KAAM,QAASA,CAAI,EAExBD,EAAM,KAAK,KAAME,CAAE,CAErB,CAGD,CASA,SAASC,EAASC,EAAQ,CAEzB,IAAIC,EACJ,GAAK,KAAK,WACT,OAAAP,EAAO,mDAAoD,EACpD,KAER,OAAAO,EAAO,KACP,KAAK,WAAa,GAElBV,EAAUW,CAAM,EAET,KAOP,SAASA,GAAQ,CACXF,IACJN,EAAO,mDAAsDd,EAASoB,CAAM,EAAMA,EAAM,QAAU,KAAK,UAAWA,CAAM,CAAE,EAC1HC,EAAK,KAAM,QAASD,CAAM,GAE3BN,EAAO,uBAAwB,EAC/BO,EAAK,KAAM,OAAQ,CACpB,CAGD,CA+CA,SAASE,EAAoBC,EAAGC,EAAQC,EAAQC,EAAQC,EAAU,CACjE,IAAIC,EACAZ,EACAa,EACJ,GAAK,EAAG,gBAAgBP,GACvB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAoBC,EAAGC,EAAQC,EAAQC,EAAQC,CAAQ,EAE5D,IAAIL,EAAoBC,EAAGC,EAAQC,EAAQC,CAAO,EAE1D,GAAK,CAACxB,EAAsBqB,CAAE,EAC7B,MAAM,IAAI,UAAWd,EAAQ,+EAAgFc,CAAE,CAAE,EAElH,GAAK,CAACzB,EAAc0B,CAAO,EAC1B,MAAM,IAAI,UAAWf,EAAQ,+EAAgFe,CAAO,CAAE,EAEvH,GAAK,CAACvB,EAAWwB,CAAO,EACvB,MAAM,IAAI,UAAWhB,EAAQ,oEAAqEgB,CAAO,CAAE,EAE5G,GAAK,CAACvB,EAAsBwB,CAAO,EAClC,MAAM,IAAI,UAAWjB,EAAQ,gFAAiFiB,CAAO,CAAE,EAExH,GAAKH,EAAI,IACRM,EAAIH,GAAWH,EAAE,GAAGE,EACfC,GAAUF,EAAO,QAAUK,EAAI,GAAKA,GAAKL,EAAO,QACpD,MAAM,IAAI,WAAY,sIAAuI,EAI/J,GADAI,EAAOzB,EAAQ,CAAC,EAAGQ,CAAS,EACvB,UAAU,OAAS,IACvBK,EAAMJ,EAAUgB,EAAMD,CAAQ,EACzBX,GACJ,MAAMA,EAIR,OAAAH,EAAO,wEAAyE,KAAK,UAAWe,CAAK,CAAE,EACvG/B,EAAS,KAAM,KAAM+B,CAAK,EAG1BvB,EAAkB,KAAM,aAAc,EAAM,EAG5CC,EAA0B,KAAM,cAAesB,EAAK,UAAW,EAG/DtB,EAA0B,KAAM,OAAQsB,EAAK,GAAI,EAGjDtB,EAA0B,KAAM,aAAcsB,EAAK,WAAa,KAAK,SAAU,EAG/EtB,EAA0B,KAAM,UAAWkB,CAAO,EAGlDlB,EAA0B,KAAM,KAAMiB,CAAE,EACxCjB,EAA0B,KAAM,UAAWmB,CAAO,EAClDnB,EAA0B,KAAM,UAAWoB,CAAO,EAClDrB,EAAkB,KAAM,OAAQqB,CAAO,EAGvCrB,EAAkB,KAAM,KAAM,CAAE,EAEzB,IACR,CAKAD,EAASkB,EAAoBzB,CAAS,EAYtCS,EAA0BgB,EAAmB,UAAW,QAASR,CAAK,EAWtER,EAA0BgB,EAAmB,UAAW,UAAWJ,CAAQ,EAK3EtB,EAAO,QAAU0B,ICtRjB,IAAAQ,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,GAAS,QAAS,uBAAwB,EAC1CC,GAAS,QAAS,uBAAwB,EAC1CC,GAAqB,IA0CzB,SAASC,GAAYC,EAAGC,EAAQC,EAAQC,EAAQC,EAAU,CACzD,IAAIC,EACJ,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAA,EAAOD,EACF,CAACT,EAAUU,CAAK,EACpB,MAAM,IAAI,UAAWT,GAAQ,qEAAsES,CAAK,CAAE,EAE3GA,EAAOR,GAAQ,CAAC,EAAGO,CAAQ,CAC5B,MACCC,EAAO,CAAC,EAET,OAAAA,EAAK,WAAa,GACX,IAAIP,GAAoBE,EAAGC,EAAQC,EAAQC,EAAQE,CAAK,CAChE,CAKAX,EAAO,QAAUK,KCrFjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAW,QAAS,gCAAiC,EACrDC,GAAS,QAAS,uBAAwB,EAC1CC,GAAS,QAAS,uBAAwB,EAC1CC,GAAqB,IA0CzB,SAASC,GAASC,EAAU,CAC3B,IAAIC,EACJ,GAAK,UAAU,OAAS,CACvB,GAAK,CAACN,GAAUK,CAAQ,EACvB,MAAM,IAAI,UAAWJ,GAAQ,qEAAsEI,CAAQ,CAAE,EAE9GC,EAAOJ,GAAQ,CAAC,EAAGG,CAAQ,CAC5B,MACCC,EAAO,CAAC,EAET,OAAOC,EAeP,SAASA,EAAcC,EAAGC,EAAQC,EAAQC,EAAS,CAClD,OAAO,IAAIR,GAAoBK,EAAGC,EAAQC,EAAQC,EAAQL,CAAK,CAChE,CACD,CAKAP,EAAO,QAAUK,KCLjB,IAAIQ,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAa,IACbC,GAAU,IAKdH,EAAaC,EAAM,aAAcC,EAAW,EAC5CF,EAAaC,EAAM,UAAWE,EAAQ,EAKtC,OAAO,QAAUF", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isNonNegative", "isString", "isFunction", "format", "validate", "opts", "options", "require_debug", "__commonJSMin", "exports", "module", "logger", "debug", "require_main", "__commonJSMin", "exports", "module", "Readable", "isCollection", "isError", "isBuffer", "isInteger", "isNonNegativeInteger", "assign", "inherit", "setNonEnumerable", "setNonEnumerableReadOnly", "string2buffer", "Buffer", "format", "nextTick", "DEFAULTS", "validate", "debug", "read", "FLG", "err", "v", "destroy", "error", "self", "close", "StridedArrayStream", "N", "buffer", "stride", "offset", "options", "opts", "i", "require_object_mode", "__commonJSMin", "exports", "module", "isObject", "format", "assign", "StridedArrayStream", "objectMode", "N", "buffer", "stride", "offset", "options", "opts", "require_factory", "__commonJSMin", "exports", "module", "isObject", "format", "assign", "StridedArrayStream", "factory", "options", "opts", "createStream", "N", "buffer", "stride", "offset", "setReadOnly", "main", "objectMode", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index acf0905..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,155 +0,0 @@ - -{{alias}}( N, buffer, stride, offset[, options] ) - Creates a readable stream from a strided array-like object. - - In object mode, `null` is a reserved value. If an array contains `null` - values (e.g., as a means to encode missing values), the stream will - prematurely end. Consider an alternative encoding or filter `null` values - prior to invocation. - - In binary mode, if an array contains `undefined` values, the stream will - emit an error. Consider providing a custom serialization function or - filtering `undefined` values prior to invocation. - - If a serialization function fails to return a string or Buffer, the stream - emits an error. - - Parameters - ---------- - N: integer - Number of values to stream. - - buffer: ArrayLikeObject - Array-like object from which to create the stream. - - stride: integer - Stride length. - - offset: integer - Starting index. - - options: Object (optional) - Options. - - options.objectMode: boolean (optional) - Specifies whether a stream should operate in "objectMode". Default: - false. - - options.encoding: string|null (optional) - Specifies how Buffer objects should be decoded to strings. Default: - null. - - options.highWaterMark: integer (optional) - Specifies the maximum number of bytes to store in an internal buffer - before pausing the stream. - - options.sep: string (optional) - Separator used to join streamed data. This option is only applicable - when a stream is not in "objectMode". Default: '\n'. - - options.serialize: Function (optional) - Serialization function. The default behavior is to serialize streamed - values as JSON strings. This option is only applicable when a stream is - not in "objectMode". - - Returns - ------- - stream: ReadableStream - Readable stream. - - Examples - -------- - > function fcn( chunk ) { console.log( chunk.toString() ); }; - > var s = {{alias}}( 3, [ 1, 2, 3 ], 1, 0 ); - > var o = {{alias:@stdlib/streams/node/inspect-sink}}( fcn ); - > s.pipe( o ); - - -{{alias}}.factory( [options] ) - Returns a function for creating readable streams from array-like objects. - - Parameters - ---------- - options: Object (optional) - Options. - - options.objectMode: boolean (optional) - Specifies whether a stream should operate in "objectMode". Default: - false. - - options.encoding: string|null (optional) - Specifies how Buffer objects should be decoded to strings. Default: - null. - - options.highWaterMark: integer (optional) - Specifies the maximum number of bytes to store in an internal buffer - before pausing streaming. - - options.sep: string (optional) - Separator used to join streamed data. This option is only applicable - when a stream is not in "objectMode". Default: '\n'. - - options.serialize: Function (optional) - Serialization function. The default behavior is to serialize streamed - values as JSON strings. This option is only applicable when a stream is - not in "objectMode". - - Returns - ------- - fcn: Function - Function for creating readable streams. - - Examples - -------- - > var opts = { 'objectMode': true, 'highWaterMark': 64 }; - > var createStream = {{alias}}.factory( opts ); - - -{{alias}}.objectMode( N, buffer, stride, offset[, options] ) - Returns an "objectMode" readable stream from a strided array-like object. - - In object mode, `null` is a reserved value. If an array contains `null` - values (e.g., as a means to encode missing values), the stream will - prematurely end. Consider an alternative encoding or filter `null` values - prior to invocation. - - Parameters - ---------- - N: integer - Number of values to stream. - - buffer: ArrayLikeObject - Array-like object from which to create the stream. - - stride: integer - Stride length. - - offset: integer - Starting index. - - options: Object (optional) - Options. - - options.encoding: string|null (optional) - Specifies how Buffer objects should be decoded to strings. Default: - null. - - options.highWaterMark: integer (optional) - Specifies the maximum number of objects to store in an internal buffer - before pausing streaming. - - Returns - ------- - stream: ReadableStream - Readable stream operating in "objectMode". - - Examples - -------- - > function fcn( v ) { console.log( v ); }; - > var s = {{alias}}.objectMode( 3, [ 1, 2, 3 ], 1, 0 ); - > var o = {{alias:@stdlib/streams/node/inspect-sink}}.objectMode( fcn ); - > s.pipe( o ); - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 39d97b7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,189 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import StridedArrayStream = require( './index' ); - - -// TESTS // - -// The constructor returns a stream... -{ - const arr = [ 1, 2, 3, 4 ]; - new StridedArrayStream( arr.length, arr, 1, 0 ); // $ExpectType Readable - new StridedArrayStream( arr.length, arr, 1, 0, { 'objectMode': true } ); // $ExpectType Readable -} - -// The constructor is callable... -{ - const arr = [ 1, 2, 3, 4 ]; - const stridedArrayStream = StridedArrayStream; - stridedArrayStream( arr.length, arr, 1, 0 ); // $ExpectType Readable - stridedArrayStream( arr.length, arr, 1, 0, { 'objectMode': true } ); // $ExpectType Readable -} - -// The constructor has an `objectMode` method which returns a stream... -{ - const arr = [ 1, 2, 3, 4 ]; - StridedArrayStream.objectMode( arr.length, arr, 1, 0 ); // $ExpectType Readable - StridedArrayStream.objectMode( arr.length, arr, 1, 0, { 'objectMode': true } ); // $ExpectType Readable -} - -// The constructor has a `factory` method which returns a function for creating streams... -{ - const arr = [ 1, 2, 3, 4 ]; - const f = StridedArrayStream.factory(); - f( arr.length, arr, 1, 0 ); // $ExpectType Readable -} - -// The compiler throws an error if the constructor is provided a first argument which is not a number... -{ - const arr = [ 1, 2, 3, 4 ]; - new StridedArrayStream( 'abc', arr, 1, 0 ); // $ExpectError - new StridedArrayStream( true, arr, 1, 0 ); // $ExpectError - new StridedArrayStream( false, arr, 1, 0 ); // $ExpectError - new StridedArrayStream( [], arr, 1, 0 ); // $ExpectError - new StridedArrayStream( {}, arr, 1, 0 ); // $ExpectError - new StridedArrayStream( null, arr, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the constructor is provided a second argument which is not a collection... -{ - const arr = [ 1, 2, 3, 4 ]; - new StridedArrayStream( arr.length, 123, 1, 0 ); // $ExpectError - new StridedArrayStream( arr.length, true, 1, 0 ); // $ExpectError - new StridedArrayStream( arr.length, false, 1, 0 ); // $ExpectError - new StridedArrayStream( arr.length, {}, 1, 0 ); // $ExpectError - new StridedArrayStream( arr.length, null, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the constructor is provided a third argument which is not a number... -{ - const arr = [ 1, 2, 3, 4 ]; - new StridedArrayStream( arr.length, arr, 'abc', 0 ); // $ExpectError - new StridedArrayStream( arr.length, arr, true, 0 ); // $ExpectError - new StridedArrayStream( arr.length, arr, false, 0 ); // $ExpectError - new StridedArrayStream( arr.length, arr, [], 0 ); // $ExpectError - new StridedArrayStream( arr.length, arr, {}, 0 ); // $ExpectError - new StridedArrayStream( arr.length, arr, null, 0 ); // $ExpectError -} - -// The compiler throws an error if the constructor is provided a fourth argument which is not a number... -{ - const arr = [ 1, 2, 3, 4 ]; - new StridedArrayStream( arr.length, arr, 1, 'abc' ); // $ExpectError - new StridedArrayStream( arr.length, arr, 1, true ); // $ExpectError - new StridedArrayStream( arr.length, arr, 1, false ); // $ExpectError - new StridedArrayStream( arr.length, arr, 1, [] ); // $ExpectError - new StridedArrayStream( arr.length, arr, 1, {} ); // $ExpectError - new StridedArrayStream( arr.length, arr, 1, null ); // $ExpectError -} - -// The compiler throws an error if the constructor is provided a fifth argument which is not an options object... -{ - const arr = [ 1, 2, 3, 4 ]; - new StridedArrayStream( arr.length, arr, 1, 0, 'abc' ); // $ExpectError - new StridedArrayStream( arr.length, arr, 1, 0, 123 ); // $ExpectError - new StridedArrayStream( arr.length, arr, 1, 0, true ); // $ExpectError - new StridedArrayStream( arr.length, arr, 1, 0, false ); // $ExpectError - new StridedArrayStream( arr.length, arr, 1, 0, [] ); // $ExpectError - new StridedArrayStream( arr.length, arr, 1, 0, null ); // $ExpectError -} - -// The compiler throws an error if the `objectMode` method is provided a first argument which is not a number... -{ - const arr = [ 1, 2, 3, 4 ]; - StridedArrayStream.objectMode( 'abc', arr, 1, 0 ); // $ExpectError - StridedArrayStream.objectMode( null, arr, 1, 0 ); // $ExpectError - StridedArrayStream.objectMode( true, arr, 1, 0 ); // $ExpectError - StridedArrayStream.objectMode( false, arr, 1, 0 ); // $ExpectError - StridedArrayStream.objectMode( [], arr, 1, 0 ); // $ExpectError - StridedArrayStream.objectMode( {}, arr, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `objectMode` method is provided a second argument which is not a collection... -{ - const arr = [ 1, 2, 3, 4 ]; - StridedArrayStream.objectMode( arr.length, null, 1, 0 ); // $ExpectError - StridedArrayStream.objectMode( arr.length, 123, 1, 0 ); // $ExpectError - StridedArrayStream.objectMode( arr.length, true, 1, 0 ); // $ExpectError - StridedArrayStream.objectMode( arr.length, false, 1, 0 ); // $ExpectError - StridedArrayStream.objectMode( arr.length, {}, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `objectMode` method is provided a third argument which is not a number... -{ - const arr = [ 1, 2, 3, 4 ]; - StridedArrayStream.objectMode( arr.length, arr, 'abc', 0 ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, null, 0 ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, true, 0 ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, false, 0 ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, [], 0 ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, {}, 0 ); // $ExpectError -} - -// The compiler throws an error if the `objectMode` method is provided a fourth argument which is not a number... -{ - const arr = [ 1, 2, 3, 4 ]; - StridedArrayStream.objectMode( arr.length, arr, 1, 'abc' ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, 1, null ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, 1, true ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, 1, false ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, 1, [] ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, 1, {} ); // $ExpectError -} - -// The compiler throws an error if the `objectMode` method is provided a fifth argument which is not an options object... -{ - const arr = [ 1, 2, 3, 4 ]; - StridedArrayStream.objectMode( arr.length, arr, 1, 0, 'abc' ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, 1, 0, 123 ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, 1, 0, true ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, 1, 0, false ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, 1, 0, [] ); // $ExpectError - StridedArrayStream.objectMode( arr.length, arr, 1, 0, null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an argument which is not an options object... -{ - StridedArrayStream.factory( 'abc' ); // $ExpectError - StridedArrayStream.factory( 123 ); // $ExpectError - StridedArrayStream.factory( true ); // $ExpectError - StridedArrayStream.factory( false ); // $ExpectError - StridedArrayStream.factory( [] ); // $ExpectError - StridedArrayStream.factory( null ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid number of arguments... -{ - const arr = [ 1, 2, 3, 4 ]; - let f = StridedArrayStream.factory(); - f(); // $ExpectError - f( arr.length ); // $ExpectError - f( arr.length, arr ); // $ExpectError - f( arr.length, arr, 1 ); // $ExpectError - f( arr.length, arr, 1, 0, {} ); // $ExpectError - - f = StridedArrayStream.factory( { 'objectMode': true } ); - f(); // $ExpectError - f( arr.length ); // $ExpectError - f( arr.length, arr ); // $ExpectError - f( arr.length, arr, 1 ); // $ExpectError - f( arr.length, arr, 1, 0, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index bc144f2..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -var randu = require( '@stdlib/random-base-randu' ); -var Float64Array = require( '@stdlib/array-float64' ); -var stridedArrayStream = require( './../lib' ); - -function log( v ) { - console.log( v.toString() ); -} - -// Create an array containing uniformly distributed pseudorandom numbers: -var arr = new Float64Array( 20 ); - -var i; -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = randu(); -} - -// Create a stream which iterates over every other element from right-to-left: -var opts = { - 'objectMode': true -}; -var stream = stridedArrayStream( 10, arr, -2, arr.length-2, opts ); - -// Create a writable stream for inspecting stream data: -opts = { - 'objectMode': true -}; -var iStream = inspectStream( opts, log ); - -// Begin data flow: -stream.pipe( iStream ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index f9f354c..71fa81e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -19,7 +19,7 @@ // TypeScript Version: 4.1 /// -/// +/// import { Readable } from 'stream'; import { Collection } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9487404 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-error@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-buffer@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/object-assign@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-inherit@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-from-string@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-ctor@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-next-tick@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as g}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as v}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-number@v0.2.2-esm/index.mjs";import{isPrimitive as y}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";function m(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})})),r}function b(){}function _(){_.init.call(this)}function E(e){return void 0===e._maxListeners?_.defaultMaxListeners:e._maxListeners}function R(e,t,r,n){var i,o,s,a;if("function"!=typeof r)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),s=o[t]):(o=e._events=new b,e._eventsCount=0),s){if("function"==typeof s?s=o[t]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),!s.warned&&(i=E(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,a=u,"function"==typeof console.warn?console.warn(a):console.log(a)}}else s=o[t]=r,++e._eventsCount;return e}function j(e,t,r){var n=!1;function i(){e.removeListener(t,i),n||(n=!0,r.apply(e,arguments))}return i.listener=r,i}function S(e){var t=this._events;if(t){var r=t[e];if("function"==typeof r)return 1;if(r)return r.length}return 0}function M(e,t){for(var r=new Array(t);t--;)r[t]=e[t];return r}b.prototype=Object.create(null),_.EventEmitter=_,_.usingDomains=!1,_.prototype.domain=void 0,_.prototype._events=void 0,_.prototype._maxListeners=void 0,_.defaultMaxListeners=10,_.init=function(){this.domain=null,_.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new b,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},_.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},_.prototype.getMaxListeners=function(){return E(this)},_.prototype.emit=function(e){var t,r,n,i,o,s,a,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(a=this.domain,u){if(t=arguments[1],!a){if(t instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=a,t.domainThrown=!1,a.emit("error",t),!1}if(!(r=s[e]))return!1;var f="function"==typeof r;switch(n=arguments.length){case 1:!function(e,t,r){if(t)e.call(r);else for(var n=e.length,i=M(e,n),o=0;o0;)if(r[o]===t||r[o].listener&&r[o].listener===t){s=r[o].listener,i=o;break}if(i<0)return this;if(1===r.length){if(r[0]=void 0,0==--this._eventsCount)return this._events=new b,this;delete n[e]}else!function(e,t){for(var r=t,n=r+1,i=e.length;n0?Reflect.ownKeys(this._events):[]};var A="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},T=[],L=[],k="undefined"!=typeof Uint8Array?Uint8Array:Array,x=!1;function P(){x=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)T[t]=e[t],L[e.charCodeAt(t)]=t;L["-".charCodeAt(0)]=62,L["_".charCodeAt(0)]=63}function C(e,t,r){for(var n,i,o=[],s=t;s>18&63]+T[i>>12&63]+T[i>>6&63]+T[63&i]);return o.join("")}function O(e){var t;x||P();for(var r=e.length,n=r%3,i="",o=[],s=16383,a=0,u=r-n;au?u:a+s));return 1===n?(t=e[r-1],i+=T[t>>2],i+=T[t<<4&63],i+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],i+=T[t>>10],i+=T[t>>4&63],i+=T[t<<2&63],i+="="),o.push(i),o.join("")}function B(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<>1,f=-7,l=r?i-1:0,c=r?-1:1,d=e[t+l];for(l+=c,o=d&(1<<-f)-1,d>>=-f,f+=a;f>0;o=256*o+e[t+l],l+=c,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+e[t+l],l+=c,f-=8);if(0===o)o=1-h;else{if(o===u)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,n),o-=h}return(d?-1:1)*s*Math.pow(2,o-n)}function U(e,t,r,n,i,o){var s,a,u,h=8*o-i-1,f=(1<>1,c=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:o-1,p=n?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+l>=1?c/u:c*Math.pow(2,1-l))*u>=2&&(s++,u/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(t*u-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[r+d]=255&a,d+=p,a/=256,i-=8);for(s=s<0;e[r+d]=255&s,d+=p,s/=256,h-=8);e[r+d-p]|=128*g}var D={}.toString,I=Array.isArray||function(e){return"[object Array]"==D.call(e)};function z(){return N.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Y(e,t){if(z()=z())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+z().toString(16)+" bytes");return 0|e}function V(e){return!(null==e||!e._isBuffer)}function $(e,t){if(V(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return _e(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Ee(e).length;default:if(n)return _e(e).length;t=(""+t).toLowerCase(),n=!0}}function G(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return fe(this,t,r);case"utf8":case"utf-8":return se(this,t,r);case"ascii":return ue(this,t,r);case"latin1":case"binary":return he(this,t,r);case"base64":return oe(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return le(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function Z(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function K(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=N.from(t,n)),V(t))return 0===t.length?-1:Q(e,t,r,n,i);if("number"==typeof t)return t&=255,N.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):Q(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function Q(e,t,r,n,i){var o,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function h(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var f=-1;for(o=r;oa&&(r=a-u),o=r;o>=0;o--){for(var l=!0,c=0;ci&&(n=i):n=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function oe(e,t,r){return 0===t&&r===e.length?O(e):O(e.slice(t,r))}function se(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i239?4:h>223?3:h>191?2:1;if(i+l<=r)switch(l){case 1:h<128&&(f=h);break;case 2:128==(192&(o=e[i+1]))&&(u=(31&h)<<6|63&o)>127&&(f=u);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(u=(15&h)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(f=u);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&h)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(f=u)}null===f?(f=65533,l=1):f>65535&&(f-=65536,n.push(f>>>10&1023|55296),f=56320|1023&f),n.push(f),i+=l}return function(e){var t=e.length;if(t<=ae)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n0&&(e=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(e+=" ... ")),""},N.prototype.compare=function(e,t,r,n,i){if(!V(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(t>>>=0),a=Math.min(o,s),u=this.slice(n,i),h=e.slice(t,r),f=0;fi)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return X(this,e,t,r);case"utf8":case"utf-8":return ee(this,e,t,r);case"ascii":return te(this,e,t,r);case"latin1":case"binary":return re(this,e,t,r);case"base64":return ne(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ie(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},N.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var ae=4096;function ue(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;in)&&(r=n);for(var i="",o=t;or)throw new RangeError("Trying to access beyond buffer length")}function de(e,t,r,n,i,o){if(!V(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||te.length)throw new RangeError("Index out of range")}function pe(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-r,2);i>>8*(n?i:1-i)}function ge(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);i>>8*(n?i:3-i)&255}function ve(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function ye(e,t,r,n,i){return i||ve(e,0,r,4),U(e,t,r,n,23,4),r+4}function we(e,t,r,n,i){return i||ve(e,0,r,8),U(e,t,r,n,52,8),r+8}N.prototype.slice=function(e,t){var r,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t0&&(i*=256);)n+=this[e+--t]*i;return n},N.prototype.readUInt8=function(e,t){return t||ce(e,1,this.length),this[e]},N.prototype.readUInt16LE=function(e,t){return t||ce(e,2,this.length),this[e]|this[e+1]<<8},N.prototype.readUInt16BE=function(e,t){return t||ce(e,2,this.length),this[e]<<8|this[e+1]},N.prototype.readUInt32LE=function(e,t){return t||ce(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},N.prototype.readUInt32BE=function(e,t){return t||ce(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},N.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||ce(e,t,this.length);for(var n=this[e],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*t)),n},N.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||ce(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},N.prototype.readInt8=function(e,t){return t||ce(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},N.prototype.readInt16LE=function(e,t){t||ce(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},N.prototype.readInt16BE=function(e,t){t||ce(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},N.prototype.readInt32LE=function(e,t){return t||ce(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},N.prototype.readInt32BE=function(e,t){return t||ce(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},N.prototype.readFloatLE=function(e,t){return t||ce(e,4,this.length),B(this,e,!0,23,4)},N.prototype.readFloatBE=function(e,t){return t||ce(e,4,this.length),B(this,e,!1,23,4)},N.prototype.readDoubleLE=function(e,t){return t||ce(e,8,this.length),B(this,e,!0,52,8)},N.prototype.readDoubleBE=function(e,t){return t||ce(e,8,this.length),B(this,e,!1,52,8)},N.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||de(this,e,t,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[t]=255&e;++o=0&&(o*=256);)this[t+i]=e/o&255;return t+r},N.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||de(this,e,t,1,255,0),N.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},N.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||de(this,e,t,2,65535,0),N.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):pe(this,e,t,!0),t+2},N.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||de(this,e,t,2,65535,0),N.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):pe(this,e,t,!1),t+2},N.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||de(this,e,t,4,4294967295,0),N.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):ge(this,e,t,!0),t+4},N.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||de(this,e,t,4,4294967295,0),N.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):ge(this,e,t,!1),t+4},N.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);de(this,e,t,r,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o>0)-a&255;return t+r},N.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);de(this,e,t,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r},N.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||de(this,e,t,1,127,-128),N.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},N.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||de(this,e,t,2,32767,-32768),N.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):pe(this,e,t,!0),t+2},N.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||de(this,e,t,2,32767,-32768),N.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):pe(this,e,t,!1),t+2},N.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||de(this,e,t,4,2147483647,-2147483648),N.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):ge(this,e,t,!0),t+4},N.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||de(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),N.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):ge(this,e,t,!1),t+4},N.prototype.writeFloatLE=function(e,t,r){return ye(this,e,t,!0,r)},N.prototype.writeFloatBE=function(e,t,r){return ye(this,e,t,!1,r)},N.prototype.writeDoubleLE=function(e,t,r){return we(this,e,t,!0,r)},N.prototype.writeDoubleBE=function(e,t,r){return we(this,e,t,!1,r)},N.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t=0;--i)e[i+t]=this[i+r];else if(o<1e3||!N.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(o=t;o55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Ee(e){return function(e){var t,r,n,i,o,s;x||P();var a=e.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");o="="===e[a-2]?2:"="===e[a-1]?1:0,s=new k(3*a/4-o),n=o>0?a-4:a;var u=0;for(t=0,r=0;t>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=L[e.charCodeAt(t)]<<2|L[e.charCodeAt(t+1)]>>4,s[u++]=255&i):1===o&&(i=L[e.charCodeAt(t)]<<10|L[e.charCodeAt(t+1)]<<4|L[e.charCodeAt(t+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s}(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(me,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Re(e,t,r,n){for(var i=0;i=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function je(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function Se(){throw new Error("setTimeout has not been defined")}function Me(){throw new Error("clearTimeout has not been defined")}var Ae=Se,Te=Me;function Le(e){if(Ae===setTimeout)return setTimeout(e,0);if((Ae===Se||!Ae)&&setTimeout)return Ae=setTimeout,setTimeout(e,0);try{return Ae(e,0)}catch(t){try{return Ae.call(null,e,0)}catch(t){return Ae.call(this,e,0)}}}"function"==typeof A.setTimeout&&(Ae=setTimeout),"function"==typeof A.clearTimeout&&(Te=clearTimeout);var ke,xe=[],Pe=!1,Ce=-1;function Oe(){Pe&&ke&&(Pe=!1,ke.length?xe=ke.concat(xe):Ce=-1,xe.length&&Be())}function Be(){if(!Pe){var e=Le(Oe);Pe=!0;for(var t=xe.length;t;){for(ke=xe,xe=[];++Ce1)for(var r=1;r=i)return e;switch(e){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(e){return"[Circular]"}default:return e}})),s=n[r];r=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),ut(t)?r.showHidden=t:t&&function(e,t){if(!t||!dt(t))return e;var r=Object.keys(t),n=r.length;for(;n--;)e[r[n]]=t[r[n]]}(r,t),lt(r.showHidden)&&(r.showHidden=!1),lt(r.depth)&&(r.depth=2),lt(r.colors)&&(r.colors=!1),lt(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=nt),ot(r,e,r.depth)}function nt(e,t){var r=rt.styles[t];return r?"["+rt.colors[r][0]+"m"+e+"["+rt.colors[r][1]+"m":e}function it(e,t){return e}function ot(e,t,r){if(e.customInspect&&t&&vt(t.inspect)&&t.inspect!==rt&&(!t.constructor||t.constructor.prototype!==t)){var n=t.inspect(r,e);return ft(n)||(n=ot(e,n,r)),n}var i=function(e,t){if(lt(t))return e.stylize("undefined","undefined");if(ft(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}if(n=t,"number"==typeof n)return e.stylize(""+t,"number");var n;if(ut(t))return e.stylize(""+t,"boolean");if(ht(t))return e.stylize("null","null")}(e,t);if(i)return i;var o=Object.keys(t),s=function(e){var t={};return e.forEach((function(e,r){t[e]=!0})),t}(o);if(e.showHidden&&(o=Object.getOwnPropertyNames(t)),gt(t)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return st(t);if(0===o.length){if(vt(t)){var a=t.name?": "+t.name:"";return e.stylize("[Function"+a+"]","special")}if(ct(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(pt(t))return e.stylize(Date.prototype.toString.call(t),"date");if(gt(t))return st(t)}var u,h,f="",l=!1,c=["{","}"];(u=t,Array.isArray(u)&&(l=!0,c=["[","]"]),vt(t))&&(f=" [Function"+(t.name?": "+t.name:"")+"]");return ct(t)&&(f=" "+RegExp.prototype.toString.call(t)),pt(t)&&(f=" "+Date.prototype.toUTCString.call(t)),gt(t)&&(f=" "+st(t)),0!==o.length||l&&0!=t.length?r<0?ct(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special"):(e.seen.push(t),h=l?function(e,t,r,n,i){for(var o=[],s=0,a=t.length;s60)return r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1];return r[0]+t+" "+e.join(", ")+" "+r[1]}(h,f,c)):c[0]+f+c[1]}function st(e){return"["+Error.prototype.toString.call(e)+"]"}function at(e,t,r,n,i,o){var s,a,u;if((u=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]}).get?a=u.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):u.set&&(a=e.stylize("[Setter]","special")),wt(n,i)||(s="["+i+"]"),a||(e.seen.indexOf(u.value)<0?(a=ht(r)?ot(e,u.value,null):ot(e,u.value,r-1)).indexOf("\n")>-1&&(a=o?a.split("\n").map((function(e){return" "+e})).join("\n").substr(2):"\n"+a.split("\n").map((function(e){return" "+e})).join("\n")):a=e.stylize("[Circular]","special")),lt(s)){if(o&&i.match(/^\d+$/))return a;(s=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+a}function ut(e){return"boolean"==typeof e}function ht(e){return null===e}function ft(e){return"string"==typeof e}function lt(e){return void 0===e}function ct(e){return dt(e)&&"[object RegExp]"===yt(e)}function dt(e){return"object"==typeof e&&null!==e}function pt(e){return dt(e)&&"[object Date]"===yt(e)}function gt(e){return dt(e)&&("[object Error]"===yt(e)||e instanceof Error)}function vt(e){return"function"==typeof e}function yt(e){return Object.prototype.toString.call(e)}function wt(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function mt(){this.head=null,this.tail=null,this.length=0}rt.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},rt.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},mt.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},mt.prototype.unshift=function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length},mt.prototype.shift=function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},mt.prototype.clear=function(){this.head=this.tail=null,this.length=0},mt.prototype.join=function(e){if(0===this.length)return"";for(var t=this.head,r=""+t.data;t=t.next;)r+=e+t.data;return r},mt.prototype.concat=function(e){if(0===this.length)return N.alloc(0);if(1===this.length)return this.head.data;for(var t=N.allocUnsafe(e>>>0),r=this.head,n=0;r;)r.data.copy(t,n),n+=r.data.length,r=r.next;return t};var bt=N.isEncoding||function(e){switch(e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function _t(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),function(e){if(e&&!bt(e))throw new Error("Unknown encoding: "+e)}(e),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=Rt;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=jt;break;default:return void(this.write=Et)}this.charBuffer=new N(6),this.charReceived=0,this.charLength=0}function Et(e){return e.toString(this.encoding)}function Rt(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function jt(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}_t.prototype.write=function(e){for(var t="";this.charLength;){var r=e.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;if(e.copy(this.charBuffer,this.charReceived,0,r),this.charReceived+=r,this.charReceived=55296&&i<=56319)){if(this.charReceived=this.charLength=0,0===e.length)return t;break}this.charLength+=this.surrogateSize,t=""}this.detectIncompleteChar(e);var n=e.length;this.charLength&&(e.copy(this.charBuffer,0,e.length-this.charReceived,n),n-=this.charReceived);var i;n=(t+=e.toString(this.encoding,0,n)).length-1;if((i=t.charCodeAt(n))>=55296&&i<=56319){var o=this.surrogateSize;return this.charLength+=o,this.charReceived+=o,this.charBuffer.copy(this.charBuffer,o,0,o),e.copy(this.charBuffer,0,0,o),t.substring(0,n)}return t},_t.prototype.detectIncompleteChar=function(e){for(var t=e.length>=3?3:e.length;t>0;t--){var r=e[e.length-t];if(1==t&&r>>5==6){this.charLength=2;break}if(t<=2&&r>>4==14){this.charLength=3;break}if(t<=3&&r>>3==30){this.charLength=4;break}}this.charReceived=t},_t.prototype.end=function(e){var t="";if(e&&e.length&&(t=this.write(e)),this.charReceived){var r=this.charReceived,n=this.charBuffer,i=this.encoding;t+=n.slice(0,r).toString(i)}return t},At.ReadableState=Mt;var St=function(e){if(lt(et)&&(et=Ge.env.NODE_DEBUG||""),e=e.toUpperCase(),!tt[e])if(new RegExp("\\b"+e+"\\b","i").test(et)){tt[e]=function(){var t=Qe.apply(null,arguments);console.error("%s %d: %s",e,0,t)}}else tt[e]=function(){};return tt[e]}("stream");function Mt(e,t){e=e||{},this.objectMode=!!e.objectMode,t instanceof tr&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var r=e.highWaterMark,n=this.objectMode?16:16384;this.highWaterMark=r||0===r?r:n,this.highWaterMark=~~this.highWaterMark,this.buffer=new mt,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(this.decoder=new _t(e.encoding),this.encoding=e.encoding)}function At(e){if(!(this instanceof At))return new At(e);this._readableState=new Mt(e,this),this.readable=!0,e&&"function"==typeof e.read&&(this._read=e.read),_.call(this)}function Tt(e,t,r,n,i){var o=function(e,t){var r=null;N.isBuffer(t)||"string"==typeof t||null==t||e.objectMode||(r=new TypeError("Invalid non-string/buffer chunk"));return r}(t,r);if(o)e.emit("error",o);else if(null===r)t.reading=!1,function(e,t){if(t.ended)return;if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,xt(e)}(e,t);else if(t.objectMode||r&&r.length>0)if(t.ended&&!i){var s=new Error("stream.push() after EOF");e.emit("error",s)}else if(t.endEmitted&&i){var a=new Error("stream.unshift() after end event");e.emit("error",a)}else{var u;!t.decoder||i||n||(r=t.decoder.write(r),u=!t.objectMode&&0===r.length),i||(t.reading=!1),u||(t.flowing&&0===t.length&&!t.sync?(e.emit("data",r),e.read(0)):(t.length+=t.objectMode?1:r.length,i?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&xt(e))),function(e,t){t.readingMore||(t.readingMore=!0,Ue(Ct,e,t))}(e,t)}else i||(t.reading=!1);return function(e){return!e.ended&&(e.needReadable||e.lengtht.highWaterMark&&(t.highWaterMark=function(e){return e>=Lt?e=Lt:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function xt(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(St("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?Ue(Pt,e):Pt(e))}function Pt(e){St("emit readable"),e.emit("readable"),Ut(e)}function Ct(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=t.length?(r=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):r=function(e,t,r){var n;eo.length?o.length:e;if(s===o.length?i+=o:i+=o.slice(0,e),0===(e-=s)){s===o.length?(++n,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=o.slice(s));break}++n}return t.length-=n,i}(e,t):function(e,t){var r=N.allocUnsafe(e),n=t.head,i=1;n.data.copy(r),e-=n.data.length;for(;n=n.next;){var o=n.data,s=e>o.length?o.length:e;if(o.copy(r,r.length-e,0,s),0===(e-=s)){s===o.length?(++i,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=o.slice(s));break}++i}return t.length-=i,r}(e,t);return n}(e,t.buffer,t.decoder),r);var r}function It(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,Ue(zt,t,e))}function zt(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function Yt(e,t){for(var r=0,n=e.length;r=t.highWaterMark||t.ended))return St("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?It(this):xt(this),null;if(0===(e=kt(e,t))&&t.ended)return 0===t.length&&It(this),null;var n,i=t.needReadable;return St("need readable",i),(0===t.length||t.length-e0?Dt(e,t):null)?(t.needReadable=!0,e=0):t.length-=e,0===t.length&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&It(this)),null!==n&&this.emit("data",n),n},At.prototype._read=function(e){this.emit("error",new Error("not implemented"))},At.prototype.pipe=function(e,t){var r=this,n=this._readableState;switch(n.pipesCount){case 0:n.pipes=e;break;case 1:n.pipes=[n.pipes,e];break;default:n.pipes.push(e)}n.pipesCount+=1,St("pipe count=%d opts=%j",n.pipesCount,t);var i=!t||!1!==t.end?s:h;function o(e){St("onunpipe"),e===r&&h()}function s(){St("onend"),e.end()}n.endEmitted?Ue(i):r.once("end",i),e.on("unpipe",o);var a=function(e){return function(){var t=e._readableState;St("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&e.listeners("data").length&&(t.flowing=!0,Ut(e))}}(r);e.on("drain",a);var u=!1;function h(){St("cleanup"),e.removeListener("close",d),e.removeListener("finish",p),e.removeListener("drain",a),e.removeListener("error",c),e.removeListener("unpipe",o),r.removeListener("end",s),r.removeListener("end",h),r.removeListener("data",l),u=!0,!n.awaitDrain||e._writableState&&!e._writableState.needDrain||a()}var f=!1;function l(t){St("ondata"),f=!1,!1!==e.write(t)||f||((1===n.pipesCount&&n.pipes===e||n.pipesCount>1&&-1!==Yt(n.pipes,e))&&!u&&(St("false write response, pause",r._readableState.awaitDrain),r._readableState.awaitDrain++,f=!0),r.pause())}function c(t){var r;St("onerror",t),g(),e.removeListener("error",c),0===(r="error",e.listeners(r).length)&&e.emit("error",t)}function d(){e.removeListener("finish",p),g()}function p(){St("onfinish"),e.removeListener("close",d),g()}function g(){St("unpipe"),r.unpipe(e)}return r.on("data",l),function(e,t,r){if("function"==typeof e.prependListener)return e.prependListener(t,r);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]:e.on(t,r)}(e,"error",c),e.once("close",d),e.once("finish",p),e.emit("pipe",r),n.flowing||(St("pipe resume"),r.resume()),e},At.prototype.unpipe=function(e){var t=this._readableState;if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this)),this;if(!e){var r=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;i-1))throw new TypeError("Unknown encoding: "+e);return this._writableState.defaultEncoding=e,this},Ht.prototype._write=function(e,t,r){r(new Error("not implemented"))},Ht.prototype._writev=null,Ht.prototype.end=function(e,t,r){var n=this._writableState;"function"==typeof e?(r=e,e=null,t=null):"function"==typeof t&&(r=t,t=null),null!=e&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),n.ending||n.finished||function(e,t,r){t.ending=!0,Zt(e,t),r&&(t.finished?Ue(r):e.once("finish",r));t.ended=!0,e.writable=!1}(this,n,r)},Ze(tr,At);for(var Qt=Object.keys(Ht.prototype),Xt=0;Xt()=>{}}))("from-strided-array-stream"),cr=hr.Readable;function dr(r,n,a,h,f){var c,m,b;if(!(this instanceof dr))return arguments.length>4?new dr(r,n,a,h,f):new dr(r,n,a,h);if(!o(r))throw new TypeError(l("1MH2d",r));if(!t(n))throw new TypeError(l("1MH2y",n));if(!i(a))throw new TypeError(l("1MH2z",a));if(!o(h))throw new TypeError(l("1MH30",h));if(r>0&&(b=h+(r-1)*a,h>=n.length||b<0||b>=n.length))throw new RangeError(l("1MH1K"));if(c=s({},fr),arguments.length>4&&(m=function(e,t){return d(t)?p(t,"sep")&&(e.sep=t.sep,!y(e.sep))?new TypeError(l("1MH2W","sep",e.sep)):p(t,"objectMode")&&(e.objectMode=t.objectMode,!g(e.objectMode))?new TypeError(l("1MH2o","objectMode",e.objectMode)):p(t,"encoding")&&(e.encoding=t.encoding,!y(e.encoding)&&null!==e.encoding)?new TypeError(l("1MH7n","encoding",e.encoding)):p(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!v(e.highWaterMark))?new TypeError(l("1MH4k","highWaterMark",e.highWaterMark)):p(t,"serialize")&&(e.serialize=t.serialize,!w(e.serialize))?new TypeError(l("1MH6p","serialize",e.serialize)):null:new TypeError(l("1MH2V",t))}(c,f),m))throw m;return lr("Creating a readable stream configured with the following options: %s.",JSON.stringify(c)),cr.call(this,c),u(this,"_destroyed",!1),e(this,"_objectMode",c.objectMode),e(this,"_sep",c.sep),e(this,"_serialize",c.serialize||JSON.stringify),e(this,"_buffer",n),e(this,"_N",r),e(this,"_stride",a),e(this,"_offset",h),u(this,"_idx",h),u(this,"_i",0),this}function pr(e,t,r,n,i){var o;if(arguments.length>4){if(!d(o=i))throw new TypeError(l("1MH2V",o));o=s({},i)}else o={};return o.objectMode=!0,new dr(e,t,r,n,o)}function gr(e){var t;if(arguments.length){if(!d(e))throw new TypeError(l("1MH2V",e));t=s({},e)}else t={};return function(e,r,n,i){return new dr(e,r,n,i,t)}}a(dr,cr),e(dr.prototype,"_read",(function(){var e,t,r;if(!this._destroyed)for(e=!0;e;){if(t=null,this._i+=1,this._i>this._N)return lr("Finished iteration."),this.push(null);r=this._buffer[this._idx],lr("Value: %s. Idx: %d. Iter: %d.",JSON.stringify(r),this._idx,this._i),this._idx+=this._stride,!1===this._objectMode&&("string"==typeof(r=this._serialize(r))?r=1===this._i?h(r):h(this._sep+r):n(r)?this._i>1&&(r=f.concat([h(this._sep),r])):t=new Error(l("1MHA9",r))),t?this.emit("error",t):e=this.push(r)}})),e(dr.prototype,"destroy",(function(e){var t;return this._destroyed?(lr("Attempted to destroy an already destroyed stream."),this):(t=this,this._destroyed=!0,c((function(){e&&(lr("Stream was destroyed due to an error. Error: %s.",r(e)?e.message:JSON.stringify(e)),t.emit("error",e));lr("Closing the stream..."),t.emit("close")})),this)})),e(dr,"objectMode",pr),e(dr,"factory",gr);export{dr as default,gr as factory,pr as objectMode}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..b091e8a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/debug.js","../lib/main.js","../lib/validate.js","../lib/object_mode.js","../lib/factory.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar logger = require( 'debug' );\n\n\n// MAIN //\n\nvar debug = logger( 'from-strided-array-stream' );\n\n\n// EXPORTS //\n\nexport default debug;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar Readable = require( 'readable-stream' ).Readable;\nimport isCollection from '@stdlib/assert-is-collection';\nimport isError from '@stdlib/assert-is-error';\nimport isBuffer from '@stdlib/assert-is-buffer';\nimport { isPrimitive as isInteger } from '@stdlib/assert-is-integer';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport assign from '@stdlib/object-assign';\nimport inherit from '@stdlib/utils-inherit';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport setNonEnumerableReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport string2buffer from '@stdlib/buffer-from-string';\nimport Buffer from '@stdlib/buffer-ctor'; // TODO: replace Buffer.concat usage with stdlib pkg\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport nextTick from '@stdlib/utils-next-tick';\nimport DEFAULTS from './defaults.json';\nimport validate from './validate.js';\nimport debug from './debug.js';\n\n\n// FUNCTIONS //\n\n/**\n* Implements the `_read` method.\n*\n* @private\n* @param {number} size - number (of bytes) to read\n* @returns {void}\n*/\nfunction read() {\n\t/* eslint-disable no-invalid-this */\n\tvar FLG;\n\tvar err;\n\tvar v;\n\n\tif ( this._destroyed ) {\n\t\treturn;\n\t}\n\tFLG = true;\n\twhile ( FLG ) {\n\t\terr = null;\n\n\t\tthis._i += 1;\n\t\tif ( this._i > this._N ) {\n\t\t\tdebug( 'Finished iteration.' );\n\t\t\treturn this.push( null );\n\t\t}\n\t\tv = this._buffer[ this._idx ];\n\t\tdebug( 'Value: %s. Idx: %d. Iter: %d.', JSON.stringify( v ), this._idx, this._i );\n\n\t\tthis._idx += this._stride;\n\t\tif ( this._objectMode === false ) {\n\t\t\tv = this._serialize( v );\n\t\t\tif ( typeof v === 'string' ) {\n\t\t\t\tif ( this._i === 1 ) {\n\t\t\t\t\tv = string2buffer( v );\n\t\t\t\t} else {\n\t\t\t\t\tv = string2buffer( this._sep+v );\n\t\t\t\t}\n\t\t\t} else if ( isBuffer( v ) ) {\n\t\t\t\tif ( this._i > 1 ) {\n\t\t\t\t\tv = Buffer.concat( [ string2buffer( this._sep ), v ] );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\terr = new Error( format( '1MHA9', v ) );\n\t\t\t}\n\t\t}\n\t\tif ( err ) {\n\t\t\tthis.emit( 'error', err );\n\t\t} else {\n\t\t\tFLG = this.push( v );\n\t\t}\n\t}\n\n\t/* eslint-enable no-invalid-this */\n}\n\n/**\n* Gracefully destroys a stream, providing backward compatibility.\n*\n* @private\n* @param {(string|Object|Error)} [error] - error\n* @returns {StridedArrayStream} Stream instance\n*/\nfunction destroy( error ) {\n\t/* eslint-disable no-invalid-this */\n\tvar self;\n\tif ( this._destroyed ) {\n\t\tdebug( 'Attempted to destroy an already destroyed stream.' );\n\t\treturn this;\n\t}\n\tself = this;\n\tthis._destroyed = true;\n\n\tnextTick( close );\n\n\treturn this;\n\n\t/**\n\t* Closes a stream.\n\t*\n\t* @private\n\t*/\n\tfunction close() {\n\t\tif ( error ) {\n\t\t\tdebug( 'Stream was destroyed due to an error. Error: %s.', ( isError( error ) ) ? error.message : JSON.stringify( error ) );\n\t\t\tself.emit( 'error', error );\n\t\t}\n\t\tdebug( 'Closing the stream...' );\n\t\tself.emit( 'close' );\n\t}\n\n\t/* eslint-enable no-invalid-this */\n}\n\n\n// MAIN //\n\n/**\n* Stream constructor for generating a readable stream from an array-like object.\n*\n* @constructor\n* @param {NonNegativeInteger} N - number of values to stream\n* @param {Collection} buffer - source value\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @param {Options} [options] - stream options\n* @param {boolean} [options.objectMode=false] - specifies whether the stream should operate in object mode\n* @param {(string|null)} [options.encoding=null] - specifies how `Buffer` objects should be decoded to strings\n* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of bytes to store in an internal buffer before pausing streaming\n* @param {string} [options.sep='\\n'] - separator used to join streamed data\n* @param {Function} [options.serialize] - custom serialization function\n* @throws {TypeError} first argument must be a nonnegative integer\n* @throws {TypeError} second argument must be an array-like object\n* @throws {TypeError} third argument must be an integer\n* @throws {TypeError} fourth argument must be a nonnegative integer\n* @throws {RangeError} linear index cannot exceed array bounds\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {StridedArrayStream} Stream instance\n*\n* @example\n* import inspectStream from '@stdlib/streams-node-inspect-sink';\n* import Float64Array from '@stdlib/array-float64';\n* import randu from '@stdlib/random-base-randu';\n*\n* function log( chunk ) {\n* console.log( chunk.toString() );\n* }\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var stream = new StridedArrayStream( arr.length, arr, 1, 0 );\n*\n* stream.pipe( inspectStream( log ) );\n*/\nfunction StridedArrayStream( N, buffer, stride, offset, options ) {\n\tvar opts;\n\tvar err;\n\tvar i;\n\tif ( !( this instanceof StridedArrayStream ) ) {\n\t\tif ( arguments.length > 4 ) {\n\t\t\treturn new StridedArrayStream( N, buffer, stride, offset, options );\n\t\t}\n\t\treturn new StridedArrayStream( N, buffer, stride, offset );\n\t}\n\tif ( !isNonNegativeInteger( N ) ) {\n\t\tthrow new TypeError( format( '1MH2d', N ) );\n\t}\n\tif ( !isCollection( buffer ) ) {\n\t\tthrow new TypeError( format( '1MH2y', buffer ) );\n\t}\n\tif ( !isInteger( stride ) ) {\n\t\tthrow new TypeError( format( '1MH2z', stride ) );\n\t}\n\tif ( !isNonNegativeInteger( offset ) ) {\n\t\tthrow new TypeError( format( '1MH30', offset ) );\n\t}\n\tif ( N > 0 ) {\n\t\ti = offset + ((N-1)*stride);\n\t\tif ( offset >= buffer.length || i < 0 || i >= buffer.length ) {\n\t\t\tthrow new RangeError( format('1MH1K') );\n\t\t}\n\t}\n\topts = assign( {}, DEFAULTS );\n\tif ( arguments.length > 4 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Make the stream a readable stream:\n\tdebug( 'Creating a readable stream configured with the following options: %s.', JSON.stringify( opts ) );\n\tReadable.call( this, opts );\n\n\t// Destruction state:\n\tsetNonEnumerable( this, '_destroyed', false );\n\n\t// Cache whether the stream is operating in object mode:\n\tsetNonEnumerableReadOnly( this, '_objectMode', opts.objectMode );\n\n\t// Cache the separator:\n\tsetNonEnumerableReadOnly( this, '_sep', opts.sep );\n\n\t// Define the serialization function:\n\tsetNonEnumerableReadOnly( this, '_serialize', opts.serialize || JSON.stringify );\n\n\t// Cache the data source:\n\tsetNonEnumerableReadOnly( this, '_buffer', buffer );\n\n\t// Cache the strided array parameters:\n\tsetNonEnumerableReadOnly( this, '_N', N );\n\tsetNonEnumerableReadOnly( this, '_stride', stride );\n\tsetNonEnumerableReadOnly( this, '_offset', offset );\n\tsetNonEnumerable( this, '_idx', offset );\n\n\t// Initialize an iteration counter:\n\tsetNonEnumerable( this, '_i', 0 );\n\n\treturn this;\n}\n\n/*\n* Inherit from the `Readable` prototype.\n*/\ninherit( StridedArrayStream, Readable );\n\n/**\n* Implements the `_read` method.\n*\n* @private\n* @name _read\n* @memberof StridedArrayStream.prototype\n* @type {Function}\n* @param {number} size - number (of bytes) to read\n* @returns {void}\n*/\nsetNonEnumerableReadOnly( StridedArrayStream.prototype, '_read', read );\n\n/**\n* Gracefully destroys a stream, providing backward compatibility.\n*\n* @name destroy\n* @memberof StridedArrayStream.prototype\n* @type {Function}\n* @param {(string|Object|Error)} [error] - error\n* @returns {StridedArrayStream} Stream instance\n*/\nsetNonEnumerableReadOnly( StridedArrayStream.prototype, 'destroy', destroy );\n\n\n// EXPORTS //\n\nexport default StridedArrayStream;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport { isPrimitive as isNonNegative } from '@stdlib/assert-is-nonnegative-number';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isFunction from '@stdlib/assert-is-function';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {string} [options.sep] - separator used to join streamed data\n* @param {boolean} [options.objectMode] - specifies whether a stream should operate in object mode\n* @param {(string|null)} [options.encoding] - specifies how `Buffer` objects should be decoded to `strings`\n* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of bytes to store in the internal buffer before pausing streaming\n* @param {Function} [options.serialize] - custom serialization function\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'objectMode': true\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '1MH2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'sep' ) ) {\n\t\topts.sep = options.sep;\n\t\tif ( !isString( opts.sep ) ) {\n\t\t\treturn new TypeError( format( '1MH2W', 'sep', opts.sep ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'objectMode' ) ) {\n\t\topts.objectMode = options.objectMode;\n\t\tif ( !isBoolean( opts.objectMode ) ) {\n\t\t\treturn new TypeError( format( '1MH2o', 'objectMode', opts.objectMode ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'encoding' ) ) {\n\t\topts.encoding = options.encoding;\n\t\tif ( !isString( opts.encoding ) && opts.encoding !== null ) {\n\t\t\treturn new TypeError( format( '1MH7n', 'encoding', opts.encoding ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegative( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '1MH4k', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'serialize' ) ) {\n\t\topts.serialize = options.serialize;\n\t\tif ( !isFunction( opts.serialize ) ) {\n\t\t\treturn new TypeError( format( '1MH6p', 'serialize', opts.serialize ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport assign from '@stdlib/object-assign';\nimport StridedArrayStream from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns an \"objectMode\" readable stream from an array-like value.\n*\n* @param {NonNegativeInteger} N - number of values to stream\n* @param {Collection} buffer - source value\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @param {Options} [options] - stream options\n* @param {(string|null)} [options.encoding=null] - specifies how `Buffer` objects should be decoded to `strings`\n* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of objects to store in an internal buffer before pausing streaming\n* @throws {TypeError} first argument must be a nonnegative integer\n* @throws {TypeError} second argument must be an array-like object\n* @throws {TypeError} third argument must be an integer\n* @throws {TypeError} fourth argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {StridedArrayStream} Stream instance\n*\n* @example\n* import inspectStream from '@stdlib/streams-node-inspect-sink';\n* import Float64Array from '@stdlib/array-float64';\n* import randu from '@stdlib/random-base-randu';\n*\n* function log( v ) {\n* console.log( v );\n* }\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var stream = objectMode( arr.length, arr, 1, 0 );\n*\n* stream.pipe( inspectStream.objectMode( log ) );\n*/\nfunction objectMode( N, buffer, stride, offset, options ) {\n\tvar opts;\n\tif ( arguments.length > 4 ) {\n\t\topts = options;\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '1MH2V', opts ) );\n\t\t}\n\t\topts = assign( {}, options );\n\t} else {\n\t\topts = {};\n\t}\n\topts.objectMode = true;\n\treturn new StridedArrayStream( N, buffer, stride, offset, opts );\n}\n\n\n// EXPORTS //\n\nexport default objectMode;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport assign from '@stdlib/object-assign';\nimport StridedArrayStream from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating readable streams from strided array-like values.\n*\n* @param {Options} [options] - stream options\n* @param {boolean} [options.objectMode=false] - specifies whether a stream should operate in object mode\n* @param {(string|null)} [options.encoding=null] - specifies how `Buffer` objects should be decoded to `strings`\n* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of bytes to store in an internal buffer before pausing streaming\n* @param {string} [options.sep='\\n'] - separator used to join streamed data\n* @param {Function} [options.serialize] - custom serialization function\n* @throws {TypeError} options argument must be an object\n* @returns {Function} stream factory\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import randu from '@stdlib/random-base-randu';\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var opts = {\n* 'sep': ',',\n* 'objectMode': false,\n* 'encoding': 'utf8',\n* 'highWaterMark': 64\n* };\n*\n* var createStream = factory( opts );\n*\n* // Create 10 identically configured streams...\n* var streams = [];\n* for ( i = 0; i < 10; i++ ) {\n* streams.push( createStream( arr.length, arr, 1, 0 ) );\n* }\n*/\nfunction factory( options ) {\n\tvar opts;\n\tif ( arguments.length ) {\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1MH2V', options ) );\n\t\t}\n\t\topts = assign( {}, options );\n\t} else {\n\t\topts = {};\n\t}\n\treturn createStream;\n\n\t/**\n\t* Returns a readable stream from an array-like object.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} N - number of values to stream\n\t* @param {Collection} buffer - source array-like object\n\t* @param {integer} stride - stride length\n\t* @param {NonNegativeInteger} offset - starting index\n\t* @throws {TypeError} must provide an array-like object\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {StridedArrayStream} Stream instance\n\t*/\n\tfunction createStream( N, buffer, stride, offset ) {\n\t\treturn new StridedArrayStream( N, buffer, stride, offset, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create a readable stream from a strided array-like value.\n*\n* @module @stdlib/streams-node-from-strided-array\n*\n* @example\n* import inspectStream from '@stdlib/streams-node-inspect-sink';\n* import Float64Array from '@stdlib/array-float64';\n* import randu from '@stdlib/random-base-randu';\n* import stridedArrayStream from '@stdlib/streams-node-from-strided-array';\n*\n* function log( chunk ) {\n* console.log( chunk.toString() );\n* }\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var stream = stridedArrayStream( arr.length, arr, 1, 0 );\n*\n* stream.pipe( inspectStream( log ) );\n*\n* @example\n* import Float64Array from '@stdlib/array-float64';\n* import randu from '@stdlib/random-base-randu';\n* import stridedArrayStream from '@stdlib/streams-node-from-strided-array';\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var opts = {\n* 'sep': ',',\n* 'objectMode': false,\n* 'encoding': 'utf8',\n* 'highWaterMark': 64\n* };\n*\n* var createStream = stridedArrayStream.factory( opts );\n*\n* // Create 10 identically configured streams...\n* var streams = [];\n* for ( i = 0; i < 10; i++ ) {\n* streams.push( createStream( arr.length, arr, 1, 0 ) );\n* }\n*\n* @example\n* import inspectStream from '@stdlib/streams-node-inspect-sink';\n* import Float64Array from '@stdlib/array-float64';\n* import randu from '@stdlib/random-base-randu';\n* import stridedArrayStream from '@stdlib/streams-node-from-strided-array';\n*\n* function log( v ) {\n* console.log( v );\n* }\n*\n* var arr = new Float64Array( 10 );\n* var i;\n* for ( i = 0; i < arr.length; i++ ) {\n* arr[ i ] = randu();\n* }\n*\n* var stream = stridedArrayStream.objectMode( arr.length, arr, 1, 0 );\n*\n* stream.pipe( inspectStream.objectMode( log ) );\n*/\n\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport objectMode from './object_mode.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'objectMode', objectMode );\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["debug","logger","Readable","require$$0","StridedArrayStream","N","buffer","stride","offset","options","opts","err","i","this","arguments","length","isNonNegativeInteger","TypeError","format","isCollection","isInteger","RangeError","assign","DEFAULTS","isObject","hasOwnProp","sep","isString","objectMode","isBoolean","encoding","highWaterMark","isNonNegative","serialize","isFunction","validate","JSON","stringify","call","setNonEnumerable","setNonEnumerableReadOnly","factory","inherit","prototype","FLG","v","_destroyed","_i","_N","push","_buffer","_idx","_stride","_objectMode","_serialize","string2buffer","_sep","isBuffer","Buffer","concat","Error","emit","error","self","nextTick","isError","message","setReadOnly","main"],"mappings":";;goxDA2BIA,wDAAQC,CAAQ,6BCLhBC,GAAWC,GAA6BD,SA+J5C,SAASE,GAAoBC,EAAGC,EAAQC,EAAQC,EAAQC,GACvD,IAAIC,EACAC,EACAC,EACJ,KAAQC,gBAAgBT,IACvB,OAAKU,UAAUC,OAAS,EAChB,IAAIX,GAAoBC,EAAGC,EAAQC,EAAQC,EAAQC,GAEpD,IAAIL,GAAoBC,EAAGC,EAAQC,EAAQC,GAEnD,IAAMQ,EAAsBX,GAC3B,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAEvC,IAAMc,EAAcb,GACnB,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMc,EAAWb,GAChB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMS,EAAsBR,GAC3B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKH,EAAI,IACRO,EAAIJ,GAAWH,EAAE,GAAGE,EACfC,GAAUF,EAAOS,QAAUH,EAAI,GAAKA,GAAKN,EAAOS,QACpD,MAAM,IAAIM,WAAYH,EAAO,UAI/B,GADAR,EAAOY,EAAQ,GAAIC,IACdT,UAAUC,OAAS,IACvBJ,EC3JF,SAAmBD,EAAMD,GACxB,OAAMe,EAAUf,GAGXgB,EAAYhB,EAAS,SACzBC,EAAKgB,IAAMjB,EAAQiB,KACbC,EAAUjB,EAAKgB,MACb,IAAIT,UAAWC,EAAQ,QAAS,MAAOR,EAAKgB,MAGhDD,EAAYhB,EAAS,gBACzBC,EAAKkB,WAAanB,EAAQmB,YACpBC,EAAWnB,EAAKkB,aACd,IAAIX,UAAWC,EAAQ,QAAS,aAAcR,EAAKkB,aAGvDH,EAAYhB,EAAS,cACzBC,EAAKoB,SAAWrB,EAAQqB,UAClBH,EAAUjB,EAAKoB,WAAgC,OAAlBpB,EAAKoB,UAChC,IAAIb,UAAWC,EAAQ,QAAS,WAAYR,EAAKoB,WAGrDL,EAAYhB,EAAS,mBACzBC,EAAKqB,cAAgBtB,EAAQsB,eACvBC,EAAetB,EAAKqB,gBAClB,IAAId,UAAWC,EAAQ,QAAS,gBAAiBR,EAAKqB,gBAG1DN,EAAYhB,EAAS,eACzBC,EAAKuB,UAAYxB,EAAQwB,WACnBC,EAAYxB,EAAKuB,YACf,IAAIhB,UAAWC,EAAQ,QAAS,YAAaR,EAAKuB,YAGpD,KAhCC,IAAIhB,UAAWC,EAAQ,QAAST,GAiCzC,CDwHQ0B,CAAUzB,EAAMD,GACjBE,GACJ,MAAMA,EA+BR,OA3BAX,GAAO,wEAAyEoC,KAAKC,UAAW3B,IAChGR,GAASoC,KAAMzB,KAAMH,GAGrB6B,EAAkB1B,KAAM,cAAc,GAGtC2B,EAA0B3B,KAAM,cAAeH,EAAKkB,YAGpDY,EAA0B3B,KAAM,OAAQH,EAAKgB,KAG7Cc,EAA0B3B,KAAM,aAAcH,EAAKuB,WAAaG,KAAKC,WAGrEG,EAA0B3B,KAAM,UAAWP,GAG3CkC,EAA0B3B,KAAM,KAAMR,GACtCmC,EAA0B3B,KAAM,UAAWN,GAC3CiC,EAA0B3B,KAAM,UAAWL,GAC3C+B,EAAkB1B,KAAM,OAAQL,GAGhC+B,EAAkB1B,KAAM,KAAM,GAEvBA,IACR,CElLA,SAASe,GAAYvB,EAAGC,EAAQC,EAAQC,EAAQC,GAC/C,IAAIC,EACJ,GAAKI,UAAUC,OAAS,EAAI,CAE3B,IAAMS,EADNd,EAAOD,GAEN,MAAM,IAAIQ,UAAWC,EAAQ,QAASR,IAEvCA,EAAOY,EAAQ,GAAIb,EACrB,MACEC,EAAO,CAAA,EAGR,OADAA,EAAKkB,YAAa,EACX,IAAIxB,GAAoBC,EAAGC,EAAQC,EAAQC,EAAQE,EAC3D,CCbA,SAAS+B,GAAShC,GACjB,IAAIC,EACJ,GAAKI,UAAUC,OAAS,CACvB,IAAMS,EAAUf,GACf,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvCC,EAAOY,EAAQ,GAAIb,EACrB,MACEC,EAAO,CAAA,EAER,OAeA,SAAuBL,EAAGC,EAAQC,EAAQC,GACzC,OAAO,IAAIJ,GAAoBC,EAAGC,EAAQC,EAAQC,EAAQE,EAC1D,CACF,CH2JAgC,EAAStC,GAAoBF,IAY7BsC,EAA0BpC,GAAmBuC,UAAW,SApNxD,WAEC,IAAIC,EACAjC,EACAkC,EAEJ,IAAKhC,KAAKiC,WAIV,IADAF,GAAM,EACEA,GAAM,CAIb,GAHAjC,EAAM,KAENE,KAAKkC,IAAM,EACNlC,KAAKkC,GAAKlC,KAAKmC,GAEnB,OADAhD,GAAO,uBACAa,KAAKoC,KAAM,MAEnBJ,EAAIhC,KAAKqC,QAASrC,KAAKsC,MACvBnD,GAAO,gCAAiCoC,KAAKC,UAAWQ,GAAKhC,KAAKsC,KAAMtC,KAAKkC,IAE7ElC,KAAKsC,MAAQtC,KAAKuC,SACQ,IAArBvC,KAAKwC,cAES,iBADlBR,EAAIhC,KAAKyC,WAAYT,IAGnBA,EADgB,IAAZhC,KAAKkC,GACLQ,EAAeV,GAEfU,EAAe1C,KAAK2C,KAAKX,GAEnBY,EAAUZ,GAChBhC,KAAKkC,GAAK,IACdF,EAAIa,EAAOC,OAAQ,CAAEJ,EAAe1C,KAAK2C,MAAQX,KAGlDlC,EAAM,IAAIiD,MAAO1C,EAAQ,QAAS2B,KAG/BlC,EACJE,KAAKgD,KAAM,QAASlD,GAEpBiC,EAAM/B,KAAKoC,KAAMJ,EAElB,CAGF,IAiLAL,EAA0BpC,GAAmBuC,UAAW,WAxKxD,SAAkBmB,GAEjB,IAAIC,EACJ,OAAKlD,KAAKiC,YACT9C,GAAO,qDACAa,OAERkD,EAAOlD,KACPA,KAAKiC,YAAa,EAElBkB,GASA,WACMF,IACJ9D,GAAO,mDAAsDiE,EAASH,GAAYA,EAAMI,QAAU9B,KAAKC,UAAWyB,IAClHC,EAAKF,KAAM,QAASC,IAErB9D,GAAO,yBACP+D,EAAKF,KAAM,QACX,IAdMhD,KAiBR,II/BAsD,EAAAC,GAAA,aAAAxC,IACAuC,EAAAC,GAAA,UAAA3B"} \ No newline at end of file diff --git a/lib/debug.js b/lib/debug.js deleted file mode 100644 index 78729ac..0000000 --- a/lib/debug.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// MAIN // - -var debug = logger( 'from-strided-array-stream' ); - - -// EXPORTS // - -module.exports = debug; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 870b0e1..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "objectMode": false, - "encoding": null, - "sep": "\n" -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index b19b1f9..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var assign = require( '@stdlib/object-assign' ); -var StridedArrayStream = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating readable streams from strided array-like values. -* -* @param {Options} [options] - stream options -* @param {boolean} [options.objectMode=false] - specifies whether a stream should operate in object mode -* @param {(string|null)} [options.encoding=null] - specifies how `Buffer` objects should be decoded to `strings` -* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of bytes to store in an internal buffer before pausing streaming -* @param {string} [options.sep='\n'] - separator used to join streamed data -* @param {Function} [options.serialize] - custom serialization function -* @throws {TypeError} options argument must be an object -* @returns {Function} stream factory -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var randu = require( '@stdlib/random-base-randu' ); -* -* var arr = new Float64Array( 10 ); -* var i; -* for ( i = 0; i < arr.length; i++ ) { -* arr[ i ] = randu(); -* } -* -* var opts = { -* 'sep': ',', -* 'objectMode': false, -* 'encoding': 'utf8', -* 'highWaterMark': 64 -* }; -* -* var createStream = factory( opts ); -* -* // Create 10 identically configured streams... -* var streams = []; -* for ( i = 0; i < 10; i++ ) { -* streams.push( createStream( arr.length, arr, 1, 0 ) ); -* } -*/ -function factory( options ) { - var opts; - if ( arguments.length ) { - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - opts = assign( {}, options ); - } else { - opts = {}; - } - return createStream; - - /** - * Returns a readable stream from an array-like object. - * - * @private - * @param {NonNegativeInteger} N - number of values to stream - * @param {Collection} buffer - source array-like object - * @param {integer} stride - stride length - * @param {NonNegativeInteger} offset - starting index - * @throws {TypeError} must provide an array-like object - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {StridedArrayStream} Stream instance - */ - function createStream( N, buffer, stride, offset ) { - return new StridedArrayStream( N, buffer, stride, offset, opts ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 825a6c8..0000000 --- a/lib/index.js +++ /dev/null @@ -1,110 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create a readable stream from a strided array-like value. -* -* @module @stdlib/streams-node-from-strided-array -* -* @example -* var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var randu = require( '@stdlib/random-base-randu' ); -* var stridedArrayStream = require( '@stdlib/streams-node-from-strided-array' ); -* -* function log( chunk ) { -* console.log( chunk.toString() ); -* } -* -* var arr = new Float64Array( 10 ); -* var i; -* for ( i = 0; i < arr.length; i++ ) { -* arr[ i ] = randu(); -* } -* -* var stream = stridedArrayStream( arr.length, arr, 1, 0 ); -* -* stream.pipe( inspectStream( log ) ); -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var randu = require( '@stdlib/random-base-randu' ); -* var stridedArrayStream = require( '@stdlib/streams-node-from-strided-array' ); -* -* var arr = new Float64Array( 10 ); -* var i; -* for ( i = 0; i < arr.length; i++ ) { -* arr[ i ] = randu(); -* } -* -* var opts = { -* 'sep': ',', -* 'objectMode': false, -* 'encoding': 'utf8', -* 'highWaterMark': 64 -* }; -* -* var createStream = stridedArrayStream.factory( opts ); -* -* // Create 10 identically configured streams... -* var streams = []; -* for ( i = 0; i < 10; i++ ) { -* streams.push( createStream( arr.length, arr, 1, 0 ) ); -* } -* -* @example -* var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var randu = require( '@stdlib/random-base-randu' ); -* var stridedArrayStream = require( '@stdlib/streams-node-from-strided-array' ); -* -* function log( v ) { -* console.log( v ); -* } -* -* var arr = new Float64Array( 10 ); -* var i; -* for ( i = 0; i < arr.length; i++ ) { -* arr[ i ] = randu(); -* } -* -* var stream = stridedArrayStream.objectMode( arr.length, arr, 1, 0 ); -* -* stream.pipe( inspectStream.objectMode( log ) ); -*/ - - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var objectMode = require( './object_mode.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'objectMode', objectMode ); -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 62e2ca5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,279 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var Readable = require( 'readable-stream' ).Readable; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isError = require( '@stdlib/assert-is-error' ); -var isBuffer = require( '@stdlib/assert-is-buffer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var assign = require( '@stdlib/object-assign' ); -var inherit = require( '@stdlib/utils-inherit' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var string2buffer = require( '@stdlib/buffer-from-string' ); -var Buffer = require( '@stdlib/buffer-ctor' ); // TODO: replace Buffer.concat usage with stdlib pkg -var format = require( '@stdlib/string-format' ); -var nextTick = require( '@stdlib/utils-next-tick' ); -var DEFAULTS = require( './defaults.json' ); -var validate = require( './validate.js' ); -var debug = require( './debug.js' ); - - -// FUNCTIONS // - -/** -* Implements the `_read` method. -* -* @private -* @param {number} size - number (of bytes) to read -* @returns {void} -*/ -function read() { - /* eslint-disable no-invalid-this */ - var FLG; - var err; - var v; - - if ( this._destroyed ) { - return; - } - FLG = true; - while ( FLG ) { - err = null; - - this._i += 1; - if ( this._i > this._N ) { - debug( 'Finished iteration.' ); - return this.push( null ); - } - v = this._buffer[ this._idx ]; - debug( 'Value: %s. Idx: %d. Iter: %d.', JSON.stringify( v ), this._idx, this._i ); - - this._idx += this._stride; - if ( this._objectMode === false ) { - v = this._serialize( v ); - if ( typeof v === 'string' ) { - if ( this._i === 1 ) { - v = string2buffer( v ); - } else { - v = string2buffer( this._sep+v ); - } - } else if ( isBuffer( v ) ) { - if ( this._i > 1 ) { - v = Buffer.concat( [ string2buffer( this._sep ), v ] ); - } - } else { - err = new Error( format( 'invalid operation. Serialization function must return a string or Buffer. Value: `%s`.', v ) ); - } - } - if ( err ) { - this.emit( 'error', err ); - } else { - FLG = this.push( v ); - } - } - - /* eslint-enable no-invalid-this */ -} - -/** -* Gracefully destroys a stream, providing backward compatibility. -* -* @private -* @param {(string|Object|Error)} [error] - error -* @returns {StridedArrayStream} Stream instance -*/ -function destroy( error ) { - /* eslint-disable no-invalid-this */ - var self; - if ( this._destroyed ) { - debug( 'Attempted to destroy an already destroyed stream.' ); - return this; - } - self = this; - this._destroyed = true; - - nextTick( close ); - - return this; - - /** - * Closes a stream. - * - * @private - */ - function close() { - if ( error ) { - debug( 'Stream was destroyed due to an error. Error: %s.', ( isError( error ) ) ? error.message : JSON.stringify( error ) ); - self.emit( 'error', error ); - } - debug( 'Closing the stream...' ); - self.emit( 'close' ); - } - - /* eslint-enable no-invalid-this */ -} - - -// MAIN // - -/** -* Stream constructor for generating a readable stream from an array-like object. -* -* @constructor -* @param {NonNegativeInteger} N - number of values to stream -* @param {Collection} buffer - source value -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index -* @param {Options} [options] - stream options -* @param {boolean} [options.objectMode=false] - specifies whether the stream should operate in object mode -* @param {(string|null)} [options.encoding=null] - specifies how `Buffer` objects should be decoded to strings -* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of bytes to store in an internal buffer before pausing streaming -* @param {string} [options.sep='\n'] - separator used to join streamed data -* @param {Function} [options.serialize] - custom serialization function -* @throws {TypeError} first argument must be a nonnegative integer -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an integer -* @throws {TypeError} fourth argument must be a nonnegative integer -* @throws {RangeError} linear index cannot exceed array bounds -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {StridedArrayStream} Stream instance -* -* @example -* var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var randu = require( '@stdlib/random-base-randu' ); -* -* function log( chunk ) { -* console.log( chunk.toString() ); -* } -* -* var arr = new Float64Array( 10 ); -* var i; -* for ( i = 0; i < arr.length; i++ ) { -* arr[ i ] = randu(); -* } -* -* var stream = new StridedArrayStream( arr.length, arr, 1, 0 ); -* -* stream.pipe( inspectStream( log ) ); -*/ -function StridedArrayStream( N, buffer, stride, offset, options ) { - var opts; - var err; - var i; - if ( !( this instanceof StridedArrayStream ) ) { - if ( arguments.length > 4 ) { - return new StridedArrayStream( N, buffer, stride, offset, options ); - } - return new StridedArrayStream( N, buffer, stride, offset ); - } - if ( !isNonNegativeInteger( N ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', N ) ); - } - if ( !isCollection( buffer ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', buffer ) ); - } - if ( !isInteger( stride ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', stride ) ); - } - if ( !isNonNegativeInteger( offset ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%s`.', offset ) ); - } - if ( N > 0 ) { - i = offset + ((N-1)*stride); - if ( offset >= buffer.length || i < 0 || i >= buffer.length ) { - throw new RangeError( 'invalid arguments. Strided array parameters are incompatible with the provided array-like object. Linear index exceeds array bounds.' ); - } - } - opts = assign( {}, DEFAULTS ); - if ( arguments.length > 4 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - // Make the stream a readable stream: - debug( 'Creating a readable stream configured with the following options: %s.', JSON.stringify( opts ) ); - Readable.call( this, opts ); - - // Destruction state: - setNonEnumerable( this, '_destroyed', false ); - - // Cache whether the stream is operating in object mode: - setNonEnumerableReadOnly( this, '_objectMode', opts.objectMode ); - - // Cache the separator: - setNonEnumerableReadOnly( this, '_sep', opts.sep ); - - // Define the serialization function: - setNonEnumerableReadOnly( this, '_serialize', opts.serialize || JSON.stringify ); - - // Cache the data source: - setNonEnumerableReadOnly( this, '_buffer', buffer ); - - // Cache the strided array parameters: - setNonEnumerableReadOnly( this, '_N', N ); - setNonEnumerableReadOnly( this, '_stride', stride ); - setNonEnumerableReadOnly( this, '_offset', offset ); - setNonEnumerable( this, '_idx', offset ); - - // Initialize an iteration counter: - setNonEnumerable( this, '_i', 0 ); - - return this; -} - -/* -* Inherit from the `Readable` prototype. -*/ -inherit( StridedArrayStream, Readable ); - -/** -* Implements the `_read` method. -* -* @private -* @name _read -* @memberof StridedArrayStream.prototype -* @type {Function} -* @param {number} size - number (of bytes) to read -* @returns {void} -*/ -setNonEnumerableReadOnly( StridedArrayStream.prototype, '_read', read ); - -/** -* Gracefully destroys a stream, providing backward compatibility. -* -* @name destroy -* @memberof StridedArrayStream.prototype -* @type {Function} -* @param {(string|Object|Error)} [error] - error -* @returns {StridedArrayStream} Stream instance -*/ -setNonEnumerableReadOnly( StridedArrayStream.prototype, 'destroy', destroy ); - - -// EXPORTS // - -module.exports = StridedArrayStream; diff --git a/lib/object_mode.js b/lib/object_mode.js deleted file mode 100644 index c0c7043..0000000 --- a/lib/object_mode.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var assign = require( '@stdlib/object-assign' ); -var StridedArrayStream = require( './main.js' ); - - -// MAIN // - -/** -* Returns an "objectMode" readable stream from an array-like value. -* -* @param {NonNegativeInteger} N - number of values to stream -* @param {Collection} buffer - source value -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index -* @param {Options} [options] - stream options -* @param {(string|null)} [options.encoding=null] - specifies how `Buffer` objects should be decoded to `strings` -* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of objects to store in an internal buffer before pausing streaming -* @throws {TypeError} first argument must be a nonnegative integer -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an integer -* @throws {TypeError} fourth argument must be a nonnegative integer -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {StridedArrayStream} Stream instance -* -* @example -* var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var randu = require( '@stdlib/random-base-randu' ); -* -* function log( v ) { -* console.log( v ); -* } -* -* var arr = new Float64Array( 10 ); -* var i; -* for ( i = 0; i < arr.length; i++ ) { -* arr[ i ] = randu(); -* } -* -* var stream = objectMode( arr.length, arr, 1, 0 ); -* -* stream.pipe( inspectStream.objectMode( log ) ); -*/ -function objectMode( N, buffer, stride, offset, options ) { - var opts; - if ( arguments.length > 4 ) { - opts = options; - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); - } - opts = assign( {}, options ); - } else { - opts = {}; - } - opts.objectMode = true; - return new StridedArrayStream( N, buffer, stride, offset, opts ); -} - - -// EXPORTS // - -module.exports = objectMode; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2f4fce4..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,97 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNonNegative = require( '@stdlib/assert-is-nonnegative-number' ).isPrimitive; -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isFunction = require( '@stdlib/assert-is-function' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {string} [options.sep] - separator used to join streamed data -* @param {boolean} [options.objectMode] - specifies whether a stream should operate in object mode -* @param {(string|null)} [options.encoding] - specifies how `Buffer` objects should be decoded to `strings` -* @param {NonNegativeNumber} [options.highWaterMark] - specifies the maximum number of bytes to store in the internal buffer before pausing streaming -* @param {Function} [options.serialize] - custom serialization function -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'objectMode': true -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); - } - } - if ( hasOwnProp( options, 'objectMode' ) ) { - opts.objectMode = options.objectMode; - if ( !isBoolean( opts.objectMode ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'objectMode', opts.objectMode ) ); - } - } - if ( hasOwnProp( options, 'encoding' ) ) { - opts.encoding = options.encoding; - if ( !isString( opts.encoding ) && opts.encoding !== null ) { - return new TypeError( format( 'invalid option. `%s` option must be a string or null. Option: `%s`.', 'encoding', opts.encoding ) ); - } - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegative( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative number. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); - } - } - if ( hasOwnProp( options, 'serialize' ) ) { - opts.serialize = options.serialize; - if ( !isFunction( opts.serialize ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a function. Option: `%s`.', 'serialize', opts.serialize ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f1b0265..3a48e0c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create a readable stream from a strided array-like object.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-buffer": "^0.2.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-error": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-nonnegative-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/buffer-ctor": "^0.2.2", - "@stdlib/buffer-from-string": "^0.2.2", - "@stdlib/object-assign": "^0.2.2", - "@stdlib/string-format": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-property": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-inherit": "^0.2.2", - "@stdlib/utils-next-tick": "^0.2.2", - "debug": "^2.6.9", - "readable-stream": "^2.1.4", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/streams-node-inspect-sink": "^0.2.2", - "@stdlib/utils-parse-json": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "utilities", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..255963a --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 0d8d995..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,376 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var StridedArrayStream = require( './../lib/main.js' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a factory function', function test( t ) { - var createStream = factory(); - t.equal( typeof createStream, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a factory function (options)', function test( t ) { - var createStream = factory( {} ); - t.equal( typeof createStream, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided a nonnegative integer for the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory(); - createStream( value, [ 1, 2, 3 ], 1, 0 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an array-like object for the second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory(); - createStream( 1, value, 1, 0 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an integer for the third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory(); - createStream( 1, [ 1, 2, 3 ], value, 0 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided a nonnegative integer for the fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory(); - createStream( 1, [ 1, 2, 3 ], 1, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided a nonnegative integer for the first argument (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory(); - createStream( value, [ 1, 2, 3 ], 1, 0, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an array-like object for the second argument (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory(); - createStream( 1, value, 1, 0, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an integer for the third argument (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory(); - createStream( 1, [ 1, 2, 3 ], value, 0, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided a nonnegative integer for the fourth argument (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory(); - createStream( 1, [ 1, 2, 3 ], 1, value, {} ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - function badValue( value ) { - return function badValue() { - var createStream = factory( value ); - createStream( 3, [ 1, 2, 3 ], 1, 0 ); - }; - } -}); - -tape( 'if provided an invalid readable stream option, the function returns a function which throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory({ - 'highWaterMark': value - }); - createStream( 3, [ 1, 2, 3 ], 1, 0 ); - }; - } -}); - -tape( 'the function returns a factory function which creates stream instances', function test( t ) { - var createStream; - var arr; - var i; - - createStream = factory(); - arr = [ 1, 2, 3 ]; - - for ( i = 0; i < 10; i++ ) { - t.equal( createStream( arr.length, arr, 1, 0 ) instanceof StridedArrayStream, true, 'returns a stream instance' ); - } - t.end(); -}); - -tape( 'the function returns a factory function which creates stream instances (options)', function test( t ) { - var createStream; - var arr; - var i; - - createStream = factory( {} ); - arr = [ 1, 2, 3 ]; - - for ( i = 0; i < 10; i++ ) { - t.equal( createStream( arr.length, arr, 1, 0 ) instanceof StridedArrayStream, true, 'returns a stream instance' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3cb29b9..0000000 --- a/test/test.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var stridedArrayStream = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof stridedArrayStream, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to main export is a method to create a stream in object mode', function test( t ) { - t.equal( typeof stridedArrayStream.objectMode, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to main export is a method to create a stream factory', function test( t ) { - t.equal( typeof stridedArrayStream.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index f51d542..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Readable = require( 'readable-stream' ).Readable; -var isBuffer = require( '@stdlib/assert-is-buffer' ); -var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -var parseJSON = require( '@stdlib/utils-parse-json' ); -var string2buffer = require( '@stdlib/buffer-from-string' ); -var stridedArrayStream = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof stridedArrayStream, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a nonnegative integer for the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( value, [ 1, 2, 3 ], 1, 0 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object for the second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 1, value, 1, 0 ); - }; - } -}); - -tape( 'the function throws an error if not provided an integer for the third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 1, [ 1, 2, 3 ], value, 0 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for the fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 1, [ 1, 2, 3 ], 1, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for the first argument (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( value, [ 1, 2, 3 ], 1, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object for the second argument (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 1, value, 1, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an integer for the third argument (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 1, [ 1, 2, 3 ], value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for the fourth argument (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - void 0, - null, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 1, [ 1, 2, 3 ], 1, value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided strided array parameters which are incompatible with a provided array-like object (number of elements; positive stride)', function test( t ) { - var values; - var i; - - values = [ - 4, - 5, - 6, - 7 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( value, [ 1, 2, 3 ], 1, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided strided array parameters which are incompatible with a provided array-like object (number of elements; negative stride)', function test( t ) { - var values; - var i; - - values = [ - 4, - 5, - 6, - 7 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( value, [ 1, 2, 3 ], -1, 2 ); - }; - } -}); - -tape( 'the function throws an error if provided strided array parameters which are incompatible with a provided array-like object (positive stride)', function test( t ) { - var values; - var i; - - values = [ - 3, - 4, - 5, - 6, - 7 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 2, [ 1, 2, 3 ], value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided strided array parameters which are incompatible with a provided array-like object (negative stride)', function test( t ) { - var values; - var i; - - values = [ - -3, - -4, - -5, - -6, - -7 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 2, [ 1, 2, 3 ], value, 2 ); - }; - } -}); - -tape( 'the function throws an error if provided strided array parameters which are incompatible with a provided array-like object (offset; positive stride)', function test( t ) { - var values; - var i; - - values = [ - 20, - 30, - 40, - 50 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 1, [ 1, 2, 3 ], 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided strided array parameters which are incompatible with a provided array-like object (offset; negative stride)', function test( t ) { - var values; - var i; - - values = [ - 20, - 30, - 40, - 50 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 1, [ 1, 2, 3 ], -1, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - 'abc', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 3, [ 1, 2, 3 ], 1, 0, value ); - }; - } -}); - -tape( 'if provided an invalid readable stream option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - stridedArrayStream( 3, [ 1, 2, 3 ], 1, 0, { - 'objectMode': value - }); - }; - } -}); - -tape( 'the function is a constructor which returns a readable stream', function test( t ) { - var StridedArrayStream = stridedArrayStream; - var s; - - s = new StridedArrayStream( 3, [ 1, 2, 3 ], 1, 0 ); - t.equal( s instanceof Readable, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` operator', function test( t ) { - var StridedArrayStream = stridedArrayStream; - var s; - - s = stridedArrayStream( 3, [ 1, 2, 3 ], 1, 0 ); - t.equal( s instanceof StridedArrayStream, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a readable stream (no new)', function test( t ) { - var s = stridedArrayStream( 3, [ 1, 2, 3 ], 1, 0 ); - t.equal( s instanceof Readable, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the returned stream provides a method to destroy a stream (object)', function test( t ) { - var count = 0; - var s; - - s = stridedArrayStream( 8, [ 1, 2, 3, 4, 5, 6, 7, 8 ], 1, 0 ); - - t.equal( typeof s.destroy, 'function', 'has destroy method' ); - - s.on( 'error', onError ); - s.on( 'close', onClose ); - - s.destroy({ - 'message': 'beep' - }); - - function onError( err ) { - count += 1; - if ( err ) { - t.ok( true, err.message ); - } else { - t.ok( false, 'does not error' ); - } - if ( count === 2 ) { - t.end(); - } - } - function onClose() { - count += 1; - t.ok( true, 'stream closes' ); - if ( count === 2 ) { - t.end(); - } - } -}); - -tape( 'the returned stream provides a method to destroy a stream (error object)', function test( t ) { - var count = 0; - var s; - - s = stridedArrayStream( 8, [ 1, 2, 3, 4, 5, 6, 7, 8 ], 1, 0 ); - - t.equal( typeof s.destroy, 'function', 'has destroy method' ); - - s.on( 'error', onError ); - s.on( 'close', onClose ); - - s.destroy( new Error( 'beep' ) ); - - function onError( err ) { - count += 1; - if ( err ) { - t.ok( true, err.message ); - } else { - t.ok( false, 'does not error' ); - } - if ( count === 2 ) { - t.end(); - } - } - function onClose() { - count += 1; - t.ok( true, 'stream closes' ); - if ( count === 2 ) { - t.end(); - } - } -}); - -tape( 'the returned stream does not allow itself to be destroyed more than once', function test( t ) { - var s; - - s = stridedArrayStream( 8, [ 1, 2, 3, 4, 5, 6, 7, 8 ], 1, 0 ); - - s.on( 'error', onError ); - s.on( 'close', onClose ); - - // If the stream is closed twice, the test will error... - s.destroy(); - s.destroy(); - - function onClose() { - t.ok( true, 'stream closes' ); - t.end(); - } - function onError( err ) { - t.ok( false, err.message ); - } -}); - -tape( 'the constructor returns a stream which streams elements of a strided array-like object (array)', function test( t ) { - var expected; - var iStream; - var result; - var values; - var opts; - var s; - - values = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - expected = values.slice(); - - opts = { - 'sep': '\n' - }; - s = stridedArrayStream( values.length, values, 1, 0, opts ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - result = ''; - s.pipe( iStream ); - - function inspect( chunk ) { - t.equal( isBuffer( chunk ), true, 'returns a buffer' ); - result += chunk.toString(); - } - - function onEnd() { - var i; - - t.pass( 'stream ended' ); - - result = result.split( '\n' ); - t.equal( result.length, expected.length, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - t.equal( parseFloat( result[ i ] ), expected[ i ], 'returns expected value. i: ' + i + '.' ); - } - t.end(); - } -}); - -tape( 'the constructor returns a stream which streams elements of a strided array-like object (object mode; array)', function test( t ) { - var expected; - var iStream; - var values; - var opts; - var s; - var i; - - values = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - expected = [ 7, 5, 3, 1 ]; - - opts = { - 'objectMode': true - }; - s = stridedArrayStream( 4, values, -2, 6, opts ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - i = -1; - s.pipe( iStream ); - - function inspect( v ) { - i += 1; - t.equal( v, expected[ i ], 'returns expected value. i: '+i+'.' ); - } - - function onEnd() { - t.pass( 'stream ended' ); - t.end(); - } -}); - -tape( 'the constructor returns a stream which streams elements of a strided array-like object (large array)', function test( t ) { - var iStream; - var result; - var count; - var opts; - var arr; - var s; - var i; - - arr = []; - for ( i = 0; i < 1e6; i++ ) { - arr.push( i ); - } - - opts = { - 'sep': '\n' - }; - s = stridedArrayStream( arr.length, arr, 1, 0, opts ); - s.on( 'close', onClose ); - - iStream = inspectStream( inspect ); - - result = ''; - count = 0; - s.pipe( iStream ); - - function inspect( chunk ) { - count += 1; - t.equal( isBuffer( chunk ), true, 'returns a buffer' ); - result += chunk.toString(); - if ( count === 10 ) { - s.destroy(); - } - } - - function onClose() { - var i; - - t.pass( 'stream closed' ); - - result = result.split( '\n' ); - t.equal( result.length >= 10, true, 'has expected length' ); - for ( i = 0; i < 10; i++ ) { - t.equal( typeof parseFloat( result[ i ] ), 'number', 'returns expected value. i: ' + i + '.' ); - } - t.end(); - } -}); - -tape( 'the constructor returns a stream which streams elements of a strided array-like object (object mode; large array)', function test( t ) { - var iStream; - var opts; - var arr; - var s; - var i; - - arr = []; - for ( i = 0; i < 1e6; i++ ) { - arr.push( i ); - } - - opts = { - 'objectMode': true - }; - s = stridedArrayStream( arr.length, arr, 1, 0, opts ); - s.on( 'close', onClose ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - i = -1; - s.pipe( iStream ); - - function inspect( v ) { - i += 1; - t.equal( typeof v, 'number', 'returns expected value. i: '+i+'.' ); - if ( i === 10 ) { - return s.destroy(); - } - } - - function onClose() { - t.pass( 'stream closed' ); - t.end(); - } -}); - -tape( 'the constructor returns a stream which streams elements of a strided array-like object (empty)', function test( t ) { - var iStream; - var values; - var opts; - var s; - - values = []; - - opts = { - 'sep': '\n' - }; - s = stridedArrayStream( values.length, values, 1, 0, opts ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - s.pipe( iStream ); - - function inspect() { - t.ok( false, 'should not be called' ); - } - - function onEnd() { - t.pass( 'stream ended' ); - t.end(); - } -}); - -tape( 'the constructor returns a stream which streams elements of a strided array-like object (object mode; empty)', function test( t ) { - var iStream; - var values; - var opts; - var s; - - values = []; - - opts = { - 'objectMode': true - }; - s = stridedArrayStream( values.length, values, 1, 0, opts ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - s.pipe( iStream ); - - function inspect() { - t.ok( false, 'should not be called' ); - } - - function onEnd() { - t.pass( 'stream ended' ); - t.end(); - } -}); - -tape( 'by default, the constructor returns a stream which streams newline-delimited values', function test( t ) { - var expected; - var iStream; - var result; - var values; - var s; - - values = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - expected = values.slice(); - - s = stridedArrayStream( values.length, values, 1, 0 ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - result = ''; - s.pipe( iStream ); - - function inspect( chunk ) { - result += chunk.toString(); - } - - function onEnd() { - var v; - var i; - - result = result.split( '\n' ); - t.equal( result.length, expected.length, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - v = parseFloat( result[ i ] ); - t.equal( v, expected[ i ], 'returns expected value' ); - } - t.end(); - } -}); - -tape( 'the constructor supports providing a custom separator for streamed values', function test( t ) { - var expected; - var iStream; - var result; - var values; - var opts; - var s; - - values = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - expected = [ 8, 7, 6, 5, 4, 3, 2, 1 ]; - - opts = { - 'sep': '--++--' - }; - s = stridedArrayStream( values.length, values, -1, values.length-1, opts ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - result = ''; - s.pipe( iStream ); - - function inspect( chunk ) { - result += chunk.toString(); - } - - function onEnd() { - var v; - var i; - - result = result.split( opts.sep ); - t.equal( result.length, expected.length, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - v = parseFloat( result[ i ] ); - t.equal( v, expected[ i ], 'returns expected value' ); - } - t.end(); - } -}); - -tape( 'by default, the constructor returns a stream which serializes streamed values as JSON strings', function test( t ) { - var iStream; - var result; - var values; - var s; - - values = [ - { - 'value': 1 - }, - { - 'value': 2 - }, - { - 'value': 3 - }, - { - 'value': 4 - }, - { - 'value': 5 - }, - { - 'value': 6 - }, - { - 'value': 7 - }, - { - 'value': 8 - } - ]; - - s = stridedArrayStream( values.length, values, 1, 0 ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - result = ''; - s.pipe( iStream ); - - function inspect( chunk ) { - result += chunk.toString(); - } - - function onEnd() { - var v; - var i; - - result = result.split( '\n' ); - t.equal( result.length, values.length, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - v = parseJSON( result[ i ] ); - t.deepEqual( v, values[ i ], 'returns expected value' ); - } - t.end(); - } -}); - -tape( 'the constructor supports providing a custom serialization function (string)', function test( t ) { - var expected; - var iStream; - var result; - var values; - var opts; - var s; - - values = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - - expected = [ - 'v::1', - 'v::2', - 'v::3', - 'v::4', - 'v::5', - 'v::6', - 'v::7', - 'v::8' - ]; - - opts = { - 'serialize': serialize - }; - s = stridedArrayStream( values.length, values, 1, 0, opts ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - result = ''; - s.pipe( iStream ); - - function serialize( v ) { - return 'v::' + v.toString(); - } - - function inspect( chunk ) { - result += chunk.toString(); - } - - function onEnd() { - var i; - result = result.split( '\n' ); - t.equal( result.length, expected.length, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - t.equal( result[ i ], expected[ i ], 'returns expected value' ); - } - t.end(); - } -}); - -tape( 'the constructor supports providing a custom serialization function (buffer)', function test( t ) { - var expected; - var iStream; - var result; - var values; - var opts; - var s; - - values = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; - - expected = [ - 'v::1', - 'v::2', - 'v::3', - 'v::4', - 'v::5', - 'v::6', - 'v::7', - 'v::8' - ]; - - opts = { - 'serialize': serialize - }; - s = stridedArrayStream( values.length, values, 1, 0, opts ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - result = ''; - s.pipe( iStream ); - - function serialize( v ) { - return string2buffer( 'v::' + v.toString() ); - } - - function inspect( chunk ) { - result += chunk.toString(); - } - - function onEnd() { - var i; - result = result.split( '\n' ); - t.equal( result.length, expected.length, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - t.equal( result[ i ], expected[ i ], 'returns expected value' ); - } - t.end(); - } -}); - -tape( 'in object mode, `null` values are reserved', function test( t ) { - var iStream; - var values; - var count; - var opts; - var FLG; - var s; - - values = [ 1, 2, 3, null, 5, 6, 7, 8 ]; - - opts = { - 'objectMode': true - }; - s = stridedArrayStream( values.length, values, 1, 0, opts ); - s.on( 'error', onError ); - s.on( 'end', onEnd ); - - iStream = inspectStream.objectMode( inspect ); - - count = 0; - FLG = false; - s.pipe( iStream ); - - function inspect( v, i ) { - count += 1; - t.equal( v, values[ i ], 'returns expected value' ); - } - - function onError( err ) { - FLG = true; - t.ok( false, err.message ); - } - - function onEnd() { - t.pass( 'stream ended' ); - t.equal( FLG, false, 'stream does not emit an error' ); - t.equal( count, 3, 'streamed expected number of values' ); - t.end(); - } -}); - -tape( 'by default, when not in object mode, a stream emits an `error` upon encountering an `undefined` value', function test( t ) { - var iStream; - var values; - var result; - var count; - var FLG; - var s; - - values = [ 1, 2, 3, void 0, 5, 6, 7, 8 ]; - - s = stridedArrayStream( values.length, values, 1, 0 ); - s.on( 'error', onError ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - result = ''; - count = 0; - FLG = false; - s.pipe( iStream ); - - function inspect( v ) { - count += 1; - result += v.toString(); - } - - function onError( err ) { - FLG = true; - t.ok( true, err.message ); - } - - function onEnd() { - var j; - var i; - - t.pass( 'stream ended' ); - t.equal( FLG, true, 'stream does emit an error' ); - t.equal( count, 7, 'streamed expected number of values' ); - - result = result.split( '\n' ); - t.equal( result.length, 7, 'has expected length' ); - - j = -1; - for ( i = 0; i < values.length; i++ ) { - if ( values[ i ] === void 0 ) { - continue; - } - j += 1; - t.equal( parseFloat( result[ j ] ), values[ i ], 'returns expected value. i: '+i+'.' ); - } - t.end(); - } -}); diff --git a/test/test.object_mode.js b/test/test.object_mode.js deleted file mode 100644 index c8b73ab..0000000 --- a/test/test.object_mode.js +++ /dev/null @@ -1,279 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -var StridedArrayStream = require( './../lib/main.js' ); -var objectMode = require( './../lib/object_mode.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof objectMode, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a nonnegative integer as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - objectMode( value, [ 1, 2, 3 ], 1, 0 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - objectMode( 1, value, 1, 0 ); - }; - } -}); - -tape( 'the function throws an error if not provided an integer as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - objectMode( 1, [ 1, 2, 3 ], value, 0 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer as a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - objectMode( 1, [ 1, 2, 3 ], 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - function badValue( value ) { - return function badValue() { - objectMode( 3, [ 1, 2, 3 ], 1, 0, value ); - }; - } -}); - -tape( 'if provided an invalid readable stream option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - NaN, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - objectMode( 3, [ 1, 2, 3 ], 1, 0, { - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a stream instance', function test( t ) { - var s = objectMode( 3, [ 1, 2, 3 ], 1, 0 ); - t.equal( s instanceof StridedArrayStream, true, 'returns a stream instance' ); - t.end(); -}); - -tape( 'the function returns a stream instance (options)', function test( t ) { - var s = objectMode( 3, [ 1, 2, 3 ], 1, 0, {} ); - t.equal( s instanceof StridedArrayStream, true, 'returns a stream instance' ); - t.end(); -}); - -tape( 'the function returns a stream which streams elements of an array-like object', function test( t ) { - var iStream; - var values; - var opts; - var s; - - values = [ 1, 2, 3, 4 ]; - - s = objectMode( values.length, values, 1, 0 ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - s.pipe( iStream ); - - function inspect( v, i ) { - t.equal( v, values[ i ], 'returns expected value' ); - } - - function onEnd() { - t.end(); - } -}); - -tape( 'the function does not support overriding the `objectMode` option', function test( t ) { - var iStream; - var values; - var opts; - var s; - - values = [ 1, 2, 3, 4 ]; - - opts = { - 'objectMode': false - }; - s = objectMode( values.length, values, 1, 0, opts ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - s.pipe( iStream ); - - function inspect( v, i ) { - t.equal( v, values[ i ], 'returns expected value' ); - } - - function onEnd() { - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 0c1b050..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,241 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.equals( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `objectMode` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'objectMode': values[ i ] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `highWaterMark` option which is not a nonnegative number', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - -5, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'highWaterMark': values[ i ] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `encoding` option which is neither a string nor `null`', function test( t ) { - var values; - var err; - var i; - - values = [ - 5, - NaN, - true, - false, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'encoding': values[ i ] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string', function test( t ) { - var values; - var err; - var i; - - values = [ - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[ i ] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `serialize` option which is not a function', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - void 0, - null, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'serialize': values[ i ] - }); - t.equal( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns null if all options are valid', function test( t ) { - var options; - var opts; - var err; - - options = { - 'objectMode': true, - 'highWaterMark': 64, - 'encoding': null, - 'sep': '\n', - 'serialize': serialize - }; - opts = {}; - err = validate( opts, options ); - - t.equal( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets option values' ); - - options = { - 'objectMode': false, - 'highWaterMark': 64, - 'encoding': 'utf8', - 'sep': '\t', - 'serialize': serialize - }; - opts = {}; - err = validate( opts, options ); - - t.equal( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets option values' ); - - t.end(); - - function serialize( v ) { - return v.toString(); - } -}); - -tape( 'the function ignores unrecognized/unsupported options', function test( t ) { - var options; - var opts; - var err; - - options = { - 'beep': true, - 'boop': 'bop' - }; - opts = {}; - err = validate( opts, options ); - - t.equal( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -});