diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +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 -insert_final_newline = false - -# 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 = false - -# 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 f908ead..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T03:53:00.173Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8f68597..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-constant) 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/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 8b9b0d4..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-constant) 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 503c136..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: '21 21 * * 0' - - # 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 663474a..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1008 +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 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 + + ```
@@ -274,74 +270,7 @@ stream.pipe( iStream ); -* * * - -
- -## CLI - -
- -## Installation - -To use as a general utility, install the CLI package globally - -```bash -npm install -g @stdlib/streams-node-from-constant-cli -``` - -
- - - -
- -### Usage - -```text -Usage: constant-stream [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --sep sep Separator used to join streamed data. Default: '\n'. - -n, --iter iterations Number of iterations. -``` - -
- - - - - -
- -### Notes - -- In accordance with POSIX convention, a trailing newline is **always** appended to generated output prior to exit. - -
- - - - - -
- -### Examples - -```bash -$ constant-stream 'beep' -n 10 -``` - -
- - - -
- @@ -367,7 +296,7 @@ $ constant-stream 'beep' -n 10 ## 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]. @@ -442,9 +371,9 @@ Copyright © 2016-2024. 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 -[@stdlib/streams/node/from-iterator]: https://github.com/stdlib-js/streams-node-from-iterator +[@stdlib/streams/node/from-iterator]: https://github.com/stdlib-js/streams-node-from-iterator/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 15b9ff9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,89 +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 constantStream = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var s; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s = constantStream( 'beep' ); - 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 s; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s = constantStream.objectMode( 'beep' ); - 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 s; - var i; - - createStream = constantStream.factory( 'beep' ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s = createStream(); - 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 9f808f8..0000000 --- a/benchmark/benchmark.throughput.js +++ /dev/null @@ -1,245 +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 constantStream = 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 i; - - function Writable( opts ) { - WritableStream.call( this, opts ); - return this; - } - - inherit( Writable, WritableStream ); - Writable.prototype._write = next; // eslint-disable-line no-underscore-dangle - - // Create a source stream: - opts = {}; - rStream = constantStream( 'beep', 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 i; - - function Writable( opts ) { - WritableStream.call( this, opts ); - return this; - } - - inherit( Writable, WritableStream ); - Writable.prototype._write = next; // eslint-disable-line no-underscore-dangle - - // Create a source stream: - opts = { - 'highWaterMark': 0 - }; - rStream = constantStream( 'beep', 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 i; - - function Writable( opts ) { - WritableStream.call( this, opts ); - return this; - } - - inherit( Writable, WritableStream ); - Writable.prototype._write = next; // eslint-disable-line no-underscore-dangle - - // Create a source stream: - opts = {}; - rStream = constantStream.objectMode( 'beep', 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 i; - - function Writable( opts ) { - WritableStream.call( this, opts ); - return this; - } - - inherit( Writable, WritableStream ); - Writable.prototype._write = next; // eslint-disable-line no-underscore-dangle - - // Create a source stream: - opts = { - 'highWaterMark': 0 - }; - rStream = constantStream.objectMode( 'beep', 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/bin/cli b/bin/cli deleted file mode 100755 index 893dded..0000000 --- a/bin/cli +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env node - -/** -* @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 resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdout = require( '@stdlib/streams-node-stdout' ); -var constantStream = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Callback invoked once a source stream ends. -* -* @private -*/ -function onEnd() { - // Append a trailing newline in accordance with standard POSIX behavior: - console.log( '' ); // eslint-disable-line no-console -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var stream; - var flags; - var opts; - var args; - var cli; - var err; - - // Create a command-line interface: - cli = new CLI({ - 'pkg': require( './../package.json' ), - 'options': require( './../etc/cli_opts.json' ), - 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }) - }); - - // Get any provided command-line options: - flags = cli.flags(); - if ( flags.help || flags.version ) { - return; - } - - // Get any provided command-line arguments: - args = cli.args(); - if ( args.length < 1 ) { - err = new Error( 'insufficient arguments. Must provide a value to stream.' ); - return onError( err ); - } - - opts = {}; - if ( flags.iter ) { - opts.iter = parseInt( flags.iter, 10 ); - } - if ( flags.sep ) { - opts.sep = flags.sep; - } - - // Create a source stream and pipe to `stdout`: - stream = constantStream( args[ 0 ].toString(), opts ); - stream.on( 'end', onEnd ); - - stream.pipe( stdout ); - - /** - * Callback invoked upon encountering an error. - * - * @private - * @param {Error} error - error - * @param {integer} [code] - exit code - */ - function onError( error, code ) { - cli.error( error, code || 1 ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7a02d90..0000000 --- a/branches.md +++ /dev/null @@ -1,60 +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]). -- **cli**: [CLI][cli-url] branch for use on the command line. - -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]; -C -->|extract| G[cli]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/streams/node/from-constant" -%% click B href "https://github.com/stdlib-js/streams-node-from-constant/tree/main" -%% click C href "https://github.com/stdlib-js/streams-node-from-constant/tree/production" -%% click D href "https://github.com/stdlib-js/streams-node-from-constant/tree/esm" -%% click E href "https://github.com/stdlib-js/streams-node-from-constant/tree/deno" -%% click F href "https://github.com/stdlib-js/streams-node-from-constant/tree/umd" -%% click G href "https://github.com/stdlib-js/streams-node-from-constant/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/streams/node/from-constant -[production-url]: https://github.com/stdlib-js/streams-node-from-constant/tree/production -[deno-url]: https://github.com/stdlib-js/streams-node-from-constant/tree/deno -[deno-readme]: https://github.com/stdlib-js/streams-node-from-constant/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/streams-node-from-constant/tree/umd -[umd-readme]: https://github.com/stdlib-js/streams-node-from-constant/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/streams-node-from-constant/tree/esm -[esm-readme]: https://github.com/stdlib-js/streams-node-from-constant/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/streams-node-from-constant/tree/cli \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index b8b7e9b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import constantStream from '../docs/types/index'; -export = constantStream; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e8e08dc..0000000 --- a/dist/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict";var a=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=a(function(ve,V){V.exports={objectMode:!1,encoding:null,sep:"\n",iter:1e308}});var q=a(function(le,b){ -var A=require('@stdlib/assert-is-plain-object/dist'),f=require('@stdlib/assert-has-own-property/dist'),B=require('@stdlib/assert-is-boolean/dist').isPrimitive,F=require('@stdlib/assert-is-nonnegative-number/dist').isPrimitive,m=require('@stdlib/assert-is-string/dist').isPrimitive,R=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/error-tools-fmtprodmsg/dist');function I(e,r){return A(r)?f(r,"sep")&&(e.sep=r.sep,!m(e.sep))?new TypeError(s('1MD2W',"sep",e.sep)):f(r,"objectMode")&&(e.objectMode=r.objectMode,!B(e.objectMode))?new TypeError(s('1MD2o',"objectMode",e.objectMode)):f(r,"encoding")&&(e.encoding=r.encoding,!m(e.encoding)&&e.encoding!==null)?new TypeError(s('1MD7n',"encoding",e.encoding)):f(r,"highWaterMark")&&(e.highWaterMark=r.highWaterMark,!F(e.highWaterMark))?new TypeError(s('1MD4k',"highWaterMark",e.highWaterMark)):f(r,"iter")&&(e.iter=r.iter,!R(e.iter))?new TypeError(s('1MD2t',"iter",e.iter)):null:new TypeError(s('1MD2V',r));}b.exports=I -});var p=a(function(me,y){ -var L=require("debug"),U=L("from-constant-stream");y.exports=U -});var c=a(function(be,_){ -var M=require("readable-stream").Readable,G=require('@stdlib/assert-is-error/dist'),J=require('@stdlib/assert-is-string/dist').isPrimitive,D=require('@stdlib/assert-is-buffer/dist'),z=require('@stdlib/assert-is-uint8array/dist'),H=require('@stdlib/buffer-from-arraybuffer/dist'),w=require('@stdlib/buffer-from-string/dist'),K=require('@stdlib/buffer-ctor/dist'),Q=require('@stdlib/object-assign/dist'),X=require('@stdlib/error-tools-fmtprodmsg/dist'),Y=require('@stdlib/utils-inherit/dist'),j=require('@stdlib/utils-define-nonenumerable-property/dist'),o=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),Z=require('@stdlib/utils-next-tick/dist'),$=l(),ee=q(),u=p();function re(){var e;if(!this._destroyed)for(e=!0;e;){if(this._i+=1,this._i>this._iter)return u("Finished iteration."),this.push(null);u("Value: %s. Iter: %d.",this._value,this._i),this._objectMode===!1&&this._i>1?e=this.push(K.concat([this._sep,this._value])):e=this.push(this._value)}}function ie(e){var r;if(this._destroyed)return u("Attempted to destroy an already destroyed stream."),this;return r=this,this._destroyed=!0,Z(i),this;function i(){e&&(u("Stream was destroyed due to an error. Error: %s.",G(e)?e.message:JSON.stringify(e)),r.emit("error",e)),u("Closing the stream..."),r.emit("close")}}function n(e,r){var i,t;if(!(this instanceof n))return arguments.length>1?new n(e,r):new n(e);if(i=Q({},$),arguments.length>1&&(t=ee(i,r),t))throw t;if(i.objectMode===!1){if(J(e))e=w(e);else if(!D(e))if(z(e))e=H(e.buffer,e.byteOffset,e.length);else throw new TypeError(X('1MDAA',e))}return u("Creating a readable stream configured with the following options: %s.",JSON.stringify(i)),M.call(this,i),j(this,"_destroyed",!1),o(this,"_objectMode",i.objectMode),o(this,"_sep",w(i.sep)),o(this,"_iter",i.iter),o(this,"_value",e),j(this,"_i",0),this}Y(n,M);o(n.prototype,"_read",re);o(n.prototype,"destroy",ie);_.exports=n -});var E=a(function(qe,O){ -var te=require('@stdlib/assert-is-plain-object/dist'),ne=require('@stdlib/error-tools-fmtprodmsg/dist'),ae=require('@stdlib/object-assign/dist'),se=c();function oe(e,r){var i;if(arguments.length>1){if(i=r,!te(i))throw new TypeError(ne('1MD2V',i));i=ae({},r)}else i={};return i.objectMode=!0,new se(e,i)}O.exports=oe -});var N=a(function(ye,k){ -var d=require('@stdlib/assert-has-own-property/dist'),ue=require('@stdlib/assert-is-plain-object/dist'),fe=require('@stdlib/error-tools-fmtprodmsg/dist'),S=require('@stdlib/object-assign/dist'),T=c();function de(e,r){var i,t,h,g;if(i=arguments.length,i===0)t={},g=!0;else if(i===1)e!==null&&typeof e=="object"&&(d(e,"sep")||d(e,"iter")||d(e,"objectMode")||d(e,"encoding")||d(e,"highWaterMark"))?(t=S({},e),g=!0):t={};else{if(!ue(r))throw new TypeError(fe('1MD2V',r));t=S({},r)}return g?h=P:h=W,h;function P(C){return new T(C,t)}function W(){return new T(e,t)}}k.exports=de -});var x=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),v=c(),ce=E(),he=N();x(v,"objectMode",ce);x(v,"factory",he);module.exports=v; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5685333..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\t\"iter\": 1e308\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 isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\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 {NonNegativeInteger} [options.iter] - number of iterations\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, 'iter' ) ) {\n\t\topts.iter = options.iter;\n\t\tif ( !isNonNegativeInteger( opts.iter ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', opts.iter ) );\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-constant-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 isError = require( '@stdlib/assert-is-error' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar isUint8Array = require( '@stdlib/assert-is-uint8array' );\nvar arraybuffer2buffer = require( '@stdlib/buffer-from-arraybuffer' );\nvar string2buffer = require( '@stdlib/buffer-from-string' );\nvar Buffer = require( '@stdlib/buffer-ctor' ); // TODO: replace Buffer.concat usage with stdlib pkg\nvar assign = require( '@stdlib/object-assign' );\nvar format = require( '@stdlib/string-format' );\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 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\tif ( this._destroyed ) {\n\t\treturn;\n\t}\n\tFLG = true;\n\twhile ( FLG ) {\n\t\tthis._i += 1;\n\t\tif ( this._i > this._iter ) {\n\t\t\tdebug( 'Finished iteration.' );\n\t\t\treturn this.push( null );\n\t\t}\n\t\tdebug( 'Value: %s. Iter: %d.', this._value, this._i );\n\t\tif ( this._objectMode === false && this._i > 1 ) {\n\t\t\tFLG = this.push( Buffer.concat( [ this._sep, this._value ] ) );\n\t\t} else {\n\t\t\tFLG = this.push( this._value );\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 {ConstantStream} 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 stream which always streams the same value.\n*\n* @constructor\n* @param {(string|Buffer|Uint8Array)} value - value to stream\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 {NonNegativeInteger} [options.iter] - number of iterations\n* @throws {TypeError} in binary mode, value to stream must be a string, `Buffer`, or `Uint8Array`\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ConstantStream} Stream instance\n*\n* @example\n* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );\n*\n* function log( chunk ) {\n* console.log( chunk.toString() );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = new ConstantStream( 'beep', opts );\n*\n* stream.pipe( inspectStream( log ) );\n*/\nfunction ConstantStream( value, options ) {\n\tvar opts;\n\tvar err;\n\tif ( !( this instanceof ConstantStream ) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ConstantStream( value, options );\n\t\t}\n\t\treturn new ConstantStream( value );\n\t}\n\topts = assign( {}, DEFAULTS );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( opts.objectMode === false ) {\n\t\tif ( isString( value ) ) {\n\t\t\tvalue = string2buffer( value );\n\t\t} else if ( isBuffer( value ) ) { // NOTE: order matters here. We want the `isBuffer` check BEFORE the `isUint8Array` check!!\n\t\t\t// Nothing to do, as value is already a buffer...\n\t\t} else if ( isUint8Array( value ) ) {\n\t\t\t// Convert to a `Buffer` object to provide backward compatibility with older Node.js versions...\n\t\t\tvalue = arraybuffer2buffer( value.buffer, value.byteOffset, value.length ); // eslint-disable-line max-len\n\t\t} else {\n\t\t\tthrow new TypeError( format( 'invalid argument. In binary mode, a provided value must be a string, Buffer, or Uint8Array. Value: `%s`.', value ) );\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', string2buffer( opts.sep ) );\n\n\t// Cache the total number of iterations:\n\tsetNonEnumerableReadOnly( this, '_iter', opts.iter );\n\n\t// Cache the value to stream:\n\tsetNonEnumerableReadOnly( this, '_value', value );\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( ConstantStream, Readable );\n\n/**\n* Implements the `_read` method.\n*\n* @private\n* @name _read\n* @memberof ConstantStream.prototype\n* @type {Function}\n* @param {number} size - number (of bytes) to read\n* @returns {void}\n*/\nsetNonEnumerableReadOnly( ConstantStream.prototype, '_read', read );\n\n/**\n* Gracefully destroys a stream, providing backward compatibility.\n*\n* @name destroy\n* @memberof ConstantStream.prototype\n* @type {Function}\n* @param {(string|Object|Error)} [error] - error\n* @returns {ConstantStream} Stream instance\n*/\nsetNonEnumerableReadOnly( ConstantStream.prototype, 'destroy', destroy );\n\n\n// EXPORTS //\n\nmodule.exports = ConstantStream;\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 ConstantStream = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns an \"objectMode\" readable stream which always streams the same value.\n*\n* @param {*} value - value to stream\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* @param {NonNegativeInteger} [options.iter] - number of iterations\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ConstantStream} Stream instance\n*\n* @example\n* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );\n*\n* function log( v ) {\n* console.log( v );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = objectMode( 3.14, opts );\n*\n* stream.pipe( inspectStream.objectMode( log ) );\n*/\nfunction objectMode( value, options ) {\n\tvar opts;\n\tif ( arguments.length > 1 ) {\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 ConstantStream( value, 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 hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar format = require( '@stdlib/string-format' );\nvar assign = require( '@stdlib/object-assign' );\nvar ConstantStream = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating readable streams which always stream the same value.\n*\n* @param {(string|Buffer|Uint8Array|*)} [value] - value to stream\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 {NonNegativeInteger} [options.iter] - number of iterations\n* @throws {TypeError} options argument must be an object\n* @returns {Function} stream factory\n*\n* @example\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* var i;\n* for ( i = 0; i < 10; i++ ) {\n* streams.push( createStream( i.toString() ) );\n* }\n*/\nfunction factory( value, options ) {\n\tvar nargs;\n\tvar opts;\n\tvar fcn;\n\tvar FLG;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\topts = {};\n\t\tFLG = true;\n\t} else if ( nargs === 1 ) {\n\t\t// Check (imperfectly!) whether we were provided an \"options\" object...\n\t\tif (\n\t\t\tvalue !== null &&\n\t\t\ttypeof value === 'object' &&\n\t\t\t(\n\t\t\t\thasOwnProp( value, 'sep' ) ||\n\t\t\t\thasOwnProp( value, 'iter' ) ||\n\t\t\t\thasOwnProp( value, 'objectMode' ) ||\n\t\t\t\thasOwnProp( value, 'encoding' ) ||\n\t\t\t\thasOwnProp( value, 'highWaterMark' )\n\t\t\t)\n\t\t) {\n\t\t\topts = assign( {}, value );\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\topts = {};\n\t\t}\n\t} else { // nargs > 1\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}\n\tif ( FLG ) {\n\t\tfcn = createStream1;\n\t} else {\n\t\tfcn = createStream2;\n\t}\n\treturn fcn;\n\n\t/**\n\t* Returns a readable stream which always streams the same value.\n\t*\n\t* @private\n\t* @param {(string|Buffer|Uint8Array|*)} value - value to stream\n\t* @throws {TypeError} in binary mode, value to stream must be a string, Buffer, or Uint8Array\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ConstantStream} Stream instance\n\t*/\n\tfunction createStream1( value ) {\n\t\treturn new ConstantStream( value, opts );\n\t}\n\n\t/**\n\t* Returns a readable stream which always streams the same value.\n\t*\n\t* @private\n\t* @throws {TypeError} in binary mode, value to stream must be a string, Buffer, or Uint8Array\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ConstantStream} Stream instance\n\t*/\n\tfunction createStream2() {\n\t\treturn new ConstantStream( value, 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 which always streams the same value.\n*\n* @module @stdlib/streams-node-from-constant\n*\n* @example\n* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );\n* var constantStream = require( '@stdlib/streams-node-from-constant' );\n*\n* function log( chunk ) {\n* console.log( chunk.toString() );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = constantStream( 'beep', opts );\n*\n* stream.pipe( inspectStream( log ) );\n*\n* @example\n* var constantStream = require( '@stdlib/streams-node-from-constant' );\n*\n* var opts = {\n* 'sep': ',',\n* 'objectMode': false,\n* 'encoding': 'utf8',\n* 'highWaterMark': 64\n* };\n*\n* var createStream = constantStream.factory( opts );\n*\n* // Create 10 identically configured streams...\n* var streams = [];\n* var i;\n* for ( i = 0; i < 10; i++ ) {\n* streams.push( createStream( i.toString() ) );\n* }\n*\n* @example\n* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );\n* var constantStream = require( '@stdlib/streams-node-from-constant' );\n*\n* function log( v ) {\n* console.log( v );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = constantStream.objectMode( 3.14, opts );\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,KACP,KAAQ,KACT,ICLA,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,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,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,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACJ,EAAsBG,EAAK,IAAK,GAC9B,IAAI,UAAWF,EAAQ,2EAA4E,OAAQE,EAAK,IAAK,CAAE,EAGzH,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,sBAAuB,EAK3CD,EAAO,QAAUE,IChCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,iBAAkB,EAAE,SACxCC,EAAU,QAAS,yBAA0B,EAC7CC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAe,QAAS,8BAA+B,EACvDC,EAAqB,QAAS,iCAAkC,EAChEC,EAAgB,QAAS,4BAA6B,EACtDC,EAAS,QAAS,qBAAsB,EACxCC,EAAS,QAAS,uBAAwB,EAC1CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAU,QAAS,uBAAwB,EAC3CC,EAAmB,QAAS,6CAA8C,EAC1EC,EAA2B,QAAS,uDAAwD,EAC5FC,EAAW,QAAS,yBAA0B,EAC9CC,EAAW,IACXC,GAAW,IACXC,EAAQ,IAYZ,SAASC,IAAO,CAEf,IAAIC,EACJ,GAAK,MAAK,WAIV,IADAA,EAAM,GACEA,GAAM,CAEb,GADA,KAAK,IAAM,EACN,KAAK,GAAK,KAAK,MACnB,OAAAF,EAAO,qBAAsB,EACtB,KAAK,KAAM,IAAK,EAExBA,EAAO,uBAAwB,KAAK,OAAQ,KAAK,EAAG,EAC/C,KAAK,cAAgB,IAAS,KAAK,GAAK,EAC5CE,EAAM,KAAK,KAAMX,EAAO,OAAQ,CAAE,KAAK,KAAM,KAAK,MAAO,CAAE,CAAE,EAE7DW,EAAM,KAAK,KAAM,KAAK,MAAO,CAE/B,CAGD,CASA,SAASC,GAASC,EAAQ,CAEzB,IAAIC,EACJ,GAAK,KAAK,WACT,OAAAL,EAAO,mDAAoD,EACpD,KAER,OAAAK,EAAO,KACP,KAAK,WAAa,GAElBR,EAAUS,CAAM,EAET,KAOP,SAASA,GAAQ,CACXF,IACJJ,EAAO,mDAAsDf,EAASmB,CAAM,EAAMA,EAAM,QAAU,KAAK,UAAWA,CAAM,CAAE,EAC1HC,EAAK,KAAM,QAASD,CAAM,GAE3BJ,EAAO,uBAAwB,EAC/BK,EAAK,KAAM,OAAQ,CACpB,CAGD,CAoCA,SAASE,EAAgBC,EAAOC,EAAU,CACzC,IAAIC,EACAC,EACJ,GAAK,EAAG,gBAAgBJ,GACvB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAgBC,EAAOC,CAAQ,EAEpC,IAAIF,EAAgBC,CAAM,EAGlC,GADAE,EAAOlB,EAAQ,CAAC,EAAGM,CAAS,EACvB,UAAU,OAAS,IACvBa,EAAMZ,GAAUW,EAAMD,CAAQ,EACzBE,GACJ,MAAMA,EAGR,GAAKD,EAAK,aAAe,IACxB,GAAKxB,EAAUsB,CAAM,EACpBA,EAAQlB,EAAekB,CAAM,UAClB,CAAArB,EAAUqB,CAAM,EAErB,GAAKpB,EAAcoB,CAAM,EAE/BA,EAAQnB,EAAoBmB,EAAM,OAAQA,EAAM,WAAYA,EAAM,MAAO,MAEzE,OAAM,IAAI,UAAWf,EAAQ,2GAA4Ge,CAAM,CAAE,EAInJ,OAAAR,EAAO,wEAAyE,KAAK,UAAWU,CAAK,CAAE,EACvG1B,EAAS,KAAM,KAAM0B,CAAK,EAG1Bf,EAAkB,KAAM,aAAc,EAAM,EAG5CC,EAA0B,KAAM,cAAec,EAAK,UAAW,EAG/Dd,EAA0B,KAAM,OAAQN,EAAeoB,EAAK,GAAI,CAAE,EAGlEd,EAA0B,KAAM,QAASc,EAAK,IAAK,EAGnDd,EAA0B,KAAM,SAAUY,CAAM,EAGhDb,EAAkB,KAAM,KAAM,CAAE,EAEzB,IACR,CAKAD,EAASa,EAAgBvB,CAAS,EAYlCY,EAA0BW,EAAe,UAAW,QAASN,EAAK,EAWlEL,EAA0BW,EAAe,UAAW,UAAWJ,EAAQ,EAKvEpB,EAAO,QAAUwB,ICtOjB,IAAAK,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAW,QAAS,gCAAiC,EACrDC,GAAS,QAAS,uBAAwB,EAC1CC,GAAS,QAAS,uBAAwB,EAC1CC,GAAiB,IAgCrB,SAASC,GAAYC,EAAOC,EAAU,CACrC,IAAIC,EACJ,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAA,EAAOD,EACF,CAACN,GAAUO,CAAK,EACpB,MAAM,IAAI,UAAWN,GAAQ,qEAAsEM,CAAK,CAAE,EAE3GA,EAAOL,GAAQ,CAAC,EAAGI,CAAQ,CAC5B,MACCC,EAAO,CAAC,EAET,OAAAA,EAAK,WAAa,GACX,IAAIJ,GAAgBE,EAAOE,CAAK,CACxC,CAKAR,EAAO,QAAUK,KC3EjB,IAAAI,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,iCAAkC,EACxDC,GAAW,QAAS,gCAAiC,EACrDC,GAAS,QAAS,uBAAwB,EAC1CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAiB,IAmCrB,SAASC,GAASC,EAAOC,EAAU,CAClC,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAH,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAO,CAAC,EACRE,EAAM,WACKH,IAAU,EAGpBF,IAAU,MACV,OAAOA,GAAU,WAEhBN,EAAYM,EAAO,KAAM,GACzBN,EAAYM,EAAO,MAAO,GAC1BN,EAAYM,EAAO,YAAa,GAChCN,EAAYM,EAAO,UAAW,GAC9BN,EAAYM,EAAO,eAAgB,IAGpCG,EAAON,EAAQ,CAAC,EAAGG,CAAM,EACzBK,EAAM,IAENF,EAAO,CAAC,MAEH,CACN,GAAK,CAACR,GAAUM,CAAQ,EACvB,MAAM,IAAI,UAAWL,GAAQ,qEAAsEK,CAAQ,CAAE,EAE9GE,EAAON,EAAQ,CAAC,EAAGI,CAAQ,CAC5B,CACA,OAAKI,EACJD,EAAME,EAENF,EAAMG,EAEAH,EAYP,SAASE,EAAeN,EAAQ,CAC/B,OAAO,IAAIF,EAAgBE,EAAOG,CAAK,CACxC,CAWA,SAASI,GAAgB,CACxB,OAAO,IAAIT,EAAgBE,EAAOG,CAAK,CACxC,CACD,CAKAV,EAAO,QAAUM,KCrDjB,IAAIS,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", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_debug", "__commonJSMin", "exports", "module", "logger", "debug", "require_main", "__commonJSMin", "exports", "module", "Readable", "isError", "isString", "isBuffer", "isUint8Array", "arraybuffer2buffer", "string2buffer", "Buffer", "assign", "format", "inherit", "setNonEnumerable", "setNonEnumerableReadOnly", "nextTick", "DEFAULTS", "validate", "debug", "read", "FLG", "destroy", "error", "self", "close", "ConstantStream", "value", "options", "opts", "err", "require_object_mode", "__commonJSMin", "exports", "module", "isObject", "format", "assign", "ConstantStream", "objectMode", "value", "options", "opts", "require_factory", "__commonJSMin", "exports", "module", "hasOwnProp", "isObject", "format", "assign", "ConstantStream", "factory", "value", "options", "nargs", "opts", "fcn", "FLG", "createStream1", "createStream2", "setReadOnly", "main", "objectMode", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f184acd..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,141 +0,0 @@ - -{{alias}}( value[, options] ) - Returns a readable stream which always streams the same value. - - In object mode, `null` is a reserved value. If provided `null`, the - returned stream will prematurely end. - - Parameters - ---------- - value: string|Buffer|Uint8Array|any - Value to stream. - - 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.iter: integer (optional) - Number of iterations. - - Returns - ------- - stream: ReadableStream - Readable stream. - - Examples - -------- - > function fcn( chunk ) { console.log( chunk.toString() ); }; - > var opts = { 'iter': 10 }; - > var s = {{alias}}( 'beep', opts ); - > var o = {{alias:@stdlib/streams/node/inspect-sink}}( fcn ); - > s.pipe( o ); - - -{{alias}}.factory( [value, ][options] ) - Returns a function for creating readable streams which always stream the - same value. - - If provided a value to stream, the returned function returns readable always - streams the provided value. - - If not provided a value to stream, the returned function requires that a - value be provided at each invocation. - - If provided only one argument and that argument is an object (either empty - or not containing any recognized options properties), the function treats - the argument as a value to be streamed, not as an options argument. - - Parameters - ---------- - value: string|Buffer|Uint8Array|any (optional) - Value to stream. - - 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.iter: integer (optional) - Number of iterations. - - Returns - ------- - fcn: Function - Function for creating readable streams. - - Examples - -------- - > var opts = { 'objectMode': true, 'highWaterMark': 64 }; - > var createStream = {{alias}}.factory( opts ); - - -{{alias}}.objectMode( value[, options] ) - Returns an "objectMode" readable stream which always streams the same value. - - In object mode, `null` is a reserved value. If provided `null`, the - returned stream will prematurely end. - - Parameters - ---------- - value: any - Value to stream. - - 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. - - options.iter: integer (optional) - Number of iterations. - - Returns - ------- - stream: ReadableStream - Readable stream operating in "objectMode". - - Examples - -------- - > function fcn( v ) { console.log( v ); }; - > var opts = { 'iter': 10 }; - > var s = {{alias}}.objectMode( 3.14, opts ); - > 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 eda0dff..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,105 +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 ConstantStream = require( './index' ); - - -// TESTS // - -// The constructor returns a stream... -{ - new ConstantStream( 'beep' ); // $ExpectType Readable - new ConstantStream( 'beep', { 'objectMode': true } ); // $ExpectType Readable -} - -// The constructor is callable... -{ - const constantStream = ConstantStream; - constantStream( 'beep' ); // $ExpectType Readable - constantStream( 'beep', { 'objectMode': true } ); // $ExpectType Readable -} - -// The constructor has an `objectMode` method which returns a stream... -{ - ConstantStream.objectMode( 'beep' ); // $ExpectType Readable - ConstantStream.objectMode( 'beep', { 'objectMode': true } ); // $ExpectType Readable -} - -// The constructor has a `factory` method which returns a function for creating streams... -{ - const f = ConstantStream.factory(); - f( 'beep' ); // $ExpectType Readable - f( 'boop' ); // $ExpectType Readable - f( 'beep' ); // $ExpectType Readable - - let f2 = ConstantStream.factory( 'beep', {} ); - f2(); // $ExpectType Readable - f2(); // $ExpectType Readable - f2(); // $ExpectType Readable - - f2 = ConstantStream.factory( 'beep', { 'objectMode': true } ); - f2(); // $ExpectType Readable - f2(); // $ExpectType Readable - f2(); // $ExpectType Readable -} - -// The compiler throws an error if the constructor is provided a second argument which is not an options object... -{ - new ConstantStream( 'beep', 'abc' ); // $ExpectError - new ConstantStream( 'beep', 123 ); // $ExpectError - new ConstantStream( 'beep', true ); // $ExpectError - new ConstantStream( 'beep', false ); // $ExpectError - new ConstantStream( 'beep', [] ); // $ExpectError - new ConstantStream( 'beep', null ); // $ExpectError -} - -// The compiler throws an error if the `objectMode` method is provided a second argument which is not an options object... -{ - ConstantStream.objectMode( 'beep', 'abc' ); // $ExpectError - ConstantStream.objectMode( 'beep', 123 ); // $ExpectError - ConstantStream.objectMode( 'beep', true ); // $ExpectError - ConstantStream.objectMode( 'beep', false ); // $ExpectError - ConstantStream.objectMode( 'beep', [] ); // $ExpectError - ConstantStream.objectMode( 'beep', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an options object... -{ - ConstantStream.factory( 'beep', 'abc' ); // $ExpectError - ConstantStream.factory( 'beep', 123 ); // $ExpectError - ConstantStream.factory( 'beep', true ); // $ExpectError - ConstantStream.factory( 'beep', false ); // $ExpectError - ConstantStream.factory( 'beep', [] ); // $ExpectError - ConstantStream.factory( 'beep', null ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an invalid number of arguments... -{ - const f = ConstantStream.factory( 'beep' ); - f( 'boop' ); // $ExpectError - - let f2 = ConstantStream.factory(); - f2(); // $ExpectError - f2( 'beep', 'boop' ); // $ExpectError - - f2 = ConstantStream.factory( { 'objectMode': true } ); - f2(); // $ExpectError - f2( 'beep', 'boop' ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 84d0a4a..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Usage: constant-stream [options] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --sep sep Separator used to join streamed data. Default: '\n'. - -n, --iter iterations Number of iterations. - diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index dc23e04..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "string": [ - "sep", - "iter" - ], - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ], - "iter": [ - "n" - ] - } -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index e6acb90..0000000 --- a/examples/index.js +++ /dev/null @@ -1,39 +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 constantStream = require( './../lib' ); - -function log( v ) { - console.log( v.toString() ); -} - -var opts = { - 'objectMode': true, - 'iter': 10 -}; -var stream = constantStream( 3.14, opts ); - -opts = { - 'objectMode': true -}; -var iStream = inspectStream( opts, log ); - -stream.pipe( iStream ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e7c2832 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 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-error@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@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 i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-uint8array@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-from-arraybuffer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-from-string@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-ctor@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/object-assign@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-inherit@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@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-nonnegative-integer@v0.2.2-esm/index.mjs";function w(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 m(){}function b(){b.init.call(this)}function _(e){return void 0===e._maxListeners?b.defaultMaxListeners:e._maxListeners}function E(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 m,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))&&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 R(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 j(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 S(e,t){for(var r=new Array(t);t--;)r[t]=e[t];return r}m.prototype=Object.create(null),b.EventEmitter=b,b.usingDomains=!1,b.prototype.domain=void 0,b.prototype._events=void 0,b.prototype._maxListeners=void 0,b.defaultMaxListeners=10,b.init=function(){this.domain=null,b.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new m,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},b.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},b.prototype.getMaxListeners=function(){return _(this)},b.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 f=new Error('Uncaught, unspecified "error" event. ('+t+")");throw f.context=t,f}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 h="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=S(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 m,this;delete n[e]}else!function(e,t){for(var r=t,n=r+1,i=e.length;n0?Reflect.ownKeys(this._events):[]};var M="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},A=[],L=[],T="undefined"!=typeof Uint8Array?Uint8Array:Array,k=!1;function x(){k=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)A[t]=e[t],L[e.charCodeAt(t)]=t;L["-".charCodeAt(0)]=62,L["_".charCodeAt(0)]=63}function P(e,t,r){for(var n,i,o=[],s=t;s>18&63]+A[i>>12&63]+A[i>>6&63]+A[63&i]);return o.join("")}function C(e){var t;k||x();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+=A[t>>2],i+=A[t<<4&63],i+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],i+=A[t>>10],i+=A[t>>4&63],i+=A[t<<2&63],i+="="),o.push(i),o.join("")}function O(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<>1,h=-7,l=r?i-1:0,c=r?-1:1,d=e[t+l];for(l+=c,o=d&(1<<-h)-1,d>>=-h,h+=a;h>0;o=256*o+e[t+l],l+=c,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+e[t+l],l+=c,h-=8);if(0===o)o=1-f;else{if(o===u)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,n),o-=f}return(d?-1:1)*s*Math.pow(2,o-n)}function B(e,t,r,n,i,o){var s,a,u,f=8*o-i-1,h=(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=h):(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>=h?(a=0,s=h):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,f-=8);e[r+d-p]|=128*g}var D={}.toString,U=Array.isArray||function(e){return"[object Array]"==D.call(e)};function I(){return z.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Y(e,t){if(I()=I())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+I().toString(16)+" bytes");return 0|e}function J(e){return!(null==e||!e._isBuffer)}function V(e,t){if(J(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 be(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return _e(e).length;default:if(n)return be(e).length;t=(""+t).toLowerCase(),n=!0}}function $(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 oe(this,t,r);case"ascii":return ae(this,t,r);case"latin1":case"binary":return ue(this,t,r);case"base64":return ie(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return he(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function G(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function Z(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=z.from(t,n)),J(t))return 0===t.length?-1:K(e,t,r,n,i);if("number"==typeof t)return t&=255,z.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):K(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function K(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 f(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var h=-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 ie(e,t,r){return 0===t&&r===e.length?C(e):C(e.slice(t,r))}function oe(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i239?4:f>223?3:f>191?2:1;if(i+l<=r)switch(l){case 1:f<128&&(h=f);break;case 2:128==(192&(o=e[i+1]))&&(u=(31&f)<<6|63&o)>127&&(h=u);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(u=(15&f)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(h=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&f)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(h=u)}null===h?(h=65533,l=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),i+=l}return function(e){var t=e.length;if(t<=se)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+=" ... ")),""},z.prototype.compare=function(e,t,r,n,i){if(!J(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),f=e.slice(t,r),h=0;hi)&&(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 Q(this,e,t,r);case"utf8":case"utf-8":return X(this,e,t,r);case"ascii":return ee(this,e,t,r);case"latin1":case"binary":return te(this,e,t,r);case"base64":return re(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ne(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},z.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var se=4096;function ae(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 ce(e,t,r,n,i,o){if(!J(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||te.length)throw new RangeError("Index out of range")}function de(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 pe(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 ge(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 ve(e,t,r,n,i){return i||ge(e,0,r,4),B(e,t,r,n,23,4),r+4}function ye(e,t,r,n,i){return i||ge(e,0,r,8),B(e,t,r,n,52,8),r+8}z.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},z.prototype.readUInt8=function(e,t){return t||le(e,1,this.length),this[e]},z.prototype.readUInt16LE=function(e,t){return t||le(e,2,this.length),this[e]|this[e+1]<<8},z.prototype.readUInt16BE=function(e,t){return t||le(e,2,this.length),this[e]<<8|this[e+1]},z.prototype.readUInt32LE=function(e,t){return t||le(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},z.prototype.readUInt32BE=function(e,t){return t||le(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},z.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||le(e,t,this.length);for(var n=this[e],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*t)),n},z.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||le(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},z.prototype.readInt8=function(e,t){return t||le(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},z.prototype.readInt16LE=function(e,t){t||le(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},z.prototype.readInt16BE=function(e,t){t||le(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},z.prototype.readInt32LE=function(e,t){return t||le(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},z.prototype.readInt32BE=function(e,t){return t||le(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},z.prototype.readFloatLE=function(e,t){return t||le(e,4,this.length),O(this,e,!0,23,4)},z.prototype.readFloatBE=function(e,t){return t||le(e,4,this.length),O(this,e,!1,23,4)},z.prototype.readDoubleLE=function(e,t){return t||le(e,8,this.length),O(this,e,!0,52,8)},z.prototype.readDoubleBE=function(e,t){return t||le(e,8,this.length),O(this,e,!1,52,8)},z.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||ce(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},z.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||ce(this,e,t,1,255,0),z.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},z.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||ce(this,e,t,2,65535,0),z.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):de(this,e,t,!0),t+2},z.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||ce(this,e,t,2,65535,0),z.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):de(this,e,t,!1),t+2},z.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||ce(this,e,t,4,4294967295,0),z.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):pe(this,e,t,!0),t+4},z.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||ce(this,e,t,4,4294967295,0),z.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):pe(this,e,t,!1),t+4},z.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);ce(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},z.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);ce(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},z.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||ce(this,e,t,1,127,-128),z.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},z.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||ce(this,e,t,2,32767,-32768),z.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):de(this,e,t,!0),t+2},z.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||ce(this,e,t,2,32767,-32768),z.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):de(this,e,t,!1),t+2},z.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||ce(this,e,t,4,2147483647,-2147483648),z.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):pe(this,e,t,!0),t+4},z.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||ce(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),z.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):pe(this,e,t,!1),t+4},z.prototype.writeFloatLE=function(e,t,r){return ve(this,e,t,!0,r)},z.prototype.writeFloatBE=function(e,t,r){return ve(this,e,t,!1,r)},z.prototype.writeDoubleLE=function(e,t,r){return ye(this,e,t,!0,r)},z.prototype.writeDoubleBE=function(e,t,r){return ye(this,e,t,!1,r)},z.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||!z.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 _e(e){return function(e){var t,r,n,i,o,s;k||x();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 T(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(we,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Ee(e,t,r,n){for(var i=0;i=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function Re(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function je(){throw new Error("setTimeout has not been defined")}function Se(){throw new Error("clearTimeout has not been defined")}var Me=je,Ae=Se;function Le(e){if(Me===setTimeout)return setTimeout(e,0);if((Me===je||!Me)&&setTimeout)return Me=setTimeout,setTimeout(e,0);try{return Me(e,0)}catch(t){try{return Me.call(null,e,0)}catch(t){return Me.call(this,e,0)}}}"function"==typeof M.setTimeout&&(Me=setTimeout),"function"==typeof M.clearTimeout&&(Ae=clearTimeout);var Te,ke=[],xe=!1,Pe=-1;function Ce(){xe&&Te&&(xe=!1,Te.length?ke=Te.concat(ke):Pe=-1,ke.length&&Oe())}function Oe(){if(!xe){var e=Le(Ce);xe=!0;for(var t=ke.length;t;){for(Te=ke,ke=[];++Pe1)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]),at(t)?r.showHidden=t:t&&function(e,t){if(!t||!ct(t))return e;var r=Object.keys(t),n=r.length;for(;n--;)e[r[n]]=t[r[n]]}(r,t),ht(r.showHidden)&&(r.showHidden=!1),ht(r.depth)&&(r.depth=2),ht(r.colors)&&(r.colors=!1),ht(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=rt),it(r,e,r.depth)}function rt(e,t){var r=tt.styles[t];return r?"["+tt.colors[r][0]+"m"+e+"["+tt.colors[r][1]+"m":e}function nt(e,t){return e}function it(e,t,r){if(e.customInspect&&t&>(t.inspect)&&t.inspect!==tt&&(!t.constructor||t.constructor.prototype!==t)){var n=t.inspect(r,e);return ft(n)||(n=it(e,n,r)),n}var i=function(e,t){if(ht(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(at(t))return e.stylize(""+t,"boolean");if(ut(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)),pt(t)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return ot(t);if(0===o.length){if(gt(t)){var a=t.name?": "+t.name:"";return e.stylize("[Function"+a+"]","special")}if(lt(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(dt(t))return e.stylize(Date.prototype.toString.call(t),"date");if(pt(t))return ot(t)}var u,f,h="",l=!1,c=["{","}"];(u=t,Array.isArray(u)&&(l=!0,c=["[","]"]),gt(t))&&(h=" [Function"+(t.name?": "+t.name:"")+"]");return lt(t)&&(h=" "+RegExp.prototype.toString.call(t)),dt(t)&&(h=" "+Date.prototype.toUTCString.call(t)),pt(t)&&(h=" "+ot(t)),0!==o.length||l&&0!=t.length?r<0?lt(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special"):(e.seen.push(t),f=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]}(f,h,c)):c[0]+h+c[1]}function ot(e){return"["+Error.prototype.toString.call(e)+"]"}function st(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")),yt(n,i)||(s="["+i+"]"),a||(e.seen.indexOf(u.value)<0?(a=ut(r)?it(e,u.value,null):it(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")),ht(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 at(e){return"boolean"==typeof e}function ut(e){return null===e}function ft(e){return"string"==typeof e}function ht(e){return void 0===e}function lt(e){return ct(e)&&"[object RegExp]"===vt(e)}function ct(e){return"object"==typeof e&&null!==e}function dt(e){return ct(e)&&"[object Date]"===vt(e)}function pt(e){return ct(e)&&("[object Error]"===vt(e)||e instanceof Error)}function gt(e){return"function"==typeof e}function vt(e){return Object.prototype.toString.call(e)}function yt(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function wt(){this.head=null,this.tail=null,this.length=0}tt.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]},tt.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},wt.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},wt.prototype.unshift=function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length},wt.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}},wt.prototype.clear=function(){this.head=this.tail=null,this.length=0},wt.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},wt.prototype.concat=function(e){if(0===this.length)return z.alloc(0);if(1===this.length)return this.head.data;for(var t=z.allocUnsafe(e>>>0),r=this.head,n=0;r;)r.data.copy(t,n),n+=r.data.length,r=r.next;return t};var mt=z.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 bt(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),function(e){if(e&&!mt(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=Et;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=Rt;break;default:return void(this.write=_t)}this.charBuffer=new z(6),this.charReceived=0,this.charLength=0}function _t(e){return e.toString(this.encoding)}function Et(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function Rt(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}bt.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},bt.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},bt.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},Mt.ReadableState=St;var jt=function(e){if(ht(Xe)&&(Xe=$e.env.NODE_DEBUG||""),e=e.toUpperCase(),!et[e])if(new RegExp("\\b"+e+"\\b","i").test(Xe)){et[e]=function(){var t=Ke.apply(null,arguments);console.error("%s %d: %s",e,0,t)}}else et[e]=function(){};return et[e]}("stream");function St(e,t){e=e||{},this.objectMode=!!e.objectMode,t instanceof er&&(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 wt,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 bt(e.encoding),this.encoding=e.encoding)}function Mt(e){if(!(this instanceof Mt))return new Mt(e);this._readableState=new St(e,this),this.readable=!0,e&&"function"==typeof e.read&&(this._read=e.read),b.call(this)}function At(e,t,r,n,i){var o=function(e,t){var r=null;z.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,kt(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&&kt(e))),function(e,t){t.readingMore||(t.readingMore=!0,Be(Pt,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 kt(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(jt("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?Be(xt,e):xt(e))}function xt(e){jt("emit readable"),e.emit("readable"),Bt(e)}function Pt(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=z.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 Ut(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,Be(It,t,e))}function It(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 jt("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?Ut(this):kt(this),null;if(0===(e=Tt(e,t))&&t.ended)return 0===t.length&&Ut(this),null;var n,i=t.needReadable;return jt("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&&Ut(this)),null!==n&&this.emit("data",n),n},Mt.prototype._read=function(e){this.emit("error",new Error("not implemented"))},Mt.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,jt("pipe count=%d opts=%j",n.pipesCount,t);var i=!t||!1!==t.end?s:f;function o(e){jt("onunpipe"),e===r&&f()}function s(){jt("onend"),e.end()}n.endEmitted?Be(i):r.once("end",i),e.on("unpipe",o);var a=function(e){return function(){var t=e._readableState;jt("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&e.listeners("data").length&&(t.flowing=!0,Bt(e))}}(r);e.on("drain",a);var u=!1;function f(){jt("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",f),r.removeListener("data",l),u=!0,!n.awaitDrain||e._writableState&&!e._writableState.needDrain||a()}var h=!1;function l(t){jt("ondata"),h=!1,!1!==e.write(t)||h||((1===n.pipesCount&&n.pipes===e||n.pipesCount>1&&-1!==Yt(n.pipes,e))&&!u&&(jt("false write response, pause",r._readableState.awaitDrain),r._readableState.awaitDrain++,h=!0),r.pause())}function c(t){var r;jt("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(){jt("onfinish"),e.removeListener("close",d),g()}function g(){jt("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||(jt("pipe resume"),r.resume()),e},Mt.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},qt.prototype._write=function(e,t,r){r(new Error("not implemented"))},qt.prototype._writev=null,qt.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,Gt(e,t),r&&(t.finished?Be(r):e.once("finish",r));t.ended=!0,e.writable=!1}(this,n,r)},Ge(er,Mt);for(var Kt=Object.keys(qt.prototype),Qt=0;Qt()=>{}}))("from-constant-stream"),lr=ur.Readable;function cr(t,a){var h,c;if(!(this instanceof cr))return arguments.length>1?new cr(t,a):new cr(t);if(h=u({},fr),arguments.length>1&&(c=function(e,t){return d(t)?p(t,"sep")&&(e.sep=t.sep,!r(e.sep))?new TypeError(f("1MD2W","sep",e.sep)):p(t,"objectMode")&&(e.objectMode=t.objectMode,!g(e.objectMode))?new TypeError(f("1MD2o","objectMode",e.objectMode)):p(t,"encoding")&&(e.encoding=t.encoding,!r(e.encoding)&&null!==e.encoding)?new TypeError(f("1MD7n","encoding",e.encoding)):p(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!v(e.highWaterMark))?new TypeError(f("1MD4k","highWaterMark",e.highWaterMark)):p(t,"iter")&&(e.iter=t.iter,!y(e.iter))?new TypeError(f("1MD2t","iter",e.iter)):null:new TypeError(f("1MD2V",t))}(h,a),c))throw c;if(!1===h.objectMode)if(r(t))t=s(t);else if(n(t));else{if(!i(t))throw new TypeError(f("1MDAA",t));t=o(t.buffer,t.byteOffset,t.length)}return hr("Creating a readable stream configured with the following options: %s.",JSON.stringify(h)),lr.call(this,h),l(this,"_destroyed",!1),e(this,"_objectMode",h.objectMode),e(this,"_sep",s(h.sep)),e(this,"_iter",h.iter),e(this,"_value",t),l(this,"_i",0),this}function dr(e,t){var r;if(arguments.length>1){if(!d(r=t))throw new TypeError(f("1MD2V",r));r=u({},t)}else r={};return r.objectMode=!0,new cr(e,r)}function pr(e,t){var r,n,i;if(0===(r=arguments.length))n={},i=!0;else if(1===r)null!==e&&"object"==typeof e&&(p(e,"sep")||p(e,"iter")||p(e,"objectMode")||p(e,"encoding")||p(e,"highWaterMark"))?(n=u({},e),i=!0):n={};else{if(!d(t))throw new TypeError(f("1MD2V",t));n=u({},t)}return i?function(e){return new cr(e,n)}:function(){return new cr(e,n)}}h(cr,lr),e(cr.prototype,"_read",(function(){var e;if(!this._destroyed)for(e=!0;e;){if(this._i+=1,this._i>this._iter)return hr("Finished iteration."),this.push(null);hr("Value: %s. Iter: %d.",this._value,this._i),e=!1===this._objectMode&&this._i>1?this.push(a.concat([this._sep,this._value])):this.push(this._value)}})),e(cr.prototype,"destroy",(function(e){var r;return this._destroyed?(hr("Attempted to destroy an already destroyed stream."),this):(r=this,this._destroyed=!0,c((function(){e&&(hr("Stream was destroyed due to an error. Error: %s.",t(e)?e.message:JSON.stringify(e)),r.emit("error",e));hr("Closing the stream..."),r.emit("close")})),this)})),e(cr,"objectMode",dr),e(cr,"factory",pr);export{cr as default,pr as factory,dr as objectMode}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..915f159 --- /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-constant-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 isError from '@stdlib/assert-is-error';\nimport { isPrimitive as isString } from '@stdlib/assert-is-string';\nimport isBuffer from '@stdlib/assert-is-buffer';\nimport isUint8Array from '@stdlib/assert-is-uint8array';\nimport arraybuffer2buffer from '@stdlib/buffer-from-arraybuffer';\nimport string2buffer from '@stdlib/buffer-from-string';\nimport Buffer from '@stdlib/buffer-ctor'; // TODO: replace Buffer.concat usage with stdlib pkg\nimport assign from '@stdlib/object-assign';\nimport format from '@stdlib/error-tools-fmtprodmsg';\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 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\tif ( this._destroyed ) {\n\t\treturn;\n\t}\n\tFLG = true;\n\twhile ( FLG ) {\n\t\tthis._i += 1;\n\t\tif ( this._i > this._iter ) {\n\t\t\tdebug( 'Finished iteration.' );\n\t\t\treturn this.push( null );\n\t\t}\n\t\tdebug( 'Value: %s. Iter: %d.', this._value, this._i );\n\t\tif ( this._objectMode === false && this._i > 1 ) {\n\t\t\tFLG = this.push( Buffer.concat( [ this._sep, this._value ] ) );\n\t\t} else {\n\t\t\tFLG = this.push( this._value );\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 {ConstantStream} 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 stream which always streams the same value.\n*\n* @constructor\n* @param {(string|Buffer|Uint8Array)} value - value to stream\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 {NonNegativeInteger} [options.iter] - number of iterations\n* @throws {TypeError} in binary mode, value to stream must be a string, `Buffer`, or `Uint8Array`\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ConstantStream} Stream instance\n*\n* @example\n* import inspectStream from '@stdlib/streams-node-inspect-sink';\n*\n* function log( chunk ) {\n* console.log( chunk.toString() );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = new ConstantStream( 'beep', opts );\n*\n* stream.pipe( inspectStream( log ) );\n*/\nfunction ConstantStream( value, options ) {\n\tvar opts;\n\tvar err;\n\tif ( !( this instanceof ConstantStream ) ) {\n\t\tif ( arguments.length > 1 ) {\n\t\t\treturn new ConstantStream( value, options );\n\t\t}\n\t\treturn new ConstantStream( value );\n\t}\n\topts = assign( {}, DEFAULTS );\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tif ( opts.objectMode === false ) {\n\t\tif ( isString( value ) ) {\n\t\t\tvalue = string2buffer( value );\n\t\t} else if ( isBuffer( value ) ) { // NOTE: order matters here. We want the `isBuffer` check BEFORE the `isUint8Array` check!!\n\t\t\t// Nothing to do, as value is already a buffer...\n\t\t} else if ( isUint8Array( value ) ) {\n\t\t\t// Convert to a `Buffer` object to provide backward compatibility with older Node.js versions...\n\t\t\tvalue = arraybuffer2buffer( value.buffer, value.byteOffset, value.length ); // eslint-disable-line max-len\n\t\t} else {\n\t\t\tthrow new TypeError( format( '1MDAA', value ) );\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', string2buffer( opts.sep ) );\n\n\t// Cache the total number of iterations:\n\tsetNonEnumerableReadOnly( this, '_iter', opts.iter );\n\n\t// Cache the value to stream:\n\tsetNonEnumerableReadOnly( this, '_value', value );\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( ConstantStream, Readable );\n\n/**\n* Implements the `_read` method.\n*\n* @private\n* @name _read\n* @memberof ConstantStream.prototype\n* @type {Function}\n* @param {number} size - number (of bytes) to read\n* @returns {void}\n*/\nsetNonEnumerableReadOnly( ConstantStream.prototype, '_read', read );\n\n/**\n* Gracefully destroys a stream, providing backward compatibility.\n*\n* @name destroy\n* @memberof ConstantStream.prototype\n* @type {Function}\n* @param {(string|Object|Error)} [error] - error\n* @returns {ConstantStream} Stream instance\n*/\nsetNonEnumerableReadOnly( ConstantStream.prototype, 'destroy', destroy );\n\n\n// EXPORTS //\n\nexport default ConstantStream;\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 { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\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 {NonNegativeInteger} [options.iter] - number of iterations\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( '1MD2V', 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( '1MD2W', '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( '1MD2o', '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( '1MD7n', '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( '1MD4k', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'iter' ) ) {\n\t\topts.iter = options.iter;\n\t\tif ( !isNonNegativeInteger( opts.iter ) ) {\n\t\t\treturn new TypeError( format( '1MD2t', 'iter', opts.iter ) );\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 ConstantStream from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns an \"objectMode\" readable stream which always streams the same value.\n*\n* @param {*} value - value to stream\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* @param {NonNegativeInteger} [options.iter] - number of iterations\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {ConstantStream} Stream instance\n*\n* @example\n* import inspectStream from '@stdlib/streams-node-inspect-sink';\n*\n* function log( v ) {\n* console.log( v );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = objectMode( 3.14, opts );\n*\n* stream.pipe( inspectStream.objectMode( log ) );\n*/\nfunction objectMode( value, options ) {\n\tvar opts;\n\tif ( arguments.length > 1 ) {\n\t\topts = options;\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '1MD2V', opts ) );\n\t\t}\n\t\topts = assign( {}, options );\n\t} else {\n\t\topts = {};\n\t}\n\topts.objectMode = true;\n\treturn new ConstantStream( value, 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 hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport assign from '@stdlib/object-assign';\nimport ConstantStream from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating readable streams which always stream the same value.\n*\n* @param {(string|Buffer|Uint8Array|*)} [value] - value to stream\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 {NonNegativeInteger} [options.iter] - number of iterations\n* @throws {TypeError} options argument must be an object\n* @returns {Function} stream factory\n*\n* @example\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* var i;\n* for ( i = 0; i < 10; i++ ) {\n* streams.push( createStream( i.toString() ) );\n* }\n*/\nfunction factory( value, options ) {\n\tvar nargs;\n\tvar opts;\n\tvar fcn;\n\tvar FLG;\n\n\tnargs = arguments.length;\n\tif ( nargs === 0 ) {\n\t\topts = {};\n\t\tFLG = true;\n\t} else if ( nargs === 1 ) {\n\t\t// Check (imperfectly!) whether we were provided an \"options\" object...\n\t\tif (\n\t\t\tvalue !== null &&\n\t\t\ttypeof value === 'object' &&\n\t\t\t(\n\t\t\t\thasOwnProp( value, 'sep' ) ||\n\t\t\t\thasOwnProp( value, 'iter' ) ||\n\t\t\t\thasOwnProp( value, 'objectMode' ) ||\n\t\t\t\thasOwnProp( value, 'encoding' ) ||\n\t\t\t\thasOwnProp( value, 'highWaterMark' )\n\t\t\t)\n\t\t) {\n\t\t\topts = assign( {}, value );\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\topts = {};\n\t\t}\n\t} else { // nargs > 1\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1MD2V', options ) );\n\t\t}\n\t\topts = assign( {}, options );\n\t}\n\tif ( FLG ) {\n\t\tfcn = createStream1;\n\t} else {\n\t\tfcn = createStream2;\n\t}\n\treturn fcn;\n\n\t/**\n\t* Returns a readable stream which always streams the same value.\n\t*\n\t* @private\n\t* @param {(string|Buffer|Uint8Array|*)} value - value to stream\n\t* @throws {TypeError} in binary mode, value to stream must be a string, Buffer, or Uint8Array\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ConstantStream} Stream instance\n\t*/\n\tfunction createStream1( value ) {\n\t\treturn new ConstantStream( value, opts );\n\t}\n\n\t/**\n\t* Returns a readable stream which always streams the same value.\n\t*\n\t* @private\n\t* @throws {TypeError} in binary mode, value to stream must be a string, Buffer, or Uint8Array\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @returns {ConstantStream} Stream instance\n\t*/\n\tfunction createStream2() {\n\t\treturn new ConstantStream( value, 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 which always streams the same value.\n*\n* @module @stdlib/streams-node-from-constant\n*\n* @example\n* import inspectStream from '@stdlib/streams-node-inspect-sink';\n* import constantStream from '@stdlib/streams-node-from-constant';\n*\n* function log( chunk ) {\n* console.log( chunk.toString() );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = constantStream( 'beep', opts );\n*\n* stream.pipe( inspectStream( log ) );\n*\n* @example\n* import constantStream from '@stdlib/streams-node-from-constant';\n*\n* var opts = {\n* 'sep': ',',\n* 'objectMode': false,\n* 'encoding': 'utf8',\n* 'highWaterMark': 64\n* };\n*\n* var createStream = constantStream.factory( opts );\n*\n* // Create 10 identically configured streams...\n* var streams = [];\n* var i;\n* for ( i = 0; i < 10; i++ ) {\n* streams.push( createStream( i.toString() ) );\n* }\n*\n* @example\n* import inspectStream from '@stdlib/streams-node-inspect-sink';\n* import constantStream from '@stdlib/streams-node-from-constant';\n*\n* function log( v ) {\n* console.log( v );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = constantStream.objectMode( 3.14, opts );\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","ConstantStream","value","options","opts","err","this","arguments","length","assign","DEFAULTS","isObject","hasOwnProp","sep","isString","TypeError","format","objectMode","isBoolean","encoding","highWaterMark","isNonNegative","iter","isNonNegativeInteger","validate","string2buffer","isBuffer","isUint8Array","arraybuffer2buffer","buffer","byteOffset","JSON","stringify","call","setNonEnumerable","setNonEnumerableReadOnly","factory","nargs","FLG","inherit","prototype","_destroyed","_i","_iter","push","_value","_objectMode","Buffer","concat","_sep","error","self","nextTick","isError","message","emit","setReadOnly","main"],"mappings":";;mixDA2BIA,wDAAQC,CAAQ,wBCLhBC,GAAWC,GAA6BD,SA4H5C,SAASE,GAAgBC,EAAOC,GAC/B,IAAIC,EACAC,EACJ,KAAQC,gBAAgBL,IACvB,OAAKM,UAAUC,OAAS,EAChB,IAAIP,GAAgBC,EAAOC,GAE5B,IAAIF,GAAgBC,GAG5B,GADAE,EAAOK,EAAQ,GAAIC,IACdH,UAAUC,OAAS,IACvBH,ECrGF,SAAmBD,EAAMD,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,SACzBC,EAAKS,IAAMV,EAAQU,KACbC,EAAUV,EAAKS,MACb,IAAIE,UAAWC,EAAQ,QAAS,MAAOZ,EAAKS,MAGhDD,EAAYT,EAAS,gBACzBC,EAAKa,WAAad,EAAQc,YACpBC,EAAWd,EAAKa,aACd,IAAIF,UAAWC,EAAQ,QAAS,aAAcZ,EAAKa,aAGvDL,EAAYT,EAAS,cACzBC,EAAKe,SAAWhB,EAAQgB,UAClBL,EAAUV,EAAKe,WAAgC,OAAlBf,EAAKe,UAChC,IAAIJ,UAAWC,EAAQ,QAAS,WAAYZ,EAAKe,WAGrDP,EAAYT,EAAS,mBACzBC,EAAKgB,cAAgBjB,EAAQiB,eACvBC,EAAejB,EAAKgB,gBAClB,IAAIL,UAAWC,EAAQ,QAAS,gBAAiBZ,EAAKgB,gBAG1DR,EAAYT,EAAS,UACzBC,EAAKkB,KAAOnB,EAAQmB,MACdC,EAAsBnB,EAAKkB,OACzB,IAAIP,UAAWC,EAAQ,QAAS,OAAQZ,EAAKkB,OAG/C,KAhCC,IAAIP,UAAWC,EAAQ,QAASb,GAiCzC,CDkEQqB,CAAUpB,EAAMD,GACjBE,GACJ,MAAMA,EAGR,IAAyB,IAApBD,EAAKa,WACT,GAAKH,EAAUZ,GACdA,EAAQuB,EAAevB,QACjB,GAAKwB,EAAUxB,QAEf,KAAKyB,EAAczB,GAIzB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAFtCA,EAAQ0B,EAAoB1B,EAAM2B,OAAQ3B,EAAM4B,WAAY5B,EAAMM,OAGlE,CAwBF,OArBAX,GAAO,wEAAyEkC,KAAKC,UAAW5B,IAChGL,GAASkC,KAAM3B,KAAMF,GAGrB8B,EAAkB5B,KAAM,cAAc,GAGtC6B,EAA0B7B,KAAM,cAAeF,EAAKa,YAGpDkB,EAA0B7B,KAAM,OAAQmB,EAAerB,EAAKS,MAG5DsB,EAA0B7B,KAAM,QAASF,EAAKkB,MAG9Ca,EAA0B7B,KAAM,SAAUJ,GAG1CgC,EAAkB5B,KAAM,KAAM,GAEvBA,IACR,CE5IA,SAASW,GAAYf,EAAOC,GAC3B,IAAIC,EACJ,GAAKG,UAAUC,OAAS,EAAI,CAE3B,IAAMG,EADNP,EAAOD,GAEN,MAAM,IAAIY,UAAWC,EAAQ,QAASZ,IAEvCA,EAAOK,EAAQ,GAAIN,EACrB,MACEC,EAAO,CAAA,EAGR,OADAA,EAAKa,YAAa,EACX,IAAIhB,GAAgBC,EAAOE,EACnC,CCTA,SAASgC,GAASlC,EAAOC,GACxB,IAAIkC,EACAjC,EAEAkC,EAGJ,GAAe,KADfD,EAAQ9B,UAAUC,QAEjBJ,EAAO,CAAA,EACPkC,GAAM,OACA,GAAe,IAAVD,EAGA,OAAVnC,GACiB,iBAAVA,IAENU,EAAYV,EAAO,QACnBU,EAAYV,EAAO,SACnBU,EAAYV,EAAO,eACnBU,EAAYV,EAAO,aACnBU,EAAYV,EAAO,mBAGpBE,EAAOK,EAAQ,GAAIP,GACnBoC,GAAM,GAENlC,EAAO,CAAA,MAEF,CACN,IAAMO,EAAUR,GACf,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAEvCC,EAAOK,EAAQ,GAAIN,EACnB,CAMD,OALKmC,EAiBL,SAAwBpC,GACvB,OAAO,IAAID,GAAgBC,EAAOE,EAClC,EAWD,WACC,OAAO,IAAIH,GAAgBC,EAAOE,EAClC,CACF,CH0EAmC,EAAStC,GAAgBF,IAYzBoC,EAA0BlC,GAAeuC,UAAW,SApKpD,WAEC,IAAIF,EACJ,IAAKhC,KAAKmC,WAIV,IADAH,GAAM,EACEA,GAAM,CAEb,GADAhC,KAAKoC,IAAM,EACNpC,KAAKoC,GAAKpC,KAAKqC,MAEnB,OADA9C,GAAO,uBACAS,KAAKsC,KAAM,MAEnB/C,GAAO,uBAAwBS,KAAKuC,OAAQvC,KAAKoC,IAEhDJ,GADyB,IAArBhC,KAAKwC,aAAyBxC,KAAKoC,GAAK,EACtCpC,KAAKsC,KAAMG,EAAOC,OAAQ,CAAE1C,KAAK2C,KAAM3C,KAAKuC,UAE5CvC,KAAKsC,KAAMtC,KAAKuC,OAEvB,CAGF,IAyJAV,EAA0BlC,GAAeuC,UAAW,WAhJpD,SAAkBU,GAEjB,IAAIC,EACJ,OAAK7C,KAAKmC,YACT5C,GAAO,qDACAS,OAER6C,EAAO7C,KACPA,KAAKmC,YAAa,EAElBW,GASA,WACMF,IACJrD,GAAO,mDAAsDwD,EAASH,GAAYA,EAAMI,QAAUvB,KAAKC,UAAWkB,IAClHC,EAAKI,KAAM,QAASL,IAErBrD,GAAO,yBACPsD,EAAKI,KAAM,QACX,IAdMjD,KAiBR,IItBAkD,EAAAC,GAAA,aAAAxC,IACAuC,EAAAC,GAAA,UAAArB"} \ No newline at end of file diff --git a/lib/debug.js b/lib/debug.js deleted file mode 100644 index 8cc7a33..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-constant-stream' ); - - -// EXPORTS // - -module.exports = debug; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 0395bc1..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "objectMode": false, - "encoding": null, - "sep": "\n", - "iter": 1e308 -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index fdefe65..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,134 +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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var format = require( '@stdlib/string-format' ); -var assign = require( '@stdlib/object-assign' ); -var ConstantStream = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating readable streams which always stream the same value. -* -* @param {(string|Buffer|Uint8Array|*)} [value] - value to stream -* @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 {NonNegativeInteger} [options.iter] - number of iterations -* @throws {TypeError} options argument must be an object -* @returns {Function} stream factory -* -* @example -* var opts = { -* 'sep': ',', -* 'objectMode': false, -* 'encoding': 'utf8', -* 'highWaterMark': 64 -* }; -* -* var createStream = factory( opts ); -* -* // Create 10 identically configured streams... -* var streams = []; -* var i; -* for ( i = 0; i < 10; i++ ) { -* streams.push( createStream( i.toString() ) ); -* } -*/ -function factory( value, options ) { - var nargs; - var opts; - var fcn; - var FLG; - - nargs = arguments.length; - if ( nargs === 0 ) { - opts = {}; - FLG = true; - } else if ( nargs === 1 ) { - // Check (imperfectly!) whether we were provided an "options" object... - if ( - value !== null && - typeof value === 'object' && - ( - hasOwnProp( value, 'sep' ) || - hasOwnProp( value, 'iter' ) || - hasOwnProp( value, 'objectMode' ) || - hasOwnProp( value, 'encoding' ) || - hasOwnProp( value, 'highWaterMark' ) - ) - ) { - opts = assign( {}, value ); - FLG = true; - } else { - opts = {}; - } - } else { // nargs > 1 - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - opts = assign( {}, options ); - } - if ( FLG ) { - fcn = createStream1; - } else { - fcn = createStream2; - } - return fcn; - - /** - * Returns a readable stream which always streams the same value. - * - * @private - * @param {(string|Buffer|Uint8Array|*)} value - value to stream - * @throws {TypeError} in binary mode, value to stream must be a string, Buffer, or Uint8Array - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ConstantStream} Stream instance - */ - function createStream1( value ) { - return new ConstantStream( value, opts ); - } - - /** - * Returns a readable stream which always streams the same value. - * - * @private - * @throws {TypeError} in binary mode, value to stream must be a string, Buffer, or Uint8Array - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @returns {ConstantStream} Stream instance - */ - function createStream2() { - return new ConstantStream( value, opts ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 00edc67..0000000 --- a/lib/index.js +++ /dev/null @@ -1,95 +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 which always streams the same value. -* -* @module @stdlib/streams-node-from-constant -* -* @example -* var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -* var constantStream = require( '@stdlib/streams-node-from-constant' ); -* -* function log( chunk ) { -* console.log( chunk.toString() ); -* } -* -* var opts = { -* 'iter': 10 -* }; -* -* var stream = constantStream( 'beep', opts ); -* -* stream.pipe( inspectStream( log ) ); -* -* @example -* var constantStream = require( '@stdlib/streams-node-from-constant' ); -* -* var opts = { -* 'sep': ',', -* 'objectMode': false, -* 'encoding': 'utf8', -* 'highWaterMark': 64 -* }; -* -* var createStream = constantStream.factory( opts ); -* -* // Create 10 identically configured streams... -* var streams = []; -* var i; -* for ( i = 0; i < 10; i++ ) { -* streams.push( createStream( i.toString() ) ); -* } -* -* @example -* var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -* var constantStream = require( '@stdlib/streams-node-from-constant' ); -* -* function log( v ) { -* console.log( v ); -* } -* -* var opts = { -* 'iter': 10 -* }; -* -* var stream = constantStream.objectMode( 3.14, opts ); -* -* 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 4b1fda3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +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 isError = require( '@stdlib/assert-is-error' ); -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isBuffer = require( '@stdlib/assert-is-buffer' ); -var isUint8Array = require( '@stdlib/assert-is-uint8array' ); -var arraybuffer2buffer = require( '@stdlib/buffer-from-arraybuffer' ); -var string2buffer = require( '@stdlib/buffer-from-string' ); -var Buffer = require( '@stdlib/buffer-ctor' ); // TODO: replace Buffer.concat usage with stdlib pkg -var assign = require( '@stdlib/object-assign' ); -var format = require( '@stdlib/string-format' ); -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 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; - if ( this._destroyed ) { - return; - } - FLG = true; - while ( FLG ) { - this._i += 1; - if ( this._i > this._iter ) { - debug( 'Finished iteration.' ); - return this.push( null ); - } - debug( 'Value: %s. Iter: %d.', this._value, this._i ); - if ( this._objectMode === false && this._i > 1 ) { - FLG = this.push( Buffer.concat( [ this._sep, this._value ] ) ); - } else { - FLG = this.push( this._value ); - } - } - - /* eslint-enable no-invalid-this */ -} - -/** -* Gracefully destroys a stream, providing backward compatibility. -* -* @private -* @param {(string|Object|Error)} [error] - error -* @returns {ConstantStream} 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 stream which always streams the same value. -* -* @constructor -* @param {(string|Buffer|Uint8Array)} value - value to stream -* @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 {NonNegativeInteger} [options.iter] - number of iterations -* @throws {TypeError} in binary mode, value to stream must be a string, `Buffer`, or `Uint8Array` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ConstantStream} Stream instance -* -* @example -* var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -* -* function log( chunk ) { -* console.log( chunk.toString() ); -* } -* -* var opts = { -* 'iter': 10 -* }; -* -* var stream = new ConstantStream( 'beep', opts ); -* -* stream.pipe( inspectStream( log ) ); -*/ -function ConstantStream( value, options ) { - var opts; - var err; - if ( !( this instanceof ConstantStream ) ) { - if ( arguments.length > 1 ) { - return new ConstantStream( value, options ); - } - return new ConstantStream( value ); - } - opts = assign( {}, DEFAULTS ); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( opts.objectMode === false ) { - if ( isString( value ) ) { - value = string2buffer( value ); - } else if ( isBuffer( value ) ) { // NOTE: order matters here. We want the `isBuffer` check BEFORE the `isUint8Array` check!! - // Nothing to do, as value is already a buffer... - } else if ( isUint8Array( value ) ) { - // Convert to a `Buffer` object to provide backward compatibility with older Node.js versions... - value = arraybuffer2buffer( value.buffer, value.byteOffset, value.length ); // eslint-disable-line max-len - } else { - throw new TypeError( format( 'invalid argument. In binary mode, a provided value must be a string, Buffer, or Uint8Array. Value: `%s`.', value ) ); - } - } - // 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', string2buffer( opts.sep ) ); - - // Cache the total number of iterations: - setNonEnumerableReadOnly( this, '_iter', opts.iter ); - - // Cache the value to stream: - setNonEnumerableReadOnly( this, '_value', value ); - - // Initialize an iteration counter: - setNonEnumerable( this, '_i', 0 ); - - return this; -} - -/* -* Inherit from the `Readable` prototype. -*/ -inherit( ConstantStream, Readable ); - -/** -* Implements the `_read` method. -* -* @private -* @name _read -* @memberof ConstantStream.prototype -* @type {Function} -* @param {number} size - number (of bytes) to read -* @returns {void} -*/ -setNonEnumerableReadOnly( ConstantStream.prototype, '_read', read ); - -/** -* Gracefully destroys a stream, providing backward compatibility. -* -* @name destroy -* @memberof ConstantStream.prototype -* @type {Function} -* @param {(string|Object|Error)} [error] - error -* @returns {ConstantStream} Stream instance -*/ -setNonEnumerableReadOnly( ConstantStream.prototype, 'destroy', destroy ); - - -// EXPORTS // - -module.exports = ConstantStream; diff --git a/lib/object_mode.js b/lib/object_mode.js deleted file mode 100644 index b6a5a39..0000000 --- a/lib/object_mode.js +++ /dev/null @@ -1,76 +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 ConstantStream = require( './main.js' ); - - -// MAIN // - -/** -* Returns an "objectMode" readable stream which always streams the same value. -* -* @param {*} value - value to stream -* @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 -* @param {NonNegativeInteger} [options.iter] - number of iterations -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {ConstantStream} Stream instance -* -* @example -* var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -* -* function log( v ) { -* console.log( v ); -* } -* -* var opts = { -* 'iter': 10 -* }; -* -* var stream = objectMode( 3.14, opts ); -* -* stream.pipe( inspectStream.objectMode( log ) ); -*/ -function objectMode( value, options ) { - var opts; - if ( arguments.length > 1 ) { - 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 ConstantStream( value, opts ); -} - - -// EXPORTS // - -module.exports = objectMode; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 3968b1f..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 isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -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 {NonNegativeInteger} [options.iter] - number of iterations -* @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, 'iter' ) ) { - opts.iter = options.iter; - if ( !isNonNegativeInteger( opts.iter ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', opts.iter ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 782cca7..736a370 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.2", "description": "Create a readable stream which always streams the same value.", "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" - } - ], - "bin": { - "constant-stream": "./bin/cli" - }, - "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", @@ -39,59 +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-error": "^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/assert-is-uint8array": "^0.2.2", - "@stdlib/buffer-ctor": "^0.2.2", - "@stdlib/buffer-from-arraybuffer": "^0.2.2", - "@stdlib/buffer-from-string": "^0.2.2", - "@stdlib/cli-ctor": "^0.2.2", - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/object-assign": "^0.2.2", - "@stdlib/streams-node-stdout": "^0.2.2", - "@stdlib/string-format": "^0.2.2", - "@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-uint8": "^0.2.2", - "@stdlib/assert-is-browser": "^0.2.2", - "@stdlib/assert-is-windows": "^0.2.2", - "@stdlib/blas-base-gcopy": "^0.2.1", - "@stdlib/process-exec-path": "^0.2.2", - "@stdlib/streams-node-inspect-sink": "^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..2dc1bc2 --- /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.cli.js b/test/test.cli.js deleted file mode 100644 index 3ae065b..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,233 +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 resolve = require( 'path' ).resolve; -var exec = require( 'child_process' ).exec; -var tape = require( 'tape' ); -var IS_BROWSER = require( '@stdlib/assert-is-browser' ); -var IS_WINDOWS = require( '@stdlib/assert-is-windows' ); -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var EXEC_PATH = require( '@stdlib/process-exec-path' ); - - -// VARIABLES // - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); -var opts = { - 'skip': IS_BROWSER || IS_WINDOWS -}; - - -// FIXTURES // - -var PKG_VERSION = require( './../package.json' ).version; - - -// TESTS // - -tape( 'command-line interface', function test( t ) { - t.ok( true, __filename ); - t.end(); -}); - -tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '--help' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { - var expected; - var cmd; - - expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { - 'encoding': 'utf8' - }); - cmd = [ - EXEC_PATH, - fpath, - '-h' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '--version' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '-V' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); - } - t.end(); - } -}); - -tape( 'if provided insufficient arguments, the command-line interface prints an error and sets a non-zero exit code (none)', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } else { - t.fail( 'should error' ); - } - t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); - t.strictEqual( stderr.toString().length > 0, true, 'prints to `stderr`' ); - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the number of streamed values', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '3.14', - '--iter 10' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var results; - var v; - var i; - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - - results = stdout.toString(); - results = results.split( '\n' ); - - // 10 values + trailing newline: - t.strictEqual( results.length, 11, 'has expected length' ); - for ( i = 0; i < results.length-1; i++ ) { - v = parseFloat( results[ i ] ); - t.strictEqual( v, 3.14, 'is expected value' ); - } - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '3.14', - '--iter 10', - '--sep aba' - ]; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var results; - var v; - var i; - if ( error ) { - t.fail( error.message ); - } else { - t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); - - results = stdout.toString(); - results = results.split( '\n' ); - - // Only trailing newline: - t.strictEqual( results.length, 2, 'has expected length' ); - - results = results[ 0 ].split( 'aba' ); - t.strictEqual( results.length, 10, 'has expected length' ); - for ( i = 0; i < results.length-1; i++ ) { - v = parseFloat( results[ i ] ); - t.strictEqual( v, 3.14, 'is expected value' ); - } - } - t.end(); - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 5277617..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,362 +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 ConstantStream = 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({ - 'iter': 10 - }); - t.equal( typeof createStream, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a factory function (parameters)', function test( t ) { - var createStream = factory( 'beep' ); - t.equal( typeof createStream, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a factory function (parameters + options)', function test( t ) { - var createStream = factory( 'beep', {} ); - t.equal( typeof createStream, 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided a string, Buffer, or Uint8Array in binary mode', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - 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 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided a string, Buffer, or Uint8Array in binary mode (parameters)', function test( t ) { - var values; - var i; - - values = [ - 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( value ); - createStream(); - }; - } -}); - -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( 'beep', value ); - createStream(); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid `iter` option', function test( t ) { - var values; - var i; - - values = [ - 'abc', - -5, - 3.14, - null, - true, - false, - void 0, - NaN, - [], - {}, - 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({ - 'iter': value - }); - createStream( 'beep' ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid `iter` option (parameters)', function test( t ) { - var values; - var i; - - values = [ - 'abc', - -5, - 3.14, - null, - true, - false, - void 0, - NaN, - [], - {}, - 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( 'beep', { - 'iter': value - }); - createStream(); - }; - } -}); - -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( 'beep' ); - }; - } -}); - -tape( 'if provided an invalid readable stream option, the function returns a function which throws an error (parameters)', 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( 'beep', { - 'highWaterMark': value - }); - createStream(); - }; - } -}); - -tape( 'the function returns a factory function which creates stream instances', function test( t ) { - var createStream; - var i; - - createStream = factory(); - - for ( i = 0; i < 10; i++ ) { - t.equal( createStream( 'beep' ) instanceof ConstantStream, 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 i; - - createStream = factory({ - 'iter': 10 - }); - - for ( i = 0; i < 10; i++ ) { - t.equal( createStream( 'beep' ) instanceof ConstantStream, true, 'returns a stream instance' ); - } - t.end(); -}); - -tape( 'the function returns a factory function which creates stream instances (parameters)', function test( t ) { - var createStream; - var i; - - createStream = factory( 'beep' ); - - for ( i = 0; i < 10; i++ ) { - t.equal( createStream() instanceof ConstantStream, true, 'returns a stream instance' ); - } - t.end(); -}); - -tape( 'the function returns a factory function which creates stream instances (parameters + options)', function test( t ) { - var createStream; - var i; - - createStream = factory( 'beep', {} ); - - for ( i = 0; i < 10; i++ ) { - t.equal( createStream() instanceof ConstantStream, true, 'returns a stream instance' ); - } - t.end(); -}); - -tape( 'the function returns a function which creates streams which always stream the same value (empty object; object mode)', function test( t ) { - var constantStream; - var iStream; - var value; - var opts; - var s; - - value = {}; - - opts = { - 'iter': 10, - 'objectMode': true - }; - constantStream = factory( value, opts ); - - s = constantStream(); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - s.pipe( iStream ); - - function inspect( v ) { - t.equal( v, value, 'returns expected value' ); - } - - function onEnd() { - t.pass( 'stream ended' ); - t.end(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 58672db..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 constantStream = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof constantStream, '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 constantStream.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 constantStream.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index a543889..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,552 +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 gcopy = require( '@stdlib/blas-base-gcopy' ); -var string2buffer = require( '@stdlib/buffer-from-string' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -var constantStream = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof constantStream, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a string, Buffer, or Uint8Array when in binary mode', function test( t ) { - var values; - var i; - - values = [ - 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() { - constantStream( value ); - }; - } -}); - -tape( 'the function throws an error if not provided a string, Buffer, or Uint8Array when in binary mode (options)', function test( t ) { - var values; - var i; - - values = [ - 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() { - constantStream( 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, - null, - true, - false, - void 0, - NaN, - [], - 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() { - constantStream( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid `iter` option', function test( t ) { - var values; - var i; - - values = [ - 'abc', - -5, - 3.14, - null, - true, - false, - void 0, - NaN, - [], - {}, - 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() { - constantStream( 'beep', { - 'iter': 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() { - constantStream( 'beep', { - 'objectMode': value - }); - }; - } -}); - -tape( 'the function is a constructor which returns a readable stream', function test( t ) { - var ConstantStream = constantStream; - var s; - - s = new ConstantStream( 'beep' ); - t.equal( s instanceof Readable, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` operator', function test( t ) { - var ConstantStream = constantStream; - var s; - - s = constantStream( 'beep' ); - t.equal( s instanceof ConstantStream, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a readable stream (no new)', function test( t ) { - var s = constantStream( 'beep' ); - 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 = constantStream( 'boop' ); - - 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 = constantStream( 'beep' ); - - 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 = constantStream( 'beep' ); - - 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 always streams the same value (string)', function test( t ) { - var iStream; - var result; - var opts; - var s; - - opts = { - 'iter': 10, - 'sep': '\n' - }; - s = constantStream( '3.14', 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, 10, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - t.equal( parseFloat( result[ i ] ), 3.14, 'returns expected value. i: ' + i + '.' ); - } - t.end(); - } -}); - -tape( 'the constructor returns a stream which always streams the same value (Buffer)', function test( t ) { - var iStream; - var result; - var opts; - var s; - - opts = { - 'iter': 10, - 'sep': '\n' - }; - s = constantStream( string2buffer( '3.14' ), 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, 10, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - t.equal( parseFloat( result[ i ] ), 3.14, 'returns expected value. i: ' + i + '.' ); - } - t.end(); - } -}); - -tape( 'the constructor returns a stream which always streams the same value (Uint8Array)', function test( t ) { - var iStream; - var result; - var value; - var opts; - var s; - - value = string2buffer( '3.14' ); - value = gcopy( value.length, value, 1, new Uint8Array( value.length ), 1 ); - - opts = { - 'iter': 10, - 'sep': '\n' - }; - s = constantStream( value, 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, 10, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - t.equal( parseFloat( result[ i ] ), 3.14, 'returns expected value. i: ' + i + '.' ); - } - t.end(); - } -}); - -tape( 'the constructor returns a stream which always streams the same value (object mode)', function test( t ) { - var iStream; - var count; - var value; - var opts; - var s; - - value = [ 1, 2, 3, 4 ]; - opts = { - 'objectMode': true - }; - s = constantStream( value, opts ); - s.on( 'close', onClose ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - count = 0; - s.pipe( iStream ); - - function inspect( v ) { - count += 1; - t.equal( v, value, 'returns expected value. i: '+count+'.' ); - if ( count >= 10 ) { - s.destroy(); - } - } - - function onClose() { - t.pass( 'stream closed' ); - t.end(); - } -}); - -tape( 'the constructor supports limiting the number of iterations', function test( t ) { - var iStream; - var count; - var niter; - var opts; - var s; - - niter = 10; - count = 0; - - opts = { - 'iter': niter, - 'objectMode': true - }; - s = constantStream( 3.14, opts ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - s.pipe( iStream ); - - function inspect( v ) { - count += 1; - t.equal( v, 3.14, 'returns expected value' ); - } - - function onEnd() { - t.equal( count === niter, true, 'performs expected number of iterations' ); - t.end(); - } -}); - -tape( 'by default, the constructor generates newline-delimited values', function test( t ) { - var iStream; - var result; - var value; - var opts; - var s; - - value = '{"beep":"boop"}'; - opts = { - 'iter': 10 - }; - s = constantStream( value, opts ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - result = ''; - s.pipe( iStream ); - - function inspect( chunk ) { - result += chunk.toString(); - } - - function onEnd() { - var i; - - result = result.split( '\n' ); - t.equal( result.length, opts.iter, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - t.equal( result[ i ], value, 'returns expected value' ); - } - t.end(); - } -}); - -tape( 'the constructor supports providing a custom separator for streamed values', function test( t ) { - var iStream; - var result; - var opts; - var s; - - opts = { - 'iter': 10, - 'sep': '--++--' - }; - s = constantStream( '3.14', opts ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - result = ''; - s.pipe( iStream ); - - function inspect( chunk ) { - result += chunk.toString(); - } - - function onEnd() { - var i; - - result = result.split( opts.sep ); - t.equal( result.length, opts.iter, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - t.equal( result[ i ], '3.14', 'returns expected value' ); - } - t.end(); - } -}); diff --git a/test/test.object_mode.js b/test/test.object_mode.js deleted file mode 100644 index 1a60f94..0000000 --- a/test/test.object_mode.js +++ /dev/null @@ -1,195 +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 ConstantStream = 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 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( 'beep', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid `iter` option', function test( t ) { - var values; - var i; - - values = [ - 'abc', - -5, - 3.14, - null, - true, - false, - void 0, - NaN, - [], - {}, - 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( 'beep', { - 'iter': 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( 'beep', { - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a stream instance', function test( t ) { - var s = objectMode( 'beep' ); - t.equal( s instanceof ConstantStream, true, 'returns a stream instance' ); - t.end(); -}); - -tape( 'the function returns a stream instance (options)', function test( t ) { - var s = objectMode( 'beep', {} ); - t.equal( s instanceof ConstantStream, true, 'returns a stream instance' ); - t.end(); -}); - -tape( 'the function returns a stream which always streams the same value', function test( t ) { - var iStream; - var value; - var opts; - var s; - - value = [ 1, 2, 3, 4 ]; - - opts = { - 'iter': 10 - }; - s = objectMode( value, opts ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - s.pipe( iStream ); - - function inspect( v ) { - t.equal( v, value, 'returns expected value' ); - } - - function onEnd() { - t.end(); - } -}); - -tape( 'the function does not support overriding the `objectMode` option', function test( t ) { - var iStream; - var opts; - var s; - - opts = { - 'objectMode': false, - 'iter': 10 - }; - s = objectMode( 'beep', opts ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - s.pipe( iStream ); - - function inspect( v ) { - t.equal( v, 'beep', 'returns expected value' ); - } - - function onEnd() { - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 2e6a5c5..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,239 +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 an `iter` option which is not a nonnegative integer', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - void 0, - null, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'iter': 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', - 'iter': 100 - }; - 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', - 'iter': 100 - }; - opts = {}; - err = validate( opts, options ); - - t.equal( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets option values' ); - - t.end(); -}); - -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(); -});