diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# 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 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +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 - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index cd18338..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-16T02:38:57.367Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 32d3b26..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/random/streams/triangular) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 91f0c29..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/random/streams/triangular) 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 7d078fd..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: '15 3 * * 2' - - # 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 a74ef1e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,1044 +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 notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # 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 + + ```
@@ -492,80 +488,7 @@ stream.pipe( iStream ); -* * * - -
- -## CLI - -
- -## Installation - -To use as a general utility, install the CLI package globally - -```bash -npm install -g @stdlib/random-streams-triangular-cli -``` - -
- - - -
- -### Usage - -```text -Usage: random-triangular [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 pseudorandom numbers. - --seed seed Pseudorandom number generator seed. - --state filepath Path to a file containing the pseudorandom number - generator state. - --snapshot filepath Output file path for saving the pseudorandom number - generator state upon exit. -``` - -
- - - - - -
- -### Notes - -- In accordance with POSIX convention, a trailing newline is **always** appended to generated output prior to exit. -- Specifying a "snapshot" file path is useful when wanting to resume pseudorandom number generation due to, e.g., a downstream failure in an analysis pipeline. Before exiting, the process will store the pseudorandom number generator state in a file specified according to a provided file path. Upon loading a snapshot (state), the process will generate pseudorandom numbers starting from the loaded state, thus avoiding having to seed and replay an entire analysis. - -
- - - - - -
- -### Examples - -```bash -$ random-triangular 2.0 5.0 4.0 -n 10 --seed 1234 -``` - -
- - - -
- @@ -591,7 +514,7 @@ $ random-triangular 2.0 5.0 4.0 -n 10 --seed 1234 ## 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]. @@ -666,13 +589,13 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [triangular]: https://en.wikipedia.org/wiki/Triangular_distribution -[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32 +[@stdlib/array/uint32]: https://github.com/stdlib-js/array-uint32/tree/esm -[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular +[@stdlib/random/base/triangular]: https://github.com/stdlib-js/random-base-triangular/tree/esm -[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular +[@stdlib/random/iter/triangular]: https://github.com/stdlib-js/random-iter-triangular/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 4fb72d9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,114 +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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var randomStream = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var s; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s = randomStream( 2.0, 5.0, 4.0 ); - if ( typeof s !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !( s instanceof Readable ) ) { - b.fail( 'should return a readable stream' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::seed', pkg ), function benchmark( b ) { - var opts; - var s; - var i; - - opts = { - 'seed': 12345 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s = randomStream( 2.0, 5.0, 4.0, opts ); - 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( format( '%s:objectMode', pkg ), function benchmark( b ) { - var s; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s = randomStream.objectMode( 2.0, 5.0, 4.0 ); - if ( typeof s !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !( s instanceof Readable ) ) { - b.fail( 'should return a readable stream' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::factory', pkg ), function benchmark( b ) { - var createStream; - var s; - var i; - - createStream = randomStream.factory( 2.0, 5.0, 4.0 ); - - 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 85a8bb4..0000000 --- a/benchmark/benchmark.throughput.js +++ /dev/null @@ -1,246 +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 format = require( '@stdlib/string-format' ); -var inherit = require( '@stdlib/utils-inherit' ); -var nextTick = require( '@stdlib/utils-next-tick' ); -var pkg = require( './../package.json' ).name; -var randomStream = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::throughput,baseline', pkg ), 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( format( '%s::throughput:highWaterMark=', pkg ), 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 = randomStream( 2.0, 5.0, 4.0, opts ); - - // Create a sink stream: - opts = {}; - wStream = new Writable( opts ); - - i = 0; - b.tic(); - - return pipe(); - - function pipe() { - // Begin data flow... - rStream.pipe( wStream ); - } - - function next( chunk, encoding, clbk ) { - i += 1; - if ( i < b.iterations ) { - return clbk(); - } - b.toc(); - rStream.destroy(); - - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( format( '%s::throughput:highWaterMark=0', pkg ), 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 = randomStream( 2.0, 5.0, 4.0, opts ); - - // Create a sink stream: - opts = {}; - wStream = new Writable( opts ); - - i = 0; - b.tic(); - - return pipe(); - - function pipe() { - // Begin data flow... - rStream.pipe( wStream ); - } - - function next( chunk, encoding, clbk ) { - i += 1; - if ( i < b.iterations ) { - return clbk(); - } - b.toc(); - rStream.destroy(); - - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( format( '%s::throughput,object_mode:highWaterMark=', pkg ), 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 = randomStream.objectMode( 2.0, 5.0, 4.0, opts ); - - // Create a sink stream: - opts = { - 'objectMode': true - }; - wStream = new Writable( opts ); - - i = 0; - b.tic(); - - return pipe(); - - function pipe() { - // Begin data flow... - rStream.pipe( wStream ); - } - - function next( chunk, encoding, clbk ) { - i += 1; - if ( i < b.iterations ) { - return clbk(); - } - b.toc(); - rStream.destroy(); - - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( format( '%s::throughput,object_mode:highWaterMark=0', pkg ), 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 = randomStream.objectMode( 2.0, 5.0, 4.0, opts ); - - // Create a sink stream: - opts = { - 'objectMode': true - }; - wStream = new Writable( opts ); - - i = 0; - b.tic(); - - return pipe(); - - function pipe() { - // Begin data flow... - rStream.pipe( wStream ); - } - - function next( chunk, encoding, clbk ) { - i += 1; - if ( i < b.iterations ) { - return clbk(); - } - b.toc(); - rStream.destroy(); - - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/bin/cli b/bin/cli deleted file mode 100755 index 9e584a5..0000000 --- a/bin/cli +++ /dev/null @@ -1,195 +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 proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var writeFileSync = require( '@stdlib/fs-write-file' ).sync; -var CLI = require( '@stdlib/cli-ctor' ); -var stdout = require( '@stdlib/streams-node-stdout' ); -var cwd = require( '@stdlib/process-cwd' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var isUint8Array = require( '@stdlib/assert-is-uint8array' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var gcopy = require( '@stdlib/blas-base-gcopy' ); -var array2buffer = require( '@stdlib/buffer-from-array' ); -var randomStream = 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 -} - -/** -* Attempts to load a PRNG state. -* -* @private -* @param {string} filepath - absolute path to file containing PRNG state -* @returns {(Uint32Array|Error)} PRNG state or an error -*/ -function loadState( filepath ) { - var state; - var len; - - state = readFileSync( filepath ); - if ( state instanceof Error ) { - return state; - } - len = state.length; - - // For older Node.js environments, convert the `Buffer` to a `Uint8Array`... - if ( !isUint8Array( state ) ) { - state = gcopy( len, state, 1, new Uint8Array( len ), 1 ); - } - // Create a PRNG state array "view": - len /= Uint32Array.BYTES_PER_ELEMENT; - if ( !isInteger( len ) ) { - return new RangeError( 'invalid option. `state` has an invalid length.' ); - } - return new Uint32Array( state.buffer, state.byteOffset, len ); -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -* @returns {void} -*/ -function main() { - var stream; - var flags; - var opts; - var args; - var cli; - var err; - var dir; - var i; - - // 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 the current working directory: - dir = cwd(); - - // Get any provided command-line arguments: - args = cli.args(); - if ( args.length < 3 ) { - err = new Error( 'insufficient arguments. Must provide distribution parameters.' ); - return onError( err ); - } - args[ 0 ] = parseFloat( args[ 0 ] ); - args[ 1 ] = parseFloat( args[ 1 ] ); - args[ 2 ] = parseFloat( args[ 2 ] ); - - opts = {}; - if ( flags.iter ) { - opts.iter = parseInt( flags.iter, 10 ); - } - if ( flags.sep ) { - opts.sep = flags.sep; - } - if ( flags.state ) { - opts.state = loadState( resolve( dir, flags.state ) ); - if ( opts.state instanceof Error ) { - return onError( opts.state ); - } - } else if ( flags.seed ) { - opts.seed = flags.seed.split( ',' ); - for ( i = 0; i < opts.seed.length; i++ ) { - opts.seed[ i ] = parseInt( opts.seed[ i ], 10 ); - } - } - if ( flags.snapshot ) { - proc.on( 'exit', onExit ); - } - - // Create a source stream and pipe to `stdout`: - stream = randomStream( args[ 0 ], args[ 1 ], args[ 2 ], opts ); - stream.on( 'end', onEnd ); - - stream.pipe( stdout ); - - /** - * Callback invoked upon exiting the process. - * - * @private - * @param {integer} code - exit code - */ - function onExit( code ) { - var state; - var err; - - // Get the current PRNG state: - state = stream.state; - - // Create a byte array "view": - state = new Uint8Array( state.buffer, state.byteOffset, stream.byteLength ); // eslint-disable-line max-len - - // Convert the byte array to a `Buffer` (with support for older Node.js environments): - state = array2buffer( state ); - - // Attempt to write the state to file: - err = writeFileSync( resolve( dir, flags.snapshot ), state ); - if ( err ) { - onError( err, code || 1 ); - } - } - - /** - * 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 8aa4f5f..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/random/streams/triangular" -%% click B href "https://github.com/stdlib-js/random-streams-triangular/tree/main" -%% click C href "https://github.com/stdlib-js/random-streams-triangular/tree/production" -%% click D href "https://github.com/stdlib-js/random-streams-triangular/tree/esm" -%% click E href "https://github.com/stdlib-js/random-streams-triangular/tree/deno" -%% click F href "https://github.com/stdlib-js/random-streams-triangular/tree/umd" -%% click G href "https://github.com/stdlib-js/random-streams-triangular/tree/cli" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/random/streams/triangular -[production-url]: https://github.com/stdlib-js/random-streams-triangular/tree/production -[deno-url]: https://github.com/stdlib-js/random-streams-triangular/tree/deno -[deno-readme]: https://github.com/stdlib-js/random-streams-triangular/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/random-streams-triangular/tree/umd -[umd-readme]: https://github.com/stdlib-js/random-streams-triangular/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/random-streams-triangular/tree/esm -[esm-readme]: https://github.com/stdlib-js/random-streams-triangular/blob/esm/README.md -[cli-url]: https://github.com/stdlib-js/random-streams-triangular/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 ed75db0..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import randomStream from '../docs/types/index'; -export = randomStream; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index df2c48b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict";var d=function(r,e){return function(){try{return e||r((e={exports:{}}).exports,e),e.exports}catch(i){throw (e=0, i)}};};var p=d(function(je,z){z.exports={objectMode:!1,encoding:null,sep:"\n",copy:!0,siter:1e308}});var _=d(function(Me,w){ -var B=require('@stdlib/assert-is-plain-object/dist'),a=require('@stdlib/assert-has-own-property/dist'),D=require('@stdlib/assert-is-boolean/dist').isPrimitive,U=require('@stdlib/assert-is-nonnegative-number/dist').isPrimitive,q=require('@stdlib/assert-is-string/dist').isPrimitive,H=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,K=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,g=require('@stdlib/error-tools-fmtprodmsg/dist');function Q(r,e){return B(e)?a(e,"sep")&&(r.sep=e.sep,!q(r.sep))?new TypeError(g('0rx2W',"sep",r.sep)):a(e,"objectMode")&&(r.objectMode=e.objectMode,!D(r.objectMode))?new TypeError(g('0rx2o',"objectMode",r.objectMode)):a(e,"encoding")&&(r.encoding=e.encoding,!q(r.encoding)&&r.encoding!==null)?new TypeError(g('0rx7n',"encoding",r.encoding)):a(e,"highWaterMark")&&(r.highWaterMark=e.highWaterMark,!U(r.highWaterMark))?new TypeError(g('0rx4k',"highWaterMark",r.highWaterMark)):a(e,"iter")&&(r.iter=e.iter,!K(r.iter))?new TypeError(g('0rx2t',"iter",r.iter)):a(e,"siter")&&(r.siter=e.siter,!H(r.siter))?new TypeError(g('0rx3P',"siter",r.siter)):(a(e,"prng")&&(r.prng=e.prng),a(e,"seed")&&(r.seed=e.seed),a(e,"state")&&(r.state=e.state),a(e,"copy")&&(r.copy=e.copy),null):new TypeError(g('0rx2V',e));}w.exports=Q -});var M=d(function(Ee,j){ -var X=require("debug"),Y=X("random:streams:triangular");j.exports=Y -});var m=d(function(Oe,N){ -var S=require("readable-stream").Readable,c=require('@stdlib/assert-is-number/dist').isPrimitive,b=require('@stdlib/math-base-assert-is-nan/dist'),Z=require('@stdlib/assert-is-error/dist'),$=require('@stdlib/object-assign/dist'),ee=require('@stdlib/utils-inherit/dist'),E=require('@stdlib/utils-define-nonenumerable-property/dist'),o=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),v=require('@stdlib/utils-define-read-only-accessor/dist'),re=require('@stdlib/utils-define-read-write-accessor/dist'),te=require('@stdlib/random-base-triangular/dist').factory,O=require('@stdlib/buffer-from-string/dist'),ie=require('@stdlib/utils-next-tick/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist'),ne=p(),ae=_(),h=M();function se(){return this._prng.seed}function ue(){return this._prng.seedLength}function oe(){return this._prng.stateLength}function ge(){return this._prng.byteLength}function de(){return this._prng.state}function he(r){this._prng.state=r}function fe(){var r,e;if(!this._destroyed)for(r=!0;r;){if(this._i+=1,this._i>this._iter)return h("Finished generating pseudorandom numbers."),this.push(null);e=this._prng(),h("Generated a new pseudorandom number. Value: %d. Iter: %d.",e,this._i),this._objectMode===!1&&(e=e.toString(),this._i===1?e=O(e):e=O(this._sep+e)),r=this.push(e),this._i%this._siter===0&&this.emit("state",this.state)}}function ve(r){var e;if(this._destroyed)return h("Attempted to destroy an already destroyed stream."),this;return e=this,this._destroyed=!0,ie(i),this;function i(){r&&(h("Stream was destroyed due to an error. Error: %s.",Z(r)?r.message:JSON.stringify(r)),e.emit("error",r)),h("Closing the stream..."),e.emit("close")}}function n(r,e,i,s){var t,u;if(!(this instanceof n))return arguments.length>3?new n(r,e,i,s):new n(r,e,i);if(!c(r)||b(r))throw new TypeError(f('0rx6v',r));if(!c(e)||b(e))throw new TypeError(f('0rx6w',e));if(!c(i)||b(i))throw new TypeError(f('0rx7C',i));if(!(r<=i&&i<=e))throw new RangeError(f('0rx9C',"a <= c <= b",r,e,i));if(t=$({},ne),arguments.length>3&&(u=ae(t,s),u))throw u;return h("Creating a readable stream configured with the following options: %s.",JSON.stringify(t)),S.call(this,t),E(this,"_destroyed",!1),o(this,"_objectMode",t.objectMode),o(this,"_sep",t.sep),o(this,"_iter",t.iter),o(this,"_siter",t.siter),E(this,"_i",0),o(this,"_prng",te(r,e,i,t)),o(this,"PRNG",this._prng.PRNG),this}ee(n,S);v(n.prototype,"seed",se);v(n.prototype,"seedLength",ue);re(n.prototype,"state",de,he);v(n.prototype,"stateLength",oe);v(n.prototype,"byteLength",ge);o(n.prototype,"_read",fe);o(n.prototype,"destroy",ve);N.exports=n -});var P=d(function(Se,T){ -var me=require('@stdlib/assert-is-plain-object/dist'),le=require('@stdlib/object-assign/dist'),ce=require('@stdlib/error-tools-fmtprodmsg/dist'),be=m();function ye(r,e,i,s){var t;if(arguments.length>3){if(t=s,!me(t))throw new TypeError(ce('0rx2V',t));t=le({},s)}else t={};return t.objectMode=!0,new be(r,e,i,t)}T.exports=ye -});var W=d(function(Ne,x){ -var R=require('@stdlib/assert-is-plain-object/dist'),L=require('@stdlib/object-assign/dist'),V=require('@stdlib/error-tools-fmtprodmsg/dist'),k=m();function pe(r,e,i,s){var t,u,l;if(t=arguments.length,t===1){if(!R(r))throw new TypeError(V('0rx2V',r));u=L({},r)}else if(t>3){if(!R(s))throw new TypeError(V('0rx2V',s));u=L({},s)}else u={};return t<3?l=F:l=G,l;function F(I,C,J){return new k(I,C,J,u)}function G(){return new k(r,e,i,u)}}x.exports=pe -});var A=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),y=m(),qe=P(),we=W();A(y,"objectMode",qe);A(y,"factory",we);module.exports=y; -/** @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 97afc05..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 \"objectMode\": false,\n \"encoding\": null,\n \"sep\": \"\\n\",\n \"copy\": true,\n \"siter\": 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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 ceasing to generate additional pseudorandom numbers\n* @param {NonNegativeInteger} [options.iter] - number of iterations\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state\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\tif ( hasOwnProp( options, 'siter' ) ) {\n\t\topts.siter = options.siter;\n\t\tif ( !isPositiveInteger( opts.siter ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'siter', opts.siter ) );\n\t\t}\n\t}\n\t// Pass through options...\n\tif ( hasOwnProp( options, 'prng' ) ) {\n\t\topts.prng = options.prng;\n\t}\n\tif ( hasOwnProp( options, 'seed' ) ) {\n\t\topts.seed = options.seed;\n\t}\n\tif ( hasOwnProp( options, 'state' ) ) {\n\t\topts.state = options.state;\n\t}\n\tif ( hasOwnProp( options, 'copy' ) ) {\n\t\topts.copy = options.copy;\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( 'random:streams:triangular' );\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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar assign = require( '@stdlib/object-assign' );\nvar inherit = require( '@stdlib/utils-inherit' );\nvar setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' );\nvar setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar setReadOnlyAccessor = require( '@stdlib/utils-define-read-only-accessor' );\nvar setReadWriteAccessor = require( '@stdlib/utils-define-read-write-accessor' );\nvar rtriang = require( '@stdlib/random-base-triangular' ).factory;\nvar string2buffer = require( '@stdlib/buffer-from-string' );\nvar nextTick = require( '@stdlib/utils-next-tick' );\nvar format = require( '@stdlib/string-format' );\nvar DEFAULTS = require( './defaults.json' );\nvar validate = require( './validate.js' );\nvar debug = require( './debug.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Returns the PRNG seed.\n*\n* @private\n* @returns {(PRNGSeedMT19937|null)} seed\n*/\nfunction getSeed() {\n\treturn this._prng.seed; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Returns the PRNG seed length.\n*\n* @private\n* @returns {(PositiveInteger|null)} seed length\n*/\nfunction getSeedLength() {\n\treturn this._prng.seedLength; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Returns the PRNG state length.\n*\n* @private\n* @returns {(PositiveInteger|null)} state length\n*/\nfunction getStateLength() {\n\treturn this._prng.stateLength; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Returns the PRNG state size (in bytes).\n*\n* @private\n* @returns {(PositiveInteger|null)} state size (in bytes)\n*/\nfunction getStateSize() {\n\treturn this._prng.byteLength; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Returns the current PRNG state.\n*\n* @private\n* @returns {(PRNGStateMT19937|null)} current state\n*/\nfunction getState() {\n\treturn this._prng.state; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Sets the PRNG state.\n*\n* @private\n* @param {PRNGStateMT19937} s - generator state\n* @throws {Error} must provide a valid state\n*/\nfunction setState( s ) {\n\tthis._prng.state = s; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Implements the `_read` method.\n*\n* @private\n* @param {number} size - number (of bytes) to read\n* @returns {void}\n*/\nfunction read() {\n\t/* eslint-disable no-invalid-this */\n\tvar FLG;\n\tvar r;\n\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 generating pseudorandom numbers.' );\n\t\t\treturn this.push( null );\n\t\t}\n\t\tr = this._prng();\n\n\t\tdebug( 'Generated a new pseudorandom number. Value: %d. Iter: %d.', r, this._i );\n\n\t\tif ( this._objectMode === false ) {\n\t\t\tr = r.toString();\n\t\t\tif ( this._i === 1 ) {\n\t\t\t\tr = string2buffer( r );\n\t\t\t} else {\n\t\t\t\tr = string2buffer( this._sep+r );\n\t\t\t}\n\t\t}\n\t\tFLG = this.push( r );\n\t\tif ( this._i%this._siter === 0 ) {\n\t\t\tthis.emit( 'state', this.state );\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 {RandomStream} 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 of pseudorandom numbers drawn from a uniform distribution.\n*\n* @constructor\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\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 ceasing to generate additional pseudorandom numbers\n* @param {string} [options.sep='\\n'] - separator used to join streamed data\n* @param {NonNegativeInteger} [options.iter] - number of iterations\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {RandomStream} 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 RandomStream( 2.0, 5.0, 4.0, opts );\n*\n* stream.pipe( inspectStream( log ) );\n*/\nfunction RandomStream( a, b, c, options ) {\n\tvar opts;\n\tvar err;\n\tif ( !( this instanceof RandomStream ) ) {\n\t\tif ( arguments.length > 3 ) {\n\t\t\treturn new RandomStream( a, b, c, options );\n\t\t}\n\t\treturn new RandomStream( a, b, c );\n\t}\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\tthrow new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) );\n\t}\n\topts = assign( {}, DEFAULTS );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Make the stream a readable stream:\n\tdebug( 'Creating a readable stream configured with the following options: %s.', JSON.stringify( opts ) );\n\tReadable.call( this, opts );\n\n\t// Destruction state:\n\tsetNonEnumerable( this, '_destroyed', false );\n\n\t// Cache whether the stream is operating in object mode:\n\tsetNonEnumerableReadOnly( this, '_objectMode', opts.objectMode );\n\n\t// Cache the separator:\n\tsetNonEnumerableReadOnly( this, '_sep', opts.sep );\n\n\t// Cache the total number of iterations:\n\tsetNonEnumerableReadOnly( this, '_iter', opts.iter );\n\n\t// Cache the number of iterations after which to emit the underlying PRNG state:\n\tsetNonEnumerableReadOnly( this, '_siter', opts.siter );\n\n\t// Initialize an iteration counter:\n\tsetNonEnumerable( this, '_i', 0 );\n\n\t// Create the underlying PRNG:\n\tsetNonEnumerableReadOnly( this, '_prng', rtriang( a, b, c, opts ) );\n\tsetNonEnumerableReadOnly( this, 'PRNG', this._prng.PRNG );\n\n\treturn this;\n}\n\n/*\n* Inherit from the `Readable` prototype.\n*/\ninherit( RandomStream, Readable );\n\n/**\n* PRNG seed.\n*\n* @name seed\n* @memberof RandomStream.prototype\n* @type {(PRNGSeedMT19937|null)}\n*/\nsetReadOnlyAccessor( RandomStream.prototype, 'seed', getSeed );\n\n/**\n* PRNG seed length.\n*\n* @name seedLength\n* @memberof RandomStream.prototype\n* @type {(PositiveInteger|null)}\n*/\nsetReadOnlyAccessor( RandomStream.prototype, 'seedLength', getSeedLength );\n\n/**\n* PRNG state getter/setter.\n*\n* @name state\n* @memberof RandomStream.prototype\n* @type {(PRNGStateMT19937|null)}\n* @throws {Error} must provide a valid state\n*/\nsetReadWriteAccessor( RandomStream.prototype, 'state', getState, setState );\n\n/**\n* PRNG state length.\n*\n* @name stateLength\n* @memberof RandomStream.prototype\n* @type {(PositiveInteger|null)}\n*/\nsetReadOnlyAccessor( RandomStream.prototype, 'stateLength', getStateLength );\n\n/**\n* PRNG state size (in bytes).\n*\n* @name byteLength\n* @memberof RandomStream.prototype\n* @type {(PositiveInteger|null)}\n*/\nsetReadOnlyAccessor( RandomStream.prototype, 'byteLength', getStateSize );\n\n/**\n* Implements the `_read` method.\n*\n* @private\n* @name _read\n* @memberof RandomStream.prototype\n* @type {Function}\n* @param {number} size - number (of bytes) to read\n* @returns {void}\n*/\nsetNonEnumerableReadOnly( RandomStream.prototype, '_read', read );\n\n/**\n* Gracefully destroys a stream, providing backward compatibility.\n*\n* @name destroy\n* @memberof RandomStream.prototype\n* @type {Function}\n* @param {(string|Object|Error)} [error] - error\n* @returns {RandomStream} Stream instance\n*/\nsetNonEnumerableReadOnly( RandomStream.prototype, 'destroy', destroy );\n\n\n// EXPORTS //\n\nmodule.exports = RandomStream;\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 assign = require( '@stdlib/object-assign' );\nvar format = require( '@stdlib/string-format' );\nvar RandomStream = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns an \"objectMode\" readable stream for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\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 ceasing to generate additional pseudorandom numbers\n* @param {NonNegativeInteger} [options.iter] - number of iterations\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {RandomStream} 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( 2.0, 5.0, 4.0, opts );\n*\n* stream.pipe( inspectStream.objectMode( log ) );\n*/\nfunction objectMode( a, b, c, options ) {\n\tvar opts;\n\tif ( arguments.length > 3 ) {\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 RandomStream( a, b, c, 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 isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar assign = require( '@stdlib/object-assign' );\nvar format = require( '@stdlib/string-format' );\nvar RandomStream = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for creating readable streams which generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\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 ceasing to generate additional pseudorandom numbers\n* @param {string} [options.sep='\\n'] - separator used to join streamed data\n* @param {NonNegativeInteger} [options.iter] - number of iterations\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state\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( 2.0, 5.0, 4.0 ) );\n* }\n*/\nfunction factory( a, b, c, options ) {\n\tvar nargs;\n\tvar opts;\n\tvar fcn;\n\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tif ( !isPlainObject( a ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', a ) );\n\t\t}\n\t\topts = assign( {}, a );\n\t} else if ( nargs > 3 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\topts = assign( {}, options );\n\t} else {\n\t\topts = {};\n\t}\n\tif ( nargs < 3 ) {\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 for generating pseudorandom numbers drawn from a triangular distribution.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @throws {TypeError} `a` must be a number\n\t* @throws {TypeError} `b` must be a number\n\t* @throws {TypeError} `c` must be a number\n\t* @throws {RangeError} arguments must satisfy `a <= c <= b`\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @throws {Error} must provide a valid state\n\t* @returns {RandomStream} Stream instance\n\t*/\n\tfunction createStream1( a, b, c ) {\n\t\treturn new RandomStream( a, b, c, opts );\n\t}\n\n\t/**\n\t* Returns a readable stream for generating pseudorandom numbers drawn from a triangular distribution.\n\t*\n\t* @private\n\t* @throws {TypeError} `a` must be a number\n\t* @throws {TypeError} `b` must be a number\n\t* @throws {TypeError} `c` must be a number\n\t* @throws {RangeError} arguments must satisfy `a <= c <= b`\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @throws {Error} must provide a valid state\n\t* @returns {RandomStream} Stream instance\n\t*/\n\tfunction createStream2() {\n\t\treturn new RandomStream( a, b, c, 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 for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-streams-triangular\n*\n* @example\n* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );\n* var randomStream = require( '@stdlib/random-streams-triangular' );\n*\n* function log( chunk ) {\n* console.log( chunk.toString() );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = randomStream( 2.0, 5.0, 4.0, opts );\n*\n* stream.pipe( inspectStream( log ) );\n*\n* @example\n* var randomStream = require( '@stdlib/random-streams-triangular' );\n*\n* var opts = {\n* 'sep': ',',\n* 'objectMode': false,\n* 'encoding': 'utf8',\n* 'highWaterMark': 64\n* };\n*\n* var createStream = randomStream.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( 2.0, 5.0, 4.0 ) );\n* }\n*\n* @example\n* var inspectStream = require( '@stdlib/streams-node-inspect-sink' );\n* var randomStream = require( '@stdlib/random-streams-triangular' );\n*\n* function log( v ) {\n* console.log( v );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = randomStream.objectMode( 2.0, 5.0, 4.0, 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": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACE,WAAc,GACd,SAAY,KACZ,IAAO,KACP,KAAQ,GACR,MAAS,KACX,ICNA,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,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAiC9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMV,EAAUU,CAAQ,EAGnBT,EAAYS,EAAS,KAAM,IAC/BD,EAAK,IAAMC,EAAQ,IACd,CAACN,EAAUK,EAAK,GAAI,GACjB,IAAI,UAAWF,EAAQ,8DAA+D,MAAOE,EAAK,GAAI,CAAE,EAG5GR,EAAYS,EAAS,YAAa,IACtCD,EAAK,WAAaC,EAAQ,WACrB,CAACR,EAAWO,EAAK,UAAW,GACzB,IAAI,UAAWF,EAAQ,+DAAgE,aAAcE,EAAK,UAAW,CAAE,EAG3HR,EAAYS,EAAS,UAAW,IACpCD,EAAK,SAAWC,EAAQ,SACnB,CAACN,EAAUK,EAAK,QAAS,GAAKA,EAAK,WAAa,MAC7C,IAAI,UAAWF,EAAQ,sEAAuE,WAAYE,EAAK,QAAS,CAAE,EAG9HR,EAAYS,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACP,EAAeM,EAAK,aAAc,GAChC,IAAI,UAAWF,EAAQ,0EAA2E,gBAAiBE,EAAK,aAAc,CAAE,EAG5IR,EAAYS,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,KACf,CAACJ,EAAsBG,EAAK,IAAK,GAC9B,IAAI,UAAWF,EAAQ,2EAA4E,OAAQE,EAAK,IAAK,CAAE,EAG3HR,EAAYS,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAAmBI,EAAK,KAAM,GAC5B,IAAI,UAAWF,EAAQ,wEAAyE,QAASE,EAAK,KAAM,CAAE,GAI1HR,EAAYS,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,MAEhBT,EAAYS,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,MAEhBT,EAAYS,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,OAEjBT,EAAYS,EAAS,MAAO,IAChCD,EAAK,KAAOC,EAAQ,MAEd,MAnDC,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,CAoDhH,CAKAX,EAAO,QAAUS,ICzHjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,OAAQ,EAK1BC,EAAQD,EAAQ,2BAA4B,EAKhDD,EAAO,QAAUE,IChCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,iBAAkB,EAAE,SACxCC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAS,QAAS,uBAAwB,EAC1CC,GAAU,QAAS,uBAAwB,EAC3CC,EAAmB,QAAS,6CAA8C,EAC1EC,EAA2B,QAAS,uDAAwD,EAC5FC,EAAsB,QAAS,yCAA0C,EACzEC,GAAuB,QAAS,0CAA2C,EAC3EC,GAAU,QAAS,gCAAiC,EAAE,QACtDC,EAAgB,QAAS,4BAA6B,EACtDC,GAAW,QAAS,yBAA0B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,GAAW,IACXC,GAAW,IACXC,EAAQ,IAWZ,SAASC,IAAU,CAClB,OAAO,KAAK,MAAM,IACnB,CAQA,SAASC,IAAgB,CACxB,OAAO,KAAK,MAAM,UACnB,CAQA,SAASC,IAAiB,CACzB,OAAO,KAAK,MAAM,WACnB,CAQA,SAASC,IAAe,CACvB,OAAO,KAAK,MAAM,UACnB,CAQA,SAASC,IAAW,CACnB,OAAO,KAAK,MAAM,KACnB,CASA,SAASC,GAAUC,EAAI,CACtB,KAAK,MAAM,MAAQA,CACpB,CASA,SAASC,IAAO,CAEf,IAAIC,EACAC,EAEJ,GAAK,MAAK,WAIV,IADAD,EAAM,GACEA,GAAM,CAEb,GADA,KAAK,IAAM,EACN,KAAK,GAAK,KAAK,MACnB,OAAAT,EAAO,2CAA4C,EAC5C,KAAK,KAAM,IAAK,EAExBU,EAAI,KAAK,MAAM,EAEfV,EAAO,4DAA6DU,EAAG,KAAK,EAAG,EAE1E,KAAK,cAAgB,KACzBA,EAAIA,EAAE,SAAS,EACV,KAAK,KAAO,EAChBA,EAAIf,EAAee,CAAE,EAErBA,EAAIf,EAAe,KAAK,KAAKe,CAAE,GAGjCD,EAAM,KAAK,KAAMC,CAAE,EACd,KAAK,GAAG,KAAK,SAAW,GAC5B,KAAK,KAAM,QAAS,KAAK,KAAM,CAEjC,CAGD,CASA,SAASC,GAASC,EAAQ,CAEzB,IAAIC,EACJ,GAAK,KAAK,WACT,OAAAb,EAAO,mDAAoD,EACpD,KAER,OAAAa,EAAO,KACP,KAAK,WAAa,GAElBjB,GAAUkB,CAAM,EAET,KAOP,SAASA,GAAQ,CACXF,IACJZ,EAAO,mDAAsDb,EAASyB,CAAM,EAAMA,EAAM,QAAU,KAAK,UAAWA,CAAM,CAAE,EAC1HC,EAAK,KAAM,QAASD,CAAM,GAE3BZ,EAAO,uBAAwB,EAC/Ba,EAAK,KAAM,OAAQ,CACpB,CAGD,CA+CA,SAASE,EAAcC,EAAGC,EAAGC,EAAGC,EAAU,CACzC,IAAIC,EACAC,EACJ,GAAK,EAAG,gBAAgBN,GACvB,OAAK,UAAU,OAAS,EAChB,IAAIA,EAAcC,EAAGC,EAAGC,EAAGC,CAAQ,EAEpC,IAAIJ,EAAcC,EAAGC,EAAGC,CAAE,EAElC,GAAK,CAACjC,EAAU+B,CAAE,GAAK9B,EAAO8B,CAAE,EAC/B,MAAM,IAAI,UAAWnB,EAAQ,8EAA+EmB,CAAE,CAAE,EAEjH,GAAK,CAAC/B,EAAUgC,CAAE,GAAK/B,EAAO+B,CAAE,EAC/B,MAAM,IAAI,UAAWpB,EAAQ,+EAAgFoB,CAAE,CAAE,EAElH,GAAK,CAAChC,EAAUiC,CAAE,GAAKhC,EAAOgC,CAAE,EAC/B,MAAM,IAAI,UAAWrB,EAAQ,8EAA+EqB,CAAE,CAAE,EAEjH,GAAK,EAAEF,GAAKE,GAAKA,GAAKD,GACrB,MAAM,IAAI,WAAYpB,EAAQ,qGAAsG,cAAemB,EAAGC,EAAGC,CAAE,CAAE,EAG9J,GADAE,EAAOhC,EAAQ,CAAC,EAAGU,EAAS,EACvB,UAAU,OAAS,IACvBuB,EAAMtB,GAAUqB,EAAMD,CAAQ,EACzBE,GACJ,MAAMA,EAIR,OAAArB,EAAO,wEAAyE,KAAK,UAAWoB,CAAK,CAAE,EACvGpC,EAAS,KAAM,KAAMoC,CAAK,EAG1B9B,EAAkB,KAAM,aAAc,EAAM,EAG5CC,EAA0B,KAAM,cAAe6B,EAAK,UAAW,EAG/D7B,EAA0B,KAAM,OAAQ6B,EAAK,GAAI,EAGjD7B,EAA0B,KAAM,QAAS6B,EAAK,IAAK,EAGnD7B,EAA0B,KAAM,SAAU6B,EAAK,KAAM,EAGrD9B,EAAkB,KAAM,KAAM,CAAE,EAGhCC,EAA0B,KAAM,QAASG,GAASsB,EAAGC,EAAGC,EAAGE,CAAK,CAAE,EAClE7B,EAA0B,KAAM,OAAQ,KAAK,MAAM,IAAK,EAEjD,IACR,CAKAF,GAAS0B,EAAc/B,CAAS,EAShCQ,EAAqBuB,EAAa,UAAW,OAAQd,EAAQ,EAS7DT,EAAqBuB,EAAa,UAAW,aAAcb,EAAc,EAUzET,GAAsBsB,EAAa,UAAW,QAASV,GAAUC,EAAS,EAS1Ed,EAAqBuB,EAAa,UAAW,cAAeZ,EAAe,EAS3EX,EAAqBuB,EAAa,UAAW,aAAcX,EAAa,EAYxEb,EAA0BwB,EAAa,UAAW,QAASP,EAAK,EAWhEjB,EAA0BwB,EAAa,UAAW,UAAWJ,EAAQ,EAKrE5B,EAAO,QAAUgC,IC5WjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAW,QAAS,gCAAiC,EACrDC,GAAS,QAAS,uBAAwB,EAC1CC,GAAS,QAAS,uBAAwB,EAC1CC,GAAe,IA4CnB,SAASC,GAAYC,EAAGC,EAAGC,EAAGC,EAAU,CACvC,IAAIC,EACJ,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAA,EAAOD,EACF,CAACR,GAAUS,CAAK,EACpB,MAAM,IAAI,UAAWP,GAAQ,qEAAsEO,CAAK,CAAE,EAE3GA,EAAOR,GAAQ,CAAC,EAAGO,CAAQ,CAC5B,MACCC,EAAO,CAAC,EAET,OAAAA,EAAK,WAAa,GACX,IAAIN,GAAcE,EAAGC,EAAGC,EAAGE,CAAK,CACxC,CAKAV,EAAO,QAAUK,KCvFjB,IAAAM,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAe,IA0CnB,SAASC,GAASC,EAAGC,EAAGC,EAAGC,EAAU,CACpC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAQ,UAAU,OACbA,IAAU,EAAI,CAClB,GAAK,CAACT,EAAeK,CAAE,EACtB,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAE,CAAE,EAExGK,EAAOT,EAAQ,CAAC,EAAGI,CAAE,CACtB,SAAYI,EAAQ,EAAI,CACvB,GAAK,CAACT,EAAeQ,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,EAE9GE,EAAOT,EAAQ,CAAC,EAAGO,CAAQ,CAC5B,MACCE,EAAO,CAAC,EAET,OAAKD,EAAQ,EACZE,EAAMC,EAEND,EAAME,EAEAF,EAkBP,SAASC,EAAeP,EAAGC,EAAGC,EAAI,CACjC,OAAO,IAAIJ,EAAcE,EAAGC,EAAGC,EAAGG,CAAK,CACxC,CAeA,SAASG,GAAgB,CACxB,OAAO,IAAIV,EAAcE,EAAGC,EAAGC,EAAGG,CAAK,CACxC,CACD,CAKAX,EAAO,QAAUK,KCtDjB,IAAIU,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", "isPositiveInteger", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_debug", "__commonJSMin", "exports", "module", "logger", "debug", "require_main", "__commonJSMin", "exports", "module", "Readable", "isNumber", "isnan", "isError", "assign", "inherit", "setNonEnumerable", "setNonEnumerableReadOnly", "setReadOnlyAccessor", "setReadWriteAccessor", "rtriang", "string2buffer", "nextTick", "format", "DEFAULTS", "validate", "debug", "getSeed", "getSeedLength", "getStateLength", "getStateSize", "getState", "setState", "s", "read", "FLG", "r", "destroy", "error", "self", "close", "RandomStream", "a", "b", "c", "options", "opts", "err", "require_object_mode", "__commonJSMin", "exports", "module", "isObject", "assign", "format", "RandomStream", "objectMode", "a", "b", "c", "options", "opts", "require_factory", "__commonJSMin", "exports", "module", "isPlainObject", "assign", "format", "RandomStream", "factory", "a", "b", "c", "options", "nargs", "opts", "fcn", "createStream1", "createStream2", "setReadOnly", "main", "objectMode", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1109fa6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,271 +0,0 @@ - -{{alias}}( a, b, c[, options] ) - Returns a readable stream for generating pseudorandom numbers drawn from a - triangular distribution. - - In addition to standard readable stream events, the returned stream emits a - 'state' event after internally generating `siter` pseudorandom numbers, - which is useful when wanting to deterministically capture a stream's - underlying PRNG state. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - 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 ceasing to generate additional pseudorandom numbers. - - 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. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned iterator, one must seed the provided `prng` (assuming the - provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned iterator has exclusive control over - its internal state. Default: true. - - options.siter: integer (optional) - Number of iterations after which to emit the PRNG state. Default: 1e308. - - Returns - ------- - stream: ReadableStream - Readable stream. - - stream.PRNG: Function - Underlying pseudorandom number generator. - - stream.seed: Uint32Array|null - Pseudorandom number generator seed. - - stream.seedLength: integer|null - Length of generator seed. - - stream.state: Uint32Array|null - Generator state. - - stream.stateLength: integer|null - Length of generator state. - - stream.byteLength: integer|null - Size (in bytes) of generator state. - - Examples - -------- - > function fcn( chunk ) { console.log( chunk.toString() ); }; - > var opts = { 'iter': 10 }; - > var s = {{alias}}( 2.0, 5.0, 4.0, opts ); - > var o = {{alias:@stdlib/streams/node/inspect-sink}}( fcn ); - > s.pipe( o ); - - -{{alias}}.factory( [a, b, c, ][options] ) - Returns a function for creating readable streams which generate pseudorandom - numbers drawn from a triangular distribution. - - If provided distribution parameters, the returned function returns readable - streams which generate pseudorandom numbers drawn from the specified - distribution. - - If not provided distribution parameters, the returned function requires that - distribution parameters be provided at each invocation. - - Parameters - ---------- - a: number (optional) - Minimum support. - - b: number (optional) - Maximum support. - - c: number (optional) - Mode. - - 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 ceasing to generate additional pseudorandom numbers. - - 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. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned iterator, one must seed the provided `prng` (assuming the - provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned iterator has exclusive control over - its internal state. Default: true. - - options.siter: integer (optional) - Number of iterations after which to emit the PRNG state. Default: 1e308. - - Returns - ------- - fcn: Function - Function for creating readable streams. - - Examples - -------- - > var opts = { 'objectMode': true, 'highWaterMark': 64 }; - > var createStream = {{alias}}.factory( opts ); - - -{{alias}}.objectMode( a, b, c[, options] ) - Returns an "objectMode" readable stream for generating pseudorandom numbers - drawn from a triangular distribution. - - Parameters - ---------- - a: number - Minimum support. - - b: number - Maximum support. - - c: number - Mode. - - 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 ceasing to generate additional pseudorandom numbers. - - options.iter: integer (optional) - Number of iterations. - - options.prng: Function (optional) - Pseudorandom number generator (PRNG) for generating uniformly - distributed pseudorandom numbers on the interval `[0,1)`. If provided, - the `state` and `seed` options are ignored. In order to seed the - returned iterator, one must seed the provided `prng` (assuming the - provided `prng` is seedable). - - options.seed: integer|ArrayLikeObject (optional) - Pseudorandom number generator seed. The seed may be either a positive - unsigned 32-bit integer or, for arbitrary length seeds, an array-like - object containing unsigned 32-bit integers. - - options.state: Uint32Array (optional) - Pseudorandom number generator state. If provided, the `seed` option is - ignored. - - options.copy: boolean (optional) - Boolean indicating whether to copy a provided pseudorandom number - generator state. Setting this option to `false` allows sharing state - between two or more pseudorandom number generators. Setting this option - to `true` ensures that a returned iterator has exclusive control over - its internal state. Default: true. - - options.siter: integer (optional) - Number of iterations after which to emit the PRNG state. Default: 1e308. - - Returns - ------- - stream: ReadableStream - Readable stream operating in "objectMode". - - stream.PRNG: Function - Underlying pseudorandom number generator. - - stream.seed: Uint32Array|null - Pseudorandom number generator seed. - - stream.seedLength: integer|null - Length of generator seed. - - stream.state: Uint32Array|null - Generator state. - - stream.stateLength: integer|null - Length of generator state. - - stream.byteLength: integer|null - Size (in bytes) of generator state. - - Examples - -------- - > function fcn( v ) { console.log( v ); }; - > var opts = { 'iter': 10 }; - > var s = {{alias}}.objectMode( 2.0, 5.0, 4.0, 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 2d071fe..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,137 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 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. -*/ - -import RandomStream = require( './index' ); - - -// TESTS // - -// The constructor returns a stream... -{ - /* eslint-disable @typescript-eslint/no-unused-expressions */ - new RandomStream( 2.0, 5.0, 4.0 ); // $ExpectType RandomStream - new RandomStream( 2.0, 5.0, 4.0, {} ); // $ExpectType RandomStream - new RandomStream( 2.0, 5.0, 4.0, { 'iter': 10 } ); // $ExpectType RandomStream - - /* eslint-enable @typescript-eslint/no-unused-expressions */ -} - -// The constructor is callable... -{ - const randomStream = RandomStream; - - randomStream( 2.0, 5.0, 4.0 ); // $ExpectType RandomStream - randomStream( 2.0, 5.0, 4.0, {} ); // $ExpectType RandomStream - randomStream( 2.0, 5.0, 4.0, { 'iter': 10 } ); // $ExpectType RandomStream -} - -// The constructor has an `objectMode` method which returns a stream... -{ - RandomStream.objectMode( 2.0, 5.0, 4.0 ); // $ExpectType RandomStream - RandomStream.objectMode( 2.0, 5.0, 4.0, {} ); // $ExpectType RandomStream - RandomStream.objectMode( 2.0, 5.0, 4.0, { 'iter': 10 } ); // $ExpectType RandomStream -} - -// The constructor has a `factory` method which returns a function for creating streams... -{ - let f = RandomStream.factory( 2.0, 5.0, 4.0 ); - f(); // $ExpectType RandomStream - f(); // $ExpectType RandomStream - f(); // $ExpectType RandomStream - - f = RandomStream.factory( 2.0, 5.0, 4.0, {} ); - f(); // $ExpectType RandomStream - f(); // $ExpectType RandomStream - f(); // $ExpectType RandomStream - - f = RandomStream.factory( 2.0, 5.0, 4.0, { 'iter': 10 } ); - f(); // $ExpectType RandomStream - f(); // $ExpectType RandomStream - f(); // $ExpectType RandomStream - - f = RandomStream.factory(); - f( 2.0, 5.0, 4.0 ); // $ExpectType RandomStream - f( 1.0, 2.0, 1.5 ); // $ExpectType RandomStream - f( 1.0, 3.0, 2.0 ); // $ExpectType RandomStream - - f = RandomStream.factory( {} ); - f( 2.0, 5.0, 4.0 ); // $ExpectType RandomStream - f( 1.0, 2.0 ); // $ExpectType RandomStream - f( 1.0, 3.0, 2.0 ); // $ExpectType RandomStream - - f = RandomStream.factory( { 'iter': 10 } ); - f( 2.0, 5.0, 4.0 ); // $ExpectType RandomStream - f( 1.0, 2.0, 1.5 ); // $ExpectType RandomStream - f( 1.0, 3.0, 2.0 ); // $ExpectType RandomStream -} - -// The compiler throws an error if the constructor is provided invalid input arguments... -{ - const s1 = new RandomStream( '2.0', 5.0, 4.0 ); // $ExpectError - const s2 = new RandomStream( 2.0, '5.0', 4.0 ); // $ExpectError -} - -// The compiler throws an error if the `objectMode` method is provided invalid input arguments... -{ - RandomStream.objectMode( '2.0', 5.0, 4.0 ); // $ExpectError - RandomStream.objectMode( 2.0, '5.0', 4.0 ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided invalid input arguments... -{ - RandomStream.factory( '2.0', 5.0, 4.0 ); // $ExpectError - RandomStream.factory( '2.0', 5.0, 4.0, {} ); // $ExpectError - - RandomStream.factory( 2.0, '5.0', 4.0 ); // $ExpectError - RandomStream.factory( 2.0, '5.0', 4.0, {} ); // $ExpectError - - RandomStream.factory( 2.0, 5.0, 4.0, null ); // $ExpectError - RandomStream.factory( 2.0, 5.0, 4.0, { 'iter': 'beep' } ); // $ExpectError - - RandomStream.factory( null ); // $ExpectError - RandomStream.factory( { 'iter': 'beep' } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid input arguments... -{ - let f = RandomStream.factory(); - f( '2.0', 5.0, 4.0 ); // $ExpectError - f( 2.0, '5.0', 4.0 ); // $ExpectError - - f = RandomStream.factory( {} ); - f( '2.0', 5.0, 4.0 ); // $ExpectError - f( 2.0, '5.0', 4.0 ); // $ExpectError - - f = RandomStream.factory( { 'iter': 10 } ); - f( '2.0', 5.0, 4.0 ); // $ExpectError - f( 2.0, '5.0', 4.0 ); // $ExpectError -} - -// The compiler throws an error if the constructor is provided insufficient arguments... -{ - const s1 = new RandomStream(); // $ExpectError - const s2 = new RandomStream( 2.0 ); // $ExpectError - const s3 = new RandomStream( 2.0, 5.0 ); // $ExpectError -} - -// The compiler throws an error if the `objectMode` method is provided insufficient arguments... -{ - RandomStream.objectMode(); // $ExpectError - RandomStream.objectMode( 2.0 ); // $ExpectError - RandomStream.objectMode( 2.0, 5.0 ); // $ExpectError -} diff --git a/docs/usage.txt b/docs/usage.txt deleted file mode 100644 index 33daa9f..0000000 --- a/docs/usage.txt +++ /dev/null @@ -1,15 +0,0 @@ - -Usage: random-triangular [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 pseudorandom numbers. - --seed seed Pseudorandom number generator seed. - --state filepath Path to a file containing the pseudorandom number - generator state. - --snapshot filepath Output file path for saving the pseudorandom number - generator state upon exit. - diff --git a/etc/cli_opts.json b/etc/cli_opts.json deleted file mode 100644 index 7f0889f..0000000 --- a/etc/cli_opts.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "string": [ - "sep", - "iter", - "state", - "seed", - "snapshot" - ], - "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 62e162b..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 randomStream = require( './../lib' ); - -function log( v ) { - console.log( v.toString() ); -} - -var opts = { - 'objectMode': true, - 'iter': 10 -}; -var stream = randomStream( 2.0, 5.0, 4.0, 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 99% rename from docs/types/index.d.ts rename to index.d.ts index 8416a97..7ef3238 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -19,7 +19,7 @@ // TypeScript Version: 4.1 /// -/// +/// import { Readable } from 'stream'; import * as random from '@stdlib/types/random'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e05d01e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 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.3-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-nan@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-error@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/object-assign@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-inherit@v0.2.3-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-property@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-only-accessor@v0.2.3-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-read-write-accessor@v0.2.3-esm/index.mjs";import{factory as h}from"https://cdn.jsdelivr.net/gh/stdlib-js/random-base-triangular@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-from-string@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-next-tick@v0.2.3-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.3-esm/index.mjs";import{isPrimitive as g}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.3-esm/index.mjs";import{isPrimitive as y}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-number@v0.2.3-esm/index.mjs";import{isPrimitive as v}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.3-esm/index.mjs";import{isPrimitive as w}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.3-esm/index.mjs";import{isPrimitive as m}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.3-esm/index.mjs";function b(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 _(){}function E(){E.init.call(this)}function R(e){return void 0===e._maxListeners?E.defaultMaxListeners:e._maxListeners}function j(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 _,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=R(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 S(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 L(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 T(e,t){for(var r=new Array(t);t--;)r[t]=e[t];return r}_.prototype=Object.create(null),E.EventEmitter=E,E.usingDomains=!1,E.prototype.domain=void 0,E.prototype._events=void 0,E.prototype._maxListeners=void 0,E.defaultMaxListeners=10,E.init=function(){this.domain=null,E.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new _,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},E.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},E.prototype.getMaxListeners=function(){return R(this)},E.prototype.emit=function(e){var t,r,n,i,o,s,a,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(a=this.domain,u){if(t=arguments[1],!a){if(t instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=a,t.domainThrown=!1,a.emit("error",t),!1}if(!(r=s[e]))return!1;var f="function"==typeof r;switch(n=arguments.length){case 1:!function(e,t,r){if(t)e.call(r);else for(var n=e.length,i=T(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 _,this;delete n[e]}else!function(e,t){for(var r=t,n=r+1,i=e.length;n0?Reflect.ownKeys(this._events):[]};var x="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},A=[],M=[],k="undefined"!=typeof Uint8Array?Uint8Array:Array,P=!1;function C(){P=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)A[t]=e[t],M[e.charCodeAt(t)]=t;M["-".charCodeAt(0)]=62,M["_".charCodeAt(0)]=63}function O(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 B(e){var t;P||C();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 U(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<>1,f=-7,l=r?i-1:0,c=r?-1:1,d=e[t+l];for(l+=c,o=d&(1<<-f)-1,d>>=-f,f+=a;f>0;o=256*o+e[t+l],l+=c,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+e[t+l],l+=c,f-=8);if(0===o)o=1-h;else{if(o===u)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,n),o-=h}return(d?-1:1)*s*Math.pow(2,o-n)}function D(e,t,r,n,i,o){var s,a,u,h=8*o-i-1,f=(1<>1,c=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:o-1,p=n?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+l>=1?c/u:c*Math.pow(2,1-l))*u>=2&&(s++,u/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(t*u-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[r+d]=255&a,d+=p,a/=256,i-=8);for(s=s<0;e[r+d]=255&s,d+=p,s/=256,h-=8);e[r+d-p]|=128*g}var I={}.toString,Y=Array.isArray||function(e){return"[object Array]"==I.call(e)};function z(){return W.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function N(e,t){if(z()=z())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+z().toString(16)+" bytes");return 0|e}function J(e){return!(null==e||!e._isBuffer)}function $(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 Ee(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Re(e).length;default:if(n)return Ee(e).length;t=(""+t).toLowerCase(),n=!0}}function Z(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 le(this,t,r);case"utf8":case"utf-8":return ae(this,t,r);case"ascii":return he(this,t,r);case"latin1":case"binary":return fe(this,t,r);case"base64":return se(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ce(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function K(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function Q(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=W.from(t,n)),J(t))return 0===t.length?-1:X(e,t,r,n,i);if("number"==typeof t)return t&=255,W.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):X(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function X(e,t,r,n,i){var o,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function h(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var f=-1;for(o=r;oa&&(r=a-u),o=r;o>=0;o--){for(var l=!0,c=0;ci&&(n=i):n=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function se(e,t,r){return 0===t&&r===e.length?B(e):B(e.slice(t,r))}function ae(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i239?4:h>223?3:h>191?2:1;if(i+l<=r)switch(l){case 1:h<128&&(f=h);break;case 2:128==(192&(o=e[i+1]))&&(u=(31&h)<<6|63&o)>127&&(f=u);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(u=(15&h)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(f=u);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&h)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(f=u)}null===f?(f=65533,l=1):f>65535&&(f-=65536,n.push(f>>>10&1023|55296),f=56320|1023&f),n.push(f),i+=l}return function(e){var t=e.length;if(t<=ue)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+=" ... ")),""},W.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),h=e.slice(t,r),f=0;fi)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return ee(this,e,t,r);case"utf8":case"utf-8":return te(this,e,t,r);case"ascii":return re(this,e,t,r);case"latin1":case"binary":return ne(this,e,t,r);case"base64":return ie(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return oe(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},W.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var ue=4096;function he(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 pe(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 ge(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 ye(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);i>>8*(n?i:3-i)&255}function ve(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function we(e,t,r,n,i){return i||ve(e,0,r,4),D(e,t,r,n,23,4),r+4}function me(e,t,r,n,i){return i||ve(e,0,r,8),D(e,t,r,n,52,8),r+8}W.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},W.prototype.readUInt8=function(e,t){return t||de(e,1,this.length),this[e]},W.prototype.readUInt16LE=function(e,t){return t||de(e,2,this.length),this[e]|this[e+1]<<8},W.prototype.readUInt16BE=function(e,t){return t||de(e,2,this.length),this[e]<<8|this[e+1]},W.prototype.readUInt32LE=function(e,t){return t||de(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},W.prototype.readUInt32BE=function(e,t){return t||de(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},W.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||de(e,t,this.length);for(var n=this[e],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*t)),n},W.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||de(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},W.prototype.readInt8=function(e,t){return t||de(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},W.prototype.readInt16LE=function(e,t){t||de(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},W.prototype.readInt16BE=function(e,t){t||de(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},W.prototype.readInt32LE=function(e,t){return t||de(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},W.prototype.readInt32BE=function(e,t){return t||de(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},W.prototype.readFloatLE=function(e,t){return t||de(e,4,this.length),U(this,e,!0,23,4)},W.prototype.readFloatBE=function(e,t){return t||de(e,4,this.length),U(this,e,!1,23,4)},W.prototype.readDoubleLE=function(e,t){return t||de(e,8,this.length),U(this,e,!0,52,8)},W.prototype.readDoubleBE=function(e,t){return t||de(e,8,this.length),U(this,e,!1,52,8)},W.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||pe(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},W.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||pe(this,e,t,1,255,0),W.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},W.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||pe(this,e,t,2,65535,0),W.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):ge(this,e,t,!0),t+2},W.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||pe(this,e,t,2,65535,0),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):ge(this,e,t,!1),t+2},W.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||pe(this,e,t,4,4294967295,0),W.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):ye(this,e,t,!0),t+4},W.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||pe(this,e,t,4,4294967295,0),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):ye(this,e,t,!1),t+4},W.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);pe(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},W.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);pe(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},W.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||pe(this,e,t,1,127,-128),W.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},W.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||pe(this,e,t,2,32767,-32768),W.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):ge(this,e,t,!0),t+2},W.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||pe(this,e,t,2,32767,-32768),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):ge(this,e,t,!1),t+2},W.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||pe(this,e,t,4,2147483647,-2147483648),W.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):ye(this,e,t,!0),t+4},W.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||pe(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),W.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):ye(this,e,t,!1),t+4},W.prototype.writeFloatLE=function(e,t,r){return we(this,e,t,!0,r)},W.prototype.writeFloatBE=function(e,t,r){return we(this,e,t,!1,r)},W.prototype.writeDoubleLE=function(e,t,r){return me(this,e,t,!0,r)},W.prototype.writeDoubleBE=function(e,t,r){return me(this,e,t,!1,r)},W.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||!W.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 Re(e){return function(e){var t,r,n,i,o,s;P||C();var a=e.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");o="="===e[a-2]?2:"="===e[a-1]?1:0,s=new k(3*a/4-o),n=o>0?a-4:a;var u=0;for(t=0,r=0;t>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=M[e.charCodeAt(t)]<<2|M[e.charCodeAt(t+1)]>>4,s[u++]=255&i):1===o&&(i=M[e.charCodeAt(t)]<<10|M[e.charCodeAt(t+1)]<<4|M[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(be,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function je(e,t,r,n){for(var i=0;i=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function Se(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function Le(){throw new Error("setTimeout has not been defined")}function Te(){throw new Error("clearTimeout has not been defined")}var xe=Le,Ae=Te;function Me(e){if(xe===setTimeout)return setTimeout(e,0);if((xe===Le||!xe)&&setTimeout)return xe=setTimeout,setTimeout(e,0);try{return xe(e,0)}catch(t){try{return xe.call(null,e,0)}catch(t){return xe.call(this,e,0)}}}"function"==typeof x.setTimeout&&(xe=setTimeout),"function"==typeof x.clearTimeout&&(Ae=clearTimeout);var ke,Pe=[],Ce=!1,Oe=-1;function Be(){Ce&&ke&&(Ce=!1,ke.length?Pe=ke.concat(Pe):Oe=-1,Pe.length&&Ue())}function Ue(){if(!Ce){var e=Me(Be);Ce=!0;for(var t=Pe.length;t;){for(ke=Pe,Pe=[];++Oe1)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]),ht(t)?r.showHidden=t:t&&function(e,t){if(!t||!pt(t))return e;var r=Object.keys(t),n=r.length;for(;n--;)e[r[n]]=t[r[n]]}(r,t),ct(r.showHidden)&&(r.showHidden=!1),ct(r.depth)&&(r.depth=2),ct(r.colors)&&(r.colors=!1),ct(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=it),st(r,e,r.depth)}function it(e,t){var r=nt.styles[t];return r?"["+nt.colors[r][0]+"m"+e+"["+nt.colors[r][1]+"m":e}function ot(e,t){return e}function st(e,t,r){if(e.customInspect&&t&&vt(t.inspect)&&t.inspect!==nt&&(!t.constructor||t.constructor.prototype!==t)){var n=t.inspect(r,e);return lt(n)||(n=st(e,n,r)),n}var i=function(e,t){if(ct(t))return e.stylize("undefined","undefined");if(lt(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(ht(t))return e.stylize(""+t,"boolean");if(ft(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)),yt(t)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return at(t);if(0===o.length){if(vt(t)){var a=t.name?": "+t.name:"";return e.stylize("[Function"+a+"]","special")}if(dt(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(gt(t))return e.stylize(Date.prototype.toString.call(t),"date");if(yt(t))return at(t)}var u,h,f="",l=!1,c=["{","}"];(u=t,Array.isArray(u)&&(l=!0,c=["[","]"]),vt(t))&&(f=" [Function"+(t.name?": "+t.name:"")+"]");return dt(t)&&(f=" "+RegExp.prototype.toString.call(t)),gt(t)&&(f=" "+Date.prototype.toUTCString.call(t)),yt(t)&&(f=" "+at(t)),0!==o.length||l&&0!=t.length?r<0?dt(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special"):(e.seen.push(t),h=l?function(e,t,r,n,i){for(var o=[],s=0,a=t.length;s60)return r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1];return r[0]+t+" "+e.join(", ")+" "+r[1]}(h,f,c)):c[0]+f+c[1]}function at(e){return"["+Error.prototype.toString.call(e)+"]"}function ut(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")),mt(n,i)||(s="["+i+"]"),a||(e.seen.indexOf(u.value)<0?(a=ft(r)?st(e,u.value,null):st(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")),ct(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 ht(e){return"boolean"==typeof e}function ft(e){return null===e}function lt(e){return"string"==typeof e}function ct(e){return void 0===e}function dt(e){return pt(e)&&"[object RegExp]"===wt(e)}function pt(e){return"object"==typeof e&&null!==e}function gt(e){return pt(e)&&"[object Date]"===wt(e)}function yt(e){return pt(e)&&("[object Error]"===wt(e)||e instanceof Error)}function vt(e){return"function"==typeof e}function wt(e){return Object.prototype.toString.call(e)}function mt(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function bt(){this.head=null,this.tail=null,this.length=0}nt.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]},nt.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},bt.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},bt.prototype.unshift=function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length},bt.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}},bt.prototype.clear=function(){this.head=this.tail=null,this.length=0},bt.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},bt.prototype.concat=function(e){if(0===this.length)return W.alloc(0);if(1===this.length)return this.head.data;for(var t=W.allocUnsafe(e>>>0),r=this.head,n=0;r;)r.data.copy(t,n),n+=r.data.length,r=r.next;return t};var _t=W.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 Et(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),function(e){if(e&&!_t(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=jt;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=St;break;default:return void(this.write=Rt)}this.charBuffer=new W(6),this.charReceived=0,this.charLength=0}function Rt(e){return e.toString(this.encoding)}function jt(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function St(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}Et.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},Et.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},Et.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},xt.ReadableState=Tt;var Lt=function(e){if(ct(tt)&&(tt=Ze.env.NODE_DEBUG||""),e=e.toUpperCase(),!rt[e])if(new RegExp("\\b"+e+"\\b","i").test(tt)){rt[e]=function(){var t=Xe.apply(null,arguments);console.error("%s %d: %s",e,0,t)}}else rt[e]=function(){};return rt[e]}("stream");function Tt(e,t){e=e||{},this.objectMode=!!e.objectMode,t instanceof rr&&(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 bt,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 Et(e.encoding),this.encoding=e.encoding)}function xt(e){if(!(this instanceof xt))return new xt(e);this._readableState=new Tt(e,this),this.readable=!0,e&&"function"==typeof e.read&&(this._read=e.read),E.call(this)}function At(e,t,r,n,i){var o=function(e,t){var r=null;W.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,Pt(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&&Pt(e))),function(e,t){t.readingMore||(t.readingMore=!0,De(Ot,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>=Mt?e=Mt:(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 Pt(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(Lt("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?De(Ct,e):Ct(e))}function Ct(e){Lt("emit readable"),e.emit("readable"),Dt(e)}function Ot(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=W.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 Yt(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,De(zt,t,e))}function zt(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function Nt(e,t){for(var r=0,n=e.length;r=t.highWaterMark||t.ended))return Lt("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?Yt(this):Pt(this),null;if(0===(e=kt(e,t))&&t.ended)return 0===t.length&&Yt(this),null;var n,i=t.needReadable;return Lt("need readable",i),(0===t.length||t.length-e0?It(e,t):null)?(t.needReadable=!0,e=0):t.length-=e,0===t.length&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&Yt(this)),null!==n&&this.emit("data",n),n},xt.prototype._read=function(e){this.emit("error",new Error("not implemented"))},xt.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,Lt("pipe count=%d opts=%j",n.pipesCount,t);var i=!t||!1!==t.end?s:h;function o(e){Lt("onunpipe"),e===r&&h()}function s(){Lt("onend"),e.end()}n.endEmitted?De(i):r.once("end",i),e.on("unpipe",o);var a=function(e){return function(){var t=e._readableState;Lt("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&e.listeners("data").length&&(t.flowing=!0,Dt(e))}}(r);e.on("drain",a);var u=!1;function h(){Lt("cleanup"),e.removeListener("close",d),e.removeListener("finish",p),e.removeListener("drain",a),e.removeListener("error",c),e.removeListener("unpipe",o),r.removeListener("end",s),r.removeListener("end",h),r.removeListener("data",l),u=!0,!n.awaitDrain||e._writableState&&!e._writableState.needDrain||a()}var f=!1;function l(t){Lt("ondata"),f=!1,!1!==e.write(t)||f||((1===n.pipesCount&&n.pipes===e||n.pipesCount>1&&-1!==Nt(n.pipes,e))&&!u&&(Lt("false write response, pause",r._readableState.awaitDrain),r._readableState.awaitDrain++,f=!0),r.pause())}function c(t){var r;Lt("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(){Lt("onfinish"),e.removeListener("close",d),g()}function g(){Lt("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||(Lt("pipe resume"),r.resume()),e},xt.prototype.unpipe=function(e){var t=this._readableState;if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this)),this;if(!e){var r=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;i-1))throw new TypeError("Unknown encoding: "+e);return this._writableState.defaultEncoding=e,this},Ht.prototype._write=function(e,t,r){r(new Error("not implemented"))},Ht.prototype._writev=null,Ht.prototype.end=function(e,t,r){var n=this._writableState;"function"==typeof e?(r=e,e=null,t=null):"function"==typeof t&&(r=t,t=null),null!=e&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),n.ending||n.finished||function(e,t,r){t.ending=!0,Kt(e,t),r&&(t.finished?De(r):e.once("finish",r));t.ended=!0,e.writable=!1}(this,n,r)},Ke(rr,xt);for(var Xt=Object.keys(Ht.prototype),er=0;er()=>{}}))("random:streams:triangular"),dr=fr.Readable;function pr(n,o,a,u){var f,l;if(!(this instanceof pr))return arguments.length>3?new pr(n,o,a,u):new pr(n,o,a);if(!t(n)||r(n))throw new TypeError(c("0rx6v",n));if(!t(o)||r(o))throw new TypeError(c("0rx6w",o));if(!t(a)||r(a))throw new TypeError(c("0rx7C",a));if(!(n<=a&&a<=o))throw new RangeError(c("0rx9C","a <= c <= b",n,o,a));if(f=i({},lr),arguments.length>3&&(l=function(e,t){return d(t)?p(t,"sep")&&(e.sep=t.sep,!v(e.sep))?new TypeError(c("0rx2W","sep",e.sep)):p(t,"objectMode")&&(e.objectMode=t.objectMode,!g(e.objectMode))?new TypeError(c("0rx2o","objectMode",e.objectMode)):p(t,"encoding")&&(e.encoding=t.encoding,!v(e.encoding)&&null!==e.encoding)?new TypeError(c("0rx7n","encoding",e.encoding)):p(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!y(e.highWaterMark))?new TypeError(c("0rx4k","highWaterMark",e.highWaterMark)):p(t,"iter")&&(e.iter=t.iter,!m(e.iter))?new TypeError(c("0rx2t","iter",e.iter)):p(t,"siter")&&(e.siter=t.siter,!w(e.siter))?new TypeError(c("0rx3P","siter",e.siter)):(p(t,"prng")&&(e.prng=t.prng),p(t,"seed")&&(e.seed=t.seed),p(t,"state")&&(e.state=t.state),p(t,"copy")&&(e.copy=t.copy),null):new TypeError(c("0rx2V",t))}(f,u),l))throw l;return cr("Creating a readable stream configured with the following options: %s.",JSON.stringify(f)),dr.call(this,f),s(this,"_destroyed",!1),e(this,"_objectMode",f.objectMode),e(this,"_sep",f.sep),e(this,"_iter",f.iter),e(this,"_siter",f.siter),s(this,"_i",0),e(this,"_prng",h(n,o,a,f)),e(this,"PRNG",this._prng.PRNG),this}function gr(e,t,r,n){var o;if(arguments.length>3){if(!d(o=n))throw new TypeError(c("0rx2V",o));o=i({},n)}else o={};return o.objectMode=!0,new pr(e,t,r,o)}function yr(e,t,r,n){var o,s;if(1===(o=arguments.length)){if(!d(e))throw new TypeError(c("0rx2V",e));s=i({},e)}else if(o>3){if(!d(n))throw new TypeError(c("0rx2V",n));s=i({},n)}else s={};return o<3?function(e,t,r){return new pr(e,t,r,s)}:function(){return new pr(e,t,r,s)}}o(pr,dr),a(pr.prototype,"seed",(function(){return this._prng.seed})),a(pr.prototype,"seedLength",(function(){return this._prng.seedLength})),u(pr.prototype,"state",(function(){return this._prng.state}),(function(e){this._prng.state=e})),a(pr.prototype,"stateLength",(function(){return this._prng.stateLength})),a(pr.prototype,"byteLength",(function(){return this._prng.byteLength})),e(pr.prototype,"_read",(function(){var e,t;if(!this._destroyed)for(e=!0;e;){if(this._i+=1,this._i>this._iter)return cr("Finished generating pseudorandom numbers."),this.push(null);t=this._prng(),cr("Generated a new pseudorandom number. Value: %d. Iter: %d.",t,this._i),!1===this._objectMode&&(t=t.toString(),t=1===this._i?f(t):f(this._sep+t)),e=this.push(t),this._i%this._siter==0&&this.emit("state",this.state)}})),e(pr.prototype,"destroy",(function(e){var t;return this._destroyed?(cr("Attempted to destroy an already destroyed stream."),this):(t=this,this._destroyed=!0,l((function(){e&&(cr("Stream was destroyed due to an error. Error: %s.",n(e)?e.message:JSON.stringify(e)),t.emit("error",e));cr("Closing the stream..."),t.emit("close")})),this)})),e(pr,"objectMode",gr),e(pr,"factory",yr);export{pr as default,yr as factory,gr as objectMode}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..1b12076 --- /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( 'random:streams:triangular' );\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 { isPrimitive as isNumber } from '@stdlib/assert-is-number';\nimport isnan from '@stdlib/math-base-assert-is-nan';\nimport isError from '@stdlib/assert-is-error';\nimport assign from '@stdlib/object-assign';\nimport inherit from '@stdlib/utils-inherit';\nimport setNonEnumerable from '@stdlib/utils-define-nonenumerable-property';\nimport setNonEnumerableReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport setReadOnlyAccessor from '@stdlib/utils-define-read-only-accessor';\nimport setReadWriteAccessor from '@stdlib/utils-define-read-write-accessor';\nimport { factory as rtriang } from '@stdlib/random-base-triangular';\nimport string2buffer from '@stdlib/buffer-from-string';\nimport nextTick from '@stdlib/utils-next-tick';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport DEFAULTS from './defaults.json';\nimport validate from './validate.js';\nimport debug from './debug.js';\n\n\n// FUNCTIONS //\n\n/**\n* Returns the PRNG seed.\n*\n* @private\n* @returns {(PRNGSeedMT19937|null)} seed\n*/\nfunction getSeed() {\n\treturn this._prng.seed; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Returns the PRNG seed length.\n*\n* @private\n* @returns {(PositiveInteger|null)} seed length\n*/\nfunction getSeedLength() {\n\treturn this._prng.seedLength; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Returns the PRNG state length.\n*\n* @private\n* @returns {(PositiveInteger|null)} state length\n*/\nfunction getStateLength() {\n\treturn this._prng.stateLength; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Returns the PRNG state size (in bytes).\n*\n* @private\n* @returns {(PositiveInteger|null)} state size (in bytes)\n*/\nfunction getStateSize() {\n\treturn this._prng.byteLength; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Returns the current PRNG state.\n*\n* @private\n* @returns {(PRNGStateMT19937|null)} current state\n*/\nfunction getState() {\n\treturn this._prng.state; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Sets the PRNG state.\n*\n* @private\n* @param {PRNGStateMT19937} s - generator state\n* @throws {Error} must provide a valid state\n*/\nfunction setState( s ) {\n\tthis._prng.state = s; // eslint-disable-line no-invalid-this\n}\n\n/**\n* Implements the `_read` method.\n*\n* @private\n* @param {number} size - number (of bytes) to read\n* @returns {void}\n*/\nfunction read() {\n\t/* eslint-disable no-invalid-this */\n\tvar FLG;\n\tvar r;\n\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 generating pseudorandom numbers.' );\n\t\t\treturn this.push( null );\n\t\t}\n\t\tr = this._prng();\n\n\t\tdebug( 'Generated a new pseudorandom number. Value: %d. Iter: %d.', r, this._i );\n\n\t\tif ( this._objectMode === false ) {\n\t\t\tr = r.toString();\n\t\t\tif ( this._i === 1 ) {\n\t\t\t\tr = string2buffer( r );\n\t\t\t} else {\n\t\t\t\tr = string2buffer( this._sep+r );\n\t\t\t}\n\t\t}\n\t\tFLG = this.push( r );\n\t\tif ( this._i%this._siter === 0 ) {\n\t\t\tthis.emit( 'state', this.state );\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 {RandomStream} 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 of pseudorandom numbers drawn from a uniform distribution.\n*\n* @constructor\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\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 ceasing to generate additional pseudorandom numbers\n* @param {string} [options.sep='\\n'] - separator used to join streamed data\n* @param {NonNegativeInteger} [options.iter] - number of iterations\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {RandomStream} 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 RandomStream( 2.0, 5.0, 4.0, opts );\n*\n* stream.pipe( inspectStream( log ) );\n*/\nfunction RandomStream( a, b, c, options ) {\n\tvar opts;\n\tvar err;\n\tif ( !( this instanceof RandomStream ) ) {\n\t\tif ( arguments.length > 3 ) {\n\t\t\treturn new RandomStream( a, b, c, options );\n\t\t}\n\t\treturn new RandomStream( a, b, c );\n\t}\n\tif ( !isNumber( a ) || isnan( a ) ) {\n\t\tthrow new TypeError( format( '0rx6v', a ) );\n\t}\n\tif ( !isNumber( b ) || isnan( b ) ) {\n\t\tthrow new TypeError( format( '0rx6w', b ) );\n\t}\n\tif ( !isNumber( c ) || isnan( c ) ) {\n\t\tthrow new TypeError( format( '0rx7C', c ) );\n\t}\n\tif ( !(a <= c && c <= b) ) {\n\t\tthrow new RangeError( format( '0rx9C', 'a <= c <= b', a, b, c ) );\n\t}\n\topts = assign( {}, DEFAULTS );\n\tif ( arguments.length > 3 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// Make the stream a readable stream:\n\tdebug( 'Creating a readable stream configured with the following options: %s.', JSON.stringify( opts ) );\n\tReadable.call( this, opts );\n\n\t// Destruction state:\n\tsetNonEnumerable( this, '_destroyed', false );\n\n\t// Cache whether the stream is operating in object mode:\n\tsetNonEnumerableReadOnly( this, '_objectMode', opts.objectMode );\n\n\t// Cache the separator:\n\tsetNonEnumerableReadOnly( this, '_sep', opts.sep );\n\n\t// Cache the total number of iterations:\n\tsetNonEnumerableReadOnly( this, '_iter', opts.iter );\n\n\t// Cache the number of iterations after which to emit the underlying PRNG state:\n\tsetNonEnumerableReadOnly( this, '_siter', opts.siter );\n\n\t// Initialize an iteration counter:\n\tsetNonEnumerable( this, '_i', 0 );\n\n\t// Create the underlying PRNG:\n\tsetNonEnumerableReadOnly( this, '_prng', rtriang( a, b, c, opts ) );\n\tsetNonEnumerableReadOnly( this, 'PRNG', this._prng.PRNG );\n\n\treturn this;\n}\n\n/*\n* Inherit from the `Readable` prototype.\n*/\ninherit( RandomStream, Readable );\n\n/**\n* PRNG seed.\n*\n* @name seed\n* @memberof RandomStream.prototype\n* @type {(PRNGSeedMT19937|null)}\n*/\nsetReadOnlyAccessor( RandomStream.prototype, 'seed', getSeed );\n\n/**\n* PRNG seed length.\n*\n* @name seedLength\n* @memberof RandomStream.prototype\n* @type {(PositiveInteger|null)}\n*/\nsetReadOnlyAccessor( RandomStream.prototype, 'seedLength', getSeedLength );\n\n/**\n* PRNG state getter/setter.\n*\n* @name state\n* @memberof RandomStream.prototype\n* @type {(PRNGStateMT19937|null)}\n* @throws {Error} must provide a valid state\n*/\nsetReadWriteAccessor( RandomStream.prototype, 'state', getState, setState );\n\n/**\n* PRNG state length.\n*\n* @name stateLength\n* @memberof RandomStream.prototype\n* @type {(PositiveInteger|null)}\n*/\nsetReadOnlyAccessor( RandomStream.prototype, 'stateLength', getStateLength );\n\n/**\n* PRNG state size (in bytes).\n*\n* @name byteLength\n* @memberof RandomStream.prototype\n* @type {(PositiveInteger|null)}\n*/\nsetReadOnlyAccessor( RandomStream.prototype, 'byteLength', getStateSize );\n\n/**\n* Implements the `_read` method.\n*\n* @private\n* @name _read\n* @memberof RandomStream.prototype\n* @type {Function}\n* @param {number} size - number (of bytes) to read\n* @returns {void}\n*/\nsetNonEnumerableReadOnly( RandomStream.prototype, '_read', read );\n\n/**\n* Gracefully destroys a stream, providing backward compatibility.\n*\n* @name destroy\n* @memberof RandomStream.prototype\n* @type {Function}\n* @param {(string|Object|Error)} [error] - error\n* @returns {RandomStream} Stream instance\n*/\nsetNonEnumerableReadOnly( RandomStream.prototype, 'destroy', destroy );\n\n\n// EXPORTS //\n\nexport default RandomStream;\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 isPositiveInteger } from '@stdlib/assert-is-positive-integer';\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 ceasing to generate additional pseudorandom numbers\n* @param {NonNegativeInteger} [options.iter] - number of iterations\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state\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( '0rx2V', 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( '0rx2W', '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( '0rx2o', '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( '0rx7n', '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( '0rx4k', '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( '0rx2t', 'iter', opts.iter ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'siter' ) ) {\n\t\topts.siter = options.siter;\n\t\tif ( !isPositiveInteger( opts.siter ) ) {\n\t\t\treturn new TypeError( format( '0rx3P', 'siter', opts.siter ) );\n\t\t}\n\t}\n\t// Pass through options...\n\tif ( hasOwnProp( options, 'prng' ) ) {\n\t\topts.prng = options.prng;\n\t}\n\tif ( hasOwnProp( options, 'seed' ) ) {\n\t\topts.seed = options.seed;\n\t}\n\tif ( hasOwnProp( options, 'state' ) ) {\n\t\topts.state = options.state;\n\t}\n\tif ( hasOwnProp( options, 'copy' ) ) {\n\t\topts.copy = options.copy;\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 assign from '@stdlib/object-assign';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport RandomStream from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns an \"objectMode\" readable stream for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @param {number} a - minimum support\n* @param {number} b - maximum support\n* @param {number} c - mode\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 ceasing to generate additional pseudorandom numbers\n* @param {NonNegativeInteger} [options.iter] - number of iterations\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state\n* @throws {TypeError} `a` must be a number\n* @throws {TypeError} `b` must be a number\n* @throws {TypeError} `c` must be a number\n* @throws {RangeError} arguments must satisfy `a <= c <= b`\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {Error} must provide a valid state\n* @returns {RandomStream} 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( 2.0, 5.0, 4.0, opts );\n*\n* stream.pipe( inspectStream.objectMode( log ) );\n*/\nfunction objectMode( a, b, c, options ) {\n\tvar opts;\n\tif ( arguments.length > 3 ) {\n\t\topts = options;\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( '0rx2V', opts ) );\n\t\t}\n\t\topts = assign( {}, options );\n\t} else {\n\t\topts = {};\n\t}\n\topts.objectMode = true;\n\treturn new RandomStream( a, b, c, 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 isPlainObject from '@stdlib/assert-is-plain-object';\nimport assign from '@stdlib/object-assign';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport RandomStream from './main.js';\n\n\n// MAIN //\n\n/**\n* Returns a function for creating readable streams which generate pseudorandom numbers drawn from a triangular distribution.\n*\n* @param {number} [a] - minimum support\n* @param {number} [b] - maximum support\n* @param {number} [c] - mode\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 ceasing to generate additional pseudorandom numbers\n* @param {string} [options.sep='\\n'] - separator used to join streamed data\n* @param {NonNegativeInteger} [options.iter] - number of iterations\n* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers\n* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed\n* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state\n* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state\n* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state\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( 2.0, 5.0, 4.0 ) );\n* }\n*/\nfunction factory( a, b, c, options ) {\n\tvar nargs;\n\tvar opts;\n\tvar fcn;\n\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tif ( !isPlainObject( a ) ) {\n\t\t\tthrow new TypeError( format( '0rx2V', a ) );\n\t\t}\n\t\topts = assign( {}, a );\n\t} else if ( nargs > 3 ) {\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0rx2V', options ) );\n\t\t}\n\t\topts = assign( {}, options );\n\t} else {\n\t\topts = {};\n\t}\n\tif ( nargs < 3 ) {\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 for generating pseudorandom numbers drawn from a triangular distribution.\n\t*\n\t* @private\n\t* @param {number} a - minimum support\n\t* @param {number} b - maximum support\n\t* @param {number} c - mode\n\t* @throws {TypeError} `a` must be a number\n\t* @throws {TypeError} `b` must be a number\n\t* @throws {TypeError} `c` must be a number\n\t* @throws {RangeError} arguments must satisfy `a <= c <= b`\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @throws {Error} must provide a valid state\n\t* @returns {RandomStream} Stream instance\n\t*/\n\tfunction createStream1( a, b, c ) {\n\t\treturn new RandomStream( a, b, c, opts );\n\t}\n\n\t/**\n\t* Returns a readable stream for generating pseudorandom numbers drawn from a triangular distribution.\n\t*\n\t* @private\n\t* @throws {TypeError} `a` must be a number\n\t* @throws {TypeError} `b` must be a number\n\t* @throws {TypeError} `c` must be a number\n\t* @throws {RangeError} arguments must satisfy `a <= c <= b`\n\t* @throws {TypeError} options argument must be an object\n\t* @throws {TypeError} must provide valid options\n\t* @throws {Error} must provide a valid state\n\t* @returns {RandomStream} Stream instance\n\t*/\n\tfunction createStream2() {\n\t\treturn new RandomStream( a, b, c, 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 for generating pseudorandom numbers drawn from a triangular distribution.\n*\n* @module @stdlib/random-streams-triangular\n*\n* @example\n* import inspectStream from '@stdlib/streams-node-inspect-sink';\n* import randomStream from '@stdlib/random-streams-triangular';\n*\n* function log( chunk ) {\n* console.log( chunk.toString() );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = randomStream( 2.0, 5.0, 4.0, opts );\n*\n* stream.pipe( inspectStream( log ) );\n*\n* @example\n* import randomStream from '@stdlib/random-streams-triangular';\n*\n* var opts = {\n* 'sep': ',',\n* 'objectMode': false,\n* 'encoding': 'utf8',\n* 'highWaterMark': 64\n* };\n*\n* var createStream = randomStream.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( 2.0, 5.0, 4.0 ) );\n* }\n*\n* @example\n* import inspectStream from '@stdlib/streams-node-inspect-sink';\n* import randomStream from '@stdlib/random-streams-triangular';\n*\n* function log( v ) {\n* console.log( v );\n* }\n*\n* var opts = {\n* 'iter': 10\n* };\n*\n* var stream = randomStream.objectMode( 2.0, 5.0, 4.0, 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","RandomStream","a","b","c","options","opts","err","this","arguments","length","isNumber","isnan","TypeError","format","RangeError","assign","DEFAULTS","isObject","hasOwnProp","sep","isString","objectMode","isBoolean","encoding","highWaterMark","isNonNegative","iter","isNonNegativeInteger","siter","isPositiveInteger","prng","seed","state","copy","validate","JSON","stringify","call","setNonEnumerable","setNonEnumerableReadOnly","rtriang","_prng","PRNG","factory","nargs","isPlainObject","inherit","setReadOnlyAccessor","prototype","seedLength","setReadWriteAccessor","s","stateLength","byteLength","FLG","r","_destroyed","_i","_iter","push","_objectMode","toString","string2buffer","_sep","_siter","emit","error","self","nextTick","isError","message","setReadOnly","main"],"mappings":";;+zxDA2BIA,wDAAQC,CAAQ,6BCLhBC,GAAWC,GAA6BD,SAgN5C,SAASE,GAAcC,EAAGC,EAAGC,EAAGC,GAC/B,IAAIC,EACAC,EACJ,KAAQC,gBAAgBP,IACvB,OAAKQ,UAAUC,OAAS,EAChB,IAAIT,GAAcC,EAAGC,EAAGC,EAAGC,GAE5B,IAAIJ,GAAcC,EAAGC,EAAGC,GAEhC,IAAMO,EAAUT,IAAOU,EAAOV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMS,EAAUR,IAAOS,EAAOT,GAC7B,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMQ,EAAUP,IAAOQ,EAAOR,GAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,KAAOF,GAAKE,GAAKA,GAAKD,GACrB,MAAM,IAAIY,WAAYD,EAAQ,QAAS,cAAeZ,EAAGC,EAAGC,IAG7D,GADAE,EAAOU,EAAQ,GAAIC,IACdR,UAAUC,OAAS,IACvBH,EC/LF,SAAmBD,EAAMD,GACxB,OAAMa,EAAUb,GAGXc,EAAYd,EAAS,SACzBC,EAAKc,IAAMf,EAAQe,KACbC,EAAUf,EAAKc,MACb,IAAIP,UAAWC,EAAQ,QAAS,MAAOR,EAAKc,MAGhDD,EAAYd,EAAS,gBACzBC,EAAKgB,WAAajB,EAAQiB,YACpBC,EAAWjB,EAAKgB,aACd,IAAIT,UAAWC,EAAQ,QAAS,aAAcR,EAAKgB,aAGvDH,EAAYd,EAAS,cACzBC,EAAKkB,SAAWnB,EAAQmB,UAClBH,EAAUf,EAAKkB,WAAgC,OAAlBlB,EAAKkB,UAChC,IAAIX,UAAWC,EAAQ,QAAS,WAAYR,EAAKkB,WAGrDL,EAAYd,EAAS,mBACzBC,EAAKmB,cAAgBpB,EAAQoB,eACvBC,EAAepB,EAAKmB,gBAClB,IAAIZ,UAAWC,EAAQ,QAAS,gBAAiBR,EAAKmB,gBAG1DN,EAAYd,EAAS,UACzBC,EAAKqB,KAAOtB,EAAQsB,MACdC,EAAsBtB,EAAKqB,OACzB,IAAId,UAAWC,EAAQ,QAAS,OAAQR,EAAKqB,OAGjDR,EAAYd,EAAS,WACzBC,EAAKuB,MAAQxB,EAAQwB,OACfC,EAAmBxB,EAAKuB,QACtB,IAAIhB,UAAWC,EAAQ,QAAS,QAASR,EAAKuB,SAIlDV,EAAYd,EAAS,UACzBC,EAAKyB,KAAO1B,EAAQ0B,MAEhBZ,EAAYd,EAAS,UACzBC,EAAK0B,KAAO3B,EAAQ2B,MAEhBb,EAAYd,EAAS,WACzBC,EAAK2B,MAAQ5B,EAAQ4B,OAEjBd,EAAYd,EAAS,UACzBC,EAAK4B,KAAO7B,EAAQ6B,MAEd,MAnDC,IAAIrB,UAAWC,EAAQ,QAAST,GAoDzC,CDyIQ8B,CAAU7B,EAAMD,GACjBE,GACJ,MAAMA,EA6BR,OAzBAV,GAAO,wEAAyEuC,KAAKC,UAAW/B,IAChGP,GAASuC,KAAM9B,KAAMF,GAGrBiC,EAAkB/B,KAAM,cAAc,GAGtCgC,EAA0BhC,KAAM,cAAeF,EAAKgB,YAGpDkB,EAA0BhC,KAAM,OAAQF,EAAKc,KAG7CoB,EAA0BhC,KAAM,QAASF,EAAKqB,MAG9Ca,EAA0BhC,KAAM,SAAUF,EAAKuB,OAG/CU,EAAkB/B,KAAM,KAAM,GAG9BgC,EAA0BhC,KAAM,QAASiC,EAASvC,EAAGC,EAAGC,EAAGE,IAC3DkC,EAA0BhC,KAAM,OAAQA,KAAKkC,MAAMC,MAE5CnC,IACR,CExNA,SAASc,GAAYpB,EAAGC,EAAGC,EAAGC,GAC7B,IAAIC,EACJ,GAAKG,UAAUC,OAAS,EAAI,CAE3B,IAAMQ,EADNZ,EAAOD,GAEN,MAAM,IAAIQ,UAAWC,EAAQ,QAASR,IAEvCA,EAAOU,EAAQ,GAAIX,EACrB,MACEC,EAAO,CAAA,EAGR,OADAA,EAAKgB,YAAa,EACX,IAAIrB,GAAcC,EAAGC,EAAGC,EAAGE,EACnC,CCfA,SAASsC,GAAS1C,EAAGC,EAAGC,EAAGC,GAC1B,IAAIwC,EACAvC,EAIJ,GAAe,KADfuC,EAAQpC,UAAUC,QACC,CAClB,IAAMoC,EAAe5C,GACpB,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvCI,EAAOU,EAAQ,GAAId,EACrB,MAAQ,GAAK2C,EAAQ,EAAI,CACvB,IAAMC,EAAezC,GACpB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvCC,EAAOU,EAAQ,GAAIX,EACrB,MACEC,EAAO,CAAA,EAOR,OALKuC,EAAQ,EAuBb,SAAwB3C,EAAGC,EAAGC,GAC7B,OAAO,IAAIH,GAAcC,EAAGC,EAAGC,EAAGE,EAClC,EAeD,WACC,OAAO,IAAIL,GAAcC,EAAGC,EAAGC,EAAGE,EAClC,CACF,CHiKAyC,EAAS9C,GAAcF,IASvBiD,EAAqB/C,GAAagD,UAAW,QA1P7C,WACC,OAAOzC,KAAKkC,MAAMV,IACnB,IAiQAgB,EAAqB/C,GAAagD,UAAW,cAzP7C,WACC,OAAOzC,KAAKkC,MAAMQ,UACnB,IAiQAC,EAAsBlD,GAAagD,UAAW,SArO9C,WACC,OAAOzC,KAAKkC,MAAMT,KACnB,IASA,SAAmBmB,GAClB5C,KAAKkC,MAAMT,MAAQmB,CACpB,IAiOAJ,EAAqB/C,GAAagD,UAAW,eAlQ7C,WACC,OAAOzC,KAAKkC,MAAMW,WACnB,IAyQAL,EAAqB/C,GAAagD,UAAW,cAjQ7C,WACC,OAAOzC,KAAKkC,MAAMY,UACnB,IA2QAd,EAA0BvC,GAAagD,UAAW,SA7OlD,WAEC,IAAIM,EACAC,EAEJ,IAAKhD,KAAKiD,WAIV,IADAF,GAAM,EACEA,GAAM,CAEb,GADA/C,KAAKkD,IAAM,EACNlD,KAAKkD,GAAKlD,KAAKmD,MAEnB,OADA9D,GAAO,6CACAW,KAAKoD,KAAM,MAEnBJ,EAAIhD,KAAKkC,QAET7C,GAAO,4DAA6D2D,EAAGhD,KAAKkD,KAElD,IAArBlD,KAAKqD,cACTL,EAAIA,EAAEM,WAELN,EADgB,IAAZhD,KAAKkD,GACLK,EAAeP,GAEfO,EAAevD,KAAKwD,KAAKR,IAG/BD,EAAM/C,KAAKoD,KAAMJ,GACZhD,KAAKkD,GAAGlD,KAAKyD,QAAW,GAC5BzD,KAAK0D,KAAM,QAAS1D,KAAKyB,MAE1B,CAGF,IAsNAO,EAA0BvC,GAAagD,UAAW,WA7MlD,SAAkBkB,GAEjB,IAAIC,EACJ,OAAK5D,KAAKiD,YACT5D,GAAO,qDACAW,OAER4D,EAAO5D,KACPA,KAAKiD,YAAa,EAElBY,GASA,WACMF,IACJtE,GAAO,mDAAsDyE,EAASH,GAAYA,EAAMI,QAAUnC,KAAKC,UAAW8B,IAClHC,EAAKF,KAAM,QAASC,IAErBtE,GAAO,yBACPuE,EAAKF,KAAM,QACX,IAdM1D,KAiBR,II/FAgE,EAAAC,GAAA,aAAAnD,IACAkD,EAAAC,GAAA,UAAA7B"} \ No newline at end of file diff --git a/lib/debug.js b/lib/debug.js deleted file mode 100644 index ce8ecf0..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( 'random:streams:triangular' ); - - -// EXPORTS // - -module.exports = debug; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 4c9d4bb..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "objectMode": false, - "encoding": null, - "sep": "\n", - "copy": true, - "siter": 1e308 -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index fe6c483..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,135 +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 isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var assign = require( '@stdlib/object-assign' ); -var format = require( '@stdlib/string-format' ); -var RandomStream = require( './main.js' ); - - -// MAIN // - -/** -* Returns a function for creating readable streams which generate pseudorandom numbers drawn from a triangular distribution. -* -* @param {number} [a] - minimum support -* @param {number} [b] - maximum support -* @param {number} [c] - mode -* @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 ceasing to generate additional pseudorandom numbers -* @param {string} [options.sep='\n'] - separator used to join streamed data -* @param {NonNegativeInteger} [options.iter] - number of iterations -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state -* @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( 2.0, 5.0, 4.0 ) ); -* } -*/ -function factory( a, b, c, options ) { - var nargs; - var opts; - var fcn; - - nargs = arguments.length; - if ( nargs === 1 ) { - if ( !isPlainObject( a ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', a ) ); - } - opts = assign( {}, a ); - } else if ( nargs > 3 ) { - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - opts = assign( {}, options ); - } else { - opts = {}; - } - if ( nargs < 3 ) { - fcn = createStream1; - } else { - fcn = createStream2; - } - return fcn; - - /** - * Returns a readable stream for generating pseudorandom numbers drawn from a triangular distribution. - * - * @private - * @param {number} a - minimum support - * @param {number} b - maximum support - * @param {number} c - mode - * @throws {TypeError} `a` must be a number - * @throws {TypeError} `b` must be a number - * @throws {TypeError} `c` must be a number - * @throws {RangeError} arguments must satisfy `a <= c <= b` - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @throws {Error} must provide a valid state - * @returns {RandomStream} Stream instance - */ - function createStream1( a, b, c ) { - return new RandomStream( a, b, c, opts ); - } - - /** - * Returns a readable stream for generating pseudorandom numbers drawn from a triangular distribution. - * - * @private - * @throws {TypeError} `a` must be a number - * @throws {TypeError} `b` must be a number - * @throws {TypeError} `c` must be a number - * @throws {RangeError} arguments must satisfy `a <= c <= b` - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @throws {Error} must provide a valid state - * @returns {RandomStream} Stream instance - */ - function createStream2() { - return new RandomStream( a, b, c, opts ); - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 32009b0..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 for generating pseudorandom numbers drawn from a triangular distribution. -* -* @module @stdlib/random-streams-triangular -* -* @example -* var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -* var randomStream = require( '@stdlib/random-streams-triangular' ); -* -* function log( chunk ) { -* console.log( chunk.toString() ); -* } -* -* var opts = { -* 'iter': 10 -* }; -* -* var stream = randomStream( 2.0, 5.0, 4.0, opts ); -* -* stream.pipe( inspectStream( log ) ); -* -* @example -* var randomStream = require( '@stdlib/random-streams-triangular' ); -* -* var opts = { -* 'sep': ',', -* 'objectMode': false, -* 'encoding': 'utf8', -* 'highWaterMark': 64 -* }; -* -* var createStream = randomStream.factory( opts ); -* -* // Create 10 identically configured streams... -* var streams = []; -* var i; -* for ( i = 0; i < 10; i++ ) { -* streams.push( createStream( 2.0, 5.0, 4.0 ) ); -* } -* -* @example -* var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -* var randomStream = require( '@stdlib/random-streams-triangular' ); -* -* function log( v ) { -* console.log( v ); -* } -* -* var opts = { -* 'iter': 10 -* }; -* -* var stream = randomStream.objectMode( 2.0, 5.0, 4.0, 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 600300d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,365 +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 isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isError = require( '@stdlib/assert-is-error' ); -var assign = require( '@stdlib/object-assign' ); -var inherit = require( '@stdlib/utils-inherit' ); -var setNonEnumerable = require( '@stdlib/utils-define-nonenumerable-property' ); -var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-read-only-accessor' ); -var setReadWriteAccessor = require( '@stdlib/utils-define-read-write-accessor' ); -var rtriang = require( '@stdlib/random-base-triangular' ).factory; -var string2buffer = require( '@stdlib/buffer-from-string' ); -var nextTick = require( '@stdlib/utils-next-tick' ); -var format = require( '@stdlib/string-format' ); -var DEFAULTS = require( './defaults.json' ); -var validate = require( './validate.js' ); -var debug = require( './debug.js' ); - - -// FUNCTIONS // - -/** -* Returns the PRNG seed. -* -* @private -* @returns {(PRNGSeedMT19937|null)} seed -*/ -function getSeed() { - return this._prng.seed; // eslint-disable-line no-invalid-this -} - -/** -* Returns the PRNG seed length. -* -* @private -* @returns {(PositiveInteger|null)} seed length -*/ -function getSeedLength() { - return this._prng.seedLength; // eslint-disable-line no-invalid-this -} - -/** -* Returns the PRNG state length. -* -* @private -* @returns {(PositiveInteger|null)} state length -*/ -function getStateLength() { - return this._prng.stateLength; // eslint-disable-line no-invalid-this -} - -/** -* Returns the PRNG state size (in bytes). -* -* @private -* @returns {(PositiveInteger|null)} state size (in bytes) -*/ -function getStateSize() { - return this._prng.byteLength; // eslint-disable-line no-invalid-this -} - -/** -* Returns the current PRNG state. -* -* @private -* @returns {(PRNGStateMT19937|null)} current state -*/ -function getState() { - return this._prng.state; // eslint-disable-line no-invalid-this -} - -/** -* Sets the PRNG state. -* -* @private -* @param {PRNGStateMT19937} s - generator state -* @throws {Error} must provide a valid state -*/ -function setState( s ) { - this._prng.state = s; // eslint-disable-line no-invalid-this -} - -/** -* Implements the `_read` method. -* -* @private -* @param {number} size - number (of bytes) to read -* @returns {void} -*/ -function read() { - /* eslint-disable no-invalid-this */ - var FLG; - var r; - - if ( this._destroyed ) { - return; - } - FLG = true; - while ( FLG ) { - this._i += 1; - if ( this._i > this._iter ) { - debug( 'Finished generating pseudorandom numbers.' ); - return this.push( null ); - } - r = this._prng(); - - debug( 'Generated a new pseudorandom number. Value: %d. Iter: %d.', r, this._i ); - - if ( this._objectMode === false ) { - r = r.toString(); - if ( this._i === 1 ) { - r = string2buffer( r ); - } else { - r = string2buffer( this._sep+r ); - } - } - FLG = this.push( r ); - if ( this._i%this._siter === 0 ) { - this.emit( 'state', this.state ); - } - } - - /* eslint-enable no-invalid-this */ -} - -/** -* Gracefully destroys a stream, providing backward compatibility. -* -* @private -* @param {(string|Object|Error)} [error] - error -* @returns {RandomStream} 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 of pseudorandom numbers drawn from a uniform distribution. -* -* @constructor -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @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 ceasing to generate additional pseudorandom numbers -* @param {string} [options.sep='\n'] - separator used to join streamed data -* @param {NonNegativeInteger} [options.iter] - number of iterations -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {RandomStream} 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 RandomStream( 2.0, 5.0, 4.0, opts ); -* -* stream.pipe( inspectStream( log ) ); -*/ -function RandomStream( a, b, c, options ) { - var opts; - var err; - if ( !( this instanceof RandomStream ) ) { - if ( arguments.length > 3 ) { - return new RandomStream( a, b, c, options ); - } - return new RandomStream( a, b, c ); - } - if ( !isNumber( a ) || isnan( a ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a number and not NaN. Value: `%s`.', a ) ); - } - if ( !isNumber( b ) || isnan( b ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a number and not NaN. Value: `%s`.', b ) ); - } - if ( !isNumber( c ) || isnan( c ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a number and not NaN. Value: `%s`.', c ) ); - } - if ( !(a <= c && c <= b) ) { - throw new RangeError( format( 'invalid arguments. Parameters must satisfy the following condition: %s. a: `%f`. b: `%f`. c: `%f`.', 'a <= c <= b', a, b, c ) ); - } - opts = assign( {}, DEFAULTS ); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - // Make the stream a readable stream: - debug( 'Creating a readable stream configured with the following options: %s.', JSON.stringify( opts ) ); - Readable.call( this, opts ); - - // Destruction state: - setNonEnumerable( this, '_destroyed', false ); - - // Cache whether the stream is operating in object mode: - setNonEnumerableReadOnly( this, '_objectMode', opts.objectMode ); - - // Cache the separator: - setNonEnumerableReadOnly( this, '_sep', opts.sep ); - - // Cache the total number of iterations: - setNonEnumerableReadOnly( this, '_iter', opts.iter ); - - // Cache the number of iterations after which to emit the underlying PRNG state: - setNonEnumerableReadOnly( this, '_siter', opts.siter ); - - // Initialize an iteration counter: - setNonEnumerable( this, '_i', 0 ); - - // Create the underlying PRNG: - setNonEnumerableReadOnly( this, '_prng', rtriang( a, b, c, opts ) ); - setNonEnumerableReadOnly( this, 'PRNG', this._prng.PRNG ); - - return this; -} - -/* -* Inherit from the `Readable` prototype. -*/ -inherit( RandomStream, Readable ); - -/** -* PRNG seed. -* -* @name seed -* @memberof RandomStream.prototype -* @type {(PRNGSeedMT19937|null)} -*/ -setReadOnlyAccessor( RandomStream.prototype, 'seed', getSeed ); - -/** -* PRNG seed length. -* -* @name seedLength -* @memberof RandomStream.prototype -* @type {(PositiveInteger|null)} -*/ -setReadOnlyAccessor( RandomStream.prototype, 'seedLength', getSeedLength ); - -/** -* PRNG state getter/setter. -* -* @name state -* @memberof RandomStream.prototype -* @type {(PRNGStateMT19937|null)} -* @throws {Error} must provide a valid state -*/ -setReadWriteAccessor( RandomStream.prototype, 'state', getState, setState ); - -/** -* PRNG state length. -* -* @name stateLength -* @memberof RandomStream.prototype -* @type {(PositiveInteger|null)} -*/ -setReadOnlyAccessor( RandomStream.prototype, 'stateLength', getStateLength ); - -/** -* PRNG state size (in bytes). -* -* @name byteLength -* @memberof RandomStream.prototype -* @type {(PositiveInteger|null)} -*/ -setReadOnlyAccessor( RandomStream.prototype, 'byteLength', getStateSize ); - -/** -* Implements the `_read` method. -* -* @private -* @name _read -* @memberof RandomStream.prototype -* @type {Function} -* @param {number} size - number (of bytes) to read -* @returns {void} -*/ -setNonEnumerableReadOnly( RandomStream.prototype, '_read', read ); - -/** -* Gracefully destroys a stream, providing backward compatibility. -* -* @name destroy -* @memberof RandomStream.prototype -* @type {Function} -* @param {(string|Object|Error)} [error] - error -* @returns {RandomStream} Stream instance -*/ -setNonEnumerableReadOnly( RandomStream.prototype, 'destroy', destroy ); - - -// EXPORTS // - -module.exports = RandomStream; diff --git a/lib/object_mode.js b/lib/object_mode.js deleted file mode 100644 index 0f7eefd..0000000 --- a/lib/object_mode.js +++ /dev/null @@ -1,88 +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 assign = require( '@stdlib/object-assign' ); -var format = require( '@stdlib/string-format' ); -var RandomStream = require( './main.js' ); - - -// MAIN // - -/** -* Returns an "objectMode" readable stream for generating pseudorandom numbers drawn from a triangular distribution. -* -* @param {number} a - minimum support -* @param {number} b - maximum support -* @param {number} c - mode -* @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 ceasing to generate additional pseudorandom numbers -* @param {NonNegativeInteger} [options.iter] - number of iterations -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state -* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state -* @throws {TypeError} `a` must be a number -* @throws {TypeError} `b` must be a number -* @throws {TypeError} `c` must be a number -* @throws {RangeError} arguments must satisfy `a <= c <= b` -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide a valid state -* @returns {RandomStream} Stream instance -* -* @example -* var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -* -* function log( v ) { -* console.log( v ); -* } -* -* var opts = { -* 'iter': 10 -* }; -* -* var stream = objectMode( 2.0, 5.0, 4.0, opts ); -* -* stream.pipe( inspectStream.objectMode( log ) ); -*/ -function objectMode( a, b, c, options ) { - var opts; - if ( arguments.length > 3 ) { - 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 RandomStream( a, b, c, opts ); -} - - -// EXPORTS // - -module.exports = objectMode; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 3a4eefd..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,122 +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 isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).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 ceasing to generate additional pseudorandom numbers -* @param {NonNegativeInteger} [options.iter] - number of iterations -* @param {PRNG} [options.prng] - pseudorandom number generator which generates uniformly distributed pseudorandom numbers -* @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed -* @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state -* @param {boolean} [options.copy] - boolean indicating whether to copy a provided pseudorandom number generator state -* @param {PositiveInteger} [options.siter] - number of iterations after which to emit the PRNG state -* @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 ) ); - } - } - if ( hasOwnProp( options, 'siter' ) ) { - opts.siter = options.siter; - if ( !isPositiveInteger( opts.siter ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'siter', opts.siter ) ); - } - } - // Pass through options... - if ( hasOwnProp( options, 'prng' ) ) { - opts.prng = options.prng; - } - if ( hasOwnProp( options, 'seed' ) ) { - opts.seed = options.seed; - } - if ( hasOwnProp( options, 'state' ) ) { - opts.state = options.state; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 9799fa2..60dd2e1 100644 --- a/package.json +++ b/package.json @@ -3,34 +3,8 @@ "version": "0.2.2", "description": "Create a readable stream for generating pseudorandom numbers drawn from a triangular distribution.", "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": { - "random-triangular": "./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,77 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-uint32": "^0.2.3", - "@stdlib/array-uint8": "^0.2.3", - "@stdlib/assert-has-own-property": "^0.2.3", - "@stdlib/assert-is-boolean": "^0.2.3", - "@stdlib/assert-is-error": "^0.2.3", - "@stdlib/assert-is-integer": "^0.2.3", - "@stdlib/assert-is-nonnegative-integer": "^0.2.3", - "@stdlib/assert-is-nonnegative-number": "^0.2.3", - "@stdlib/assert-is-number": "^0.2.3", - "@stdlib/assert-is-plain-object": "^0.2.3", - "@stdlib/assert-is-positive-integer": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/assert-is-uint8array": "^0.2.3", - "@stdlib/blas-base-gcopy": "^0.2.3", - "@stdlib/buffer-from-array": "^0.2.3", - "@stdlib/buffer-from-string": "^0.2.3", - "@stdlib/cli-ctor": "^0.2.3", - "@stdlib/fs-read-file": "^0.2.3", - "@stdlib/fs-write-file": "^0.2.3", - "@stdlib/math-base-assert-is-nan": "^0.2.3", - "@stdlib/object-assign": "^0.2.3", - "@stdlib/process-cwd": "^0.2.3", - "@stdlib/random-base-triangular": "^0.2.2", - "@stdlib/streams-node-stdout": "^0.2.3", - "@stdlib/string-format": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/utils-define-nonenumerable-property": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3", - "@stdlib/utils-define-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-read-write-accessor": "^0.2.3", - "@stdlib/utils-inherit": "^0.2.3", - "@stdlib/utils-next-tick": "^0.2.3", - "debug": "^2.6.9", - "readable-stream": "^2.1.4", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/assert-is-browser": "^0.2.3", - "@stdlib/assert-is-buffer": "^0.2.3", - "@stdlib/assert-is-uint32array": "^0.2.3", - "@stdlib/assert-is-windows": "^0.2.3", - "@stdlib/constants-uint32-max": "^0.2.3", - "@stdlib/fs-exists": "^0.2.3", - "@stdlib/fs-unlink": "^0.2.3", - "@stdlib/process-exec-path": "^0.2.3", - "@stdlib/random-base-minstd": "^0.2.3", - "@stdlib/streams-node-inspect-sink": "^0.2.3", - "@stdlib/string-replace": "^0.2.3", - "@stdlib/time-now": "^0.2.3", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "proxyquire": "^2.0.0", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdmath", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c9367b8 --- /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/fixtures/bad_state.txt b/test/fixtures/bad_state.txt deleted file mode 100644 index 988ab48..0000000 Binary files a/test/fixtures/bad_state.txt and /dev/null differ diff --git a/test/fixtures/state.txt b/test/fixtures/state.txt deleted file mode 100644 index 785c73f..0000000 Binary files a/test/fixtures/state.txt and /dev/null differ diff --git a/test/fixtures/write_error.js.txt b/test/fixtures/write_error.js.txt deleted file mode 100644 index 134b65f..0000000 --- a/test/fixtures/write_error.js.txt +++ /dev/null @@ -1,42 +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. -*/ - -var proc = require( 'process' ); -var resolve = require( 'path' ).resolve; -var proxyquire = require( 'proxyquire' ); - -var fpath = resolve( __dirname, '..', 'bin', 'cli' ); - -proc.stdin.isTTY = true; -proc.argv[ 2 ] = 2.0; -proc.argv[ 3 ] = 5.0; -proc.argv[ 4 ] = 4.0; -proc.argv[ 5 ] = '--iter'; -proc.argv[ 6 ] = '10'; -proc.argv[ 7 ] = '--snapshot'; -proc.argv[ 8 ] = resolve( __dirname, 'fixtures', 'tmp_state.txt' ); - -proxyquire( fpath, { - '@stdlib/fs-write-file': { - 'sync': writeFile - } -}); - -function writeFile() { - return new Error( 'beep' ); -} diff --git a/test/test.cli.js b/test/test.cli.js deleted file mode 100644 index 24e10bd..0000000 --- a/test/test.cli.js +++ /dev/null @@ -1,524 +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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var triangular = require( '@stdlib/random-base-triangular' ).factory; -var readFileSync = require( '@stdlib/fs-read-file' ).sync; -var existsSync = require( '@stdlib/fs-exists' ).sync; -var unlinkSync = require( '@stdlib/fs-unlink' ).sync; -var Uint32Array = require( '@stdlib/array-uint32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var gcopy = require( '@stdlib/blas-base-gcopy' ); -var replace = require( '@stdlib/string-replace' ); -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( 'if provided insufficient arguments, the command-line interface prints an error and sets a non-zero exit code (one)', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '2.0', - '5.0' - ]; - - 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 generated pseudorandom numbers', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '2.0', - '5.0', - '4.0', - '--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 numbers + trailing newline: - t.strictEqual( results.length, 11, 'has expected length' ); - for ( i = 0; i < results.length-1; i++ ) { - v = parseFloat( results[ i ] ); - t.strictEqual( typeof v, 'number', 'has expected type' ); - t.strictEqual( isnan( v ), false, 'is not NaN' ); - } - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying the pseudorandom number generator seed', opts, function test( t ) { - var rand; - var cmd; - - cmd = [ - EXEC_PATH, - fpath, - '2.0', - '5.0', - '4.0', - '--iter 10', - '--seed 12345' - ]; - - // Note: we assume that the underlying generator is the following PRNG... - rand = triangular( 2.0, 5.0, 4.0, { - 'seed': 12345 - }); - - 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 numbers + 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, rand(), 'prints expected value' ); - } - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a custom delimiter', opts, function test( t ) { - var cmd = [ - EXEC_PATH, - fpath, - '2.0', - '5.0', - '4.0', - '--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( typeof v, 'number', 'has expected type' ); - t.strictEqual( isnan( v ), false, 'is not NaN' ); - } - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying a pseudorandom number generator state', opts, function test( t ) { - var state; - var spath; - var rand; - var cmd; - var len; - - spath = resolve( __dirname, 'fixtures', 'state.txt' ); - state = readFileSync( spath ); - - cmd = [ - EXEC_PATH, - fpath, - '2.0', - '5.0', - '4.0', - '--iter 10', - '--state "'+spath+'"' - ]; - - // Explicitly copy the `Buffer`, as, in older Node.js versions, `Buffer` is not a typed array: - len = state.length; - state = gcopy( len, state, 1, new Uint8Array( len ), 1 ); - state = new Uint32Array( state.buffer, state.byteOffset, len/Uint32Array.BYTES_PER_ELEMENT ); // eslint-disable-line max-len - - // Note: we assume that the underlying generator is the following PRNG... - rand = triangular( 2.0, 5.0, 4.0, { - 'state': state - }); - - 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 numbers + 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, rand(), 'prints expected value' ); - } - } - t.end(); - } -}); - -tape( 'the command-line interface supports specifying an output file path for saving the pseudorandom number generator state upon exit', opts, function test( t ) { - var state; - var spath; - var rand; - var cmd; - var arr; - var i; - - // Define an output path for a temporary file: - spath = resolve( __dirname, 'fixtures', 'tmp_state_snapshot.txt' ); - - // Ensure that the temporary file does not already exist: - if ( existsSync( spath ) ) { - t.fail( 'temporary file should not exist: '+spath ); - return t.end(); - } - - cmd = [ - EXEC_PATH, - fpath, - '2.0', - '5.0', - '4.0', - '--seed 12345', - '--iter 10', - '--snapshot "'+spath+'"' - ]; - - // Note: we assume that the underlying generator is the following PRNG... - rand = triangular( 2.0, 5.0, 4.0, { - 'seed': 12345 - }); - - // Advance the PRNG state: - arr = []; - for ( i = 0; i < 10; i++ ) { - arr.push( rand() ); - } - - // Get the current PRNG state: - state = rand.state; - - exec( cmd.join( ' ' ), done ); - - function done( error, stdout, stderr ) { - var snapshot; - var results; - var len; - var err; - 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 numbers + 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, arr[ i ], 'prints expected value' ); - } - - // Check that the PRNG state was written to a file: - t.strictEqual( existsSync( spath ), true, 'temporary snapshot file exists' ); - - // Verify the file contents (note: we need to explicitly copy the `Buffer`, as, in older Node.js versions, `Buffer` is not a typed array): - snapshot = readFileSync( spath ); - len = snapshot.length; - snapshot = gcopy( len, snapshot, 1, new Uint8Array( len ), 1 ); - snapshot = new Uint32Array( snapshot.buffer, snapshot.byteOffset, len/Uint32Array.BYTES_PER_ELEMENT ); // eslint-disable-line max-len - - t.deepEqual( snapshot, state, 'file contains expected contents' ); - - // Remove the temporary file: - err = unlinkSync( spath ); - if ( err ) { - t.fail( err.message ); - } - t.strictEqual( existsSync( spath ), false, 'temporary snapshot file does not exist' ); - } - t.end(); - } -}); - -tape( 'if provided an invalid pseudorandom number generator state, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var spath; - var cmd; - - spath = resolve( __dirname, 'fixtures', 'bad_state.txt' ); - - cmd = [ - EXEC_PATH, - fpath, - '2.0', - '5.0', - '4.0', - '--iter 10', - '--state "'+spath+'"' - ]; - - 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( 'if an error is encountered when writing pseudorandom number generator state to file, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { - var script; - var opts; - var cmd; - - script = readFileSync( resolve( __dirname, 'fixtures', 'write_error.js.txt' ), { - 'encoding': 'utf8' - }); - - // Replace single quotes with double quotes: - script = replace( script, '\'', '"' ); - - cmd = [ - EXEC_PATH, - '-e', - '\''+script+'\'' - ]; - - opts = { - 'cwd': __dirname - }; - - exec( cmd.join( ' ' ), opts, done ); - - function done( error, stdout, stderr ) { - if ( error ) { - t.pass( error.message ); - t.strictEqual( error.code, 1, 'expected exit code' ); - } - // Pseudorandom numbers have already been written to `stdout` by the time the error is encountered... - t.strictEqual( stdout.toString().length > 0, true, 'prints to `stdout`' ); - t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); - t.end(); - } -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index bc53c64..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,845 +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 Uint32Array = require( '@stdlib/array-uint32' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var RandomStream = 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.strictEqual( typeof createStream, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a factory function (options)', function test( t ) { - var createStream = factory( {} ); - t.strictEqual( typeof createStream, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a factory function (parameters)', function test( t ) { - var createStream = factory( 2.0, 5.0, 4.0 ); - t.strictEqual( typeof createStream, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a factory function (parameters + options)', function test( t ) { - var createStream = factory( 2.0, 5.0, 4.0, {} ); - t.strictEqual( typeof createStream, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '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() { - var createStream = factory(); - createStream( value, 5.0, 4.0 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if minimum support `a` is not a number primitive (parameters)', function test( t ) { - var values; - var i; - - values = [ - '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() { - var createStream = factory( value, 5.0, 4.0 ); - createStream(); - }; - } -}); - -tape( 'the function returns a function which throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '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() { - var createStream = factory(); - createStream( 2.0, value, 4.0 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if maximum support `b` is not a number primitive (parameters)', function test( t ) { - var values; - var i; - - values = [ - '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() { - var createStream = factory( 2.0, value, 4.0 ); - createStream(); - }; - } -}); - -tape( 'the function returns a function which throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '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() { - var createStream = factory(); - createStream( 2.0, 5.0, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if mode `c` is not a number primitive (parameters)', function test( t ) { - var values; - var i; - - values = [ - '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() { - var createStream = factory( 2.0, 5.0, value ); - createStream(); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - var createStream = factory( arr[0], arr[1], arr[2] ); - 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, - true, - false, - void 0, - null, - NaN, - function noop() {}, - [] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - function badValue( value ) { - return function badValue() { - var createStream = factory( value ); - createStream( 2.0, 5.0, 4.0 ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an options argument which is not an object (parameters)', 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 type error when provided '+values[i] ); - } - t.end(); - function badValue( value ) { - return function badValue() { - var createStream = factory( 2.0, 5.0, 4.0, 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( 2.0, 5.0, 4.0 ); - }; - } -}); - -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( 2.0, 5.0, 4.0, { - 'iter': value - }); - createStream(); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function returns a function which throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - 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({ - 'prng': value - }); - createStream( 2.0, 5.0, 4.0 ); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function returns a function which throws an error (parameters)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - 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( 2.0, 5.0, 4.0, { - 'prng': value - }); - createStream(); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function returns a function which 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() { - var createStream = factory({ - 'copy': value - }); - createStream( 2.0, 5.0, 4.0 ); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, the function returns a function which throws an error (parameters)', 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() { - var createStream = factory( 2.0, 5.0, 4.0, { - 'copy': value - }); - createStream(); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function returns a function which throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - 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({ - 'seed': value - }); - createStream( 2.0, 5.0, 4.0 ); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function returns a function which throws an error (parameters)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - 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( 2.0, 5.0, 4.0, { - 'seed': value - }); - createStream(); - }; - } -}); - -tape( 'the function returns a function which throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory({ - 'seed': value - }); - createStream( 2.0, 5.0, 4.0 ); - }; - } -}); - -tape( 'the function returns a function which throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer (parameters)', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory( 2.0, 5.0, 4.0, { - 'seed': value - }); - createStream(); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, 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({ - 'state': value - }); - createStream( 2.0, 5.0, 4.0 ); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, 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( 2.0, 5.0, 4.0, { - 'state': value - }); - createStream(); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function returns a function which throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory({ - 'state': value - }); - createStream( 2.0, 5.0, 4.0 ); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function returns a function which throws an error (parameters)', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var createStream = factory( 2.0, 5.0, 4.0, { - 'state': 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( 2.0, 5.0, 4.0 ); - }; - } -}); - -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( 2.0, 5.0, 4.0, { - '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.strictEqual( createStream( 2.0, 5.0, 4.0 ) instanceof RandomStream, true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a factory function which creates stream instances (options)', function test( t ) { - var createStream; - var i; - - createStream = factory( {} ); - - for ( i = 0; i < 10; i++ ) { - t.strictEqual( createStream( 2.0, 5.0, 4.0 ) instanceof RandomStream, true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a factory function which creates stream instances (parameters)', function test( t ) { - var createStream; - var i; - - createStream = factory( 2.0, 5.0, 4.0 ); - - for ( i = 0; i < 10; i++ ) { - t.strictEqual( createStream() instanceof RandomStream, true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a factory function which creates stream instances (parameters + options)', function test( t ) { - var createStream; - var i; - - createStream = factory( 2.0, 5.0, 4.0, {} ); - - for ( i = 0; i < 10; i++ ) { - t.strictEqual( createStream() instanceof RandomStream, true, 'returns expected value' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3648025..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 randomStream = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof randomStream, '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.strictEqual( typeof randomStream.objectMode, 'function', 'has method' ); - t.end(); -}); - -tape( 'attached to main export is a method to create a stream factory', function test( t ) { - t.strictEqual( typeof randomStream.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 916d161..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1233 +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 now = require( '@stdlib/time-now' ); -var triangular = require( '@stdlib/random-base-triangular' ).factory; -var isBuffer = require( '@stdlib/assert-is-buffer' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var minstd = require( '@stdlib/random-base-minstd' ); -var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -var randomStream = require( './../lib/main.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof randomStream, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '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() { - randomStream( value, 5.0, 4.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '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() { - randomStream( 2.0, 5.0, value ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '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() { - randomStream( 2.0, 5.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - randomStream( arr[0], arr[1], arr[2] ); - }; - } -}); - -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() { - randomStream( 2.0, 5.0, 4.0, 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() { - randomStream( 2.0, 5.0, 4.0, { - 'iter': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - 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() { - randomStream( 2.0, 5.0, 4.0, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, 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() { - randomStream( 2.0, 5.0, 4.0, { - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - 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() { - randomStream( 2.0, 5.0, 4.0, { - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - randomStream( 2.0, 5.0, 4.0, { - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, 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() { - randomStream( 2.0, 5.0, 4.0, { - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - randomStream( 2.0, 5.0, 4.0, { - 'state': 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() { - randomStream( 2.0, 5.0, 4.0, { - 'objectMode': value - }); - }; - } -}); - -tape( 'the function is a constructor which returns a readable stream', function test( t ) { - var RandomStream = randomStream; - var s; - - s = new RandomStream( 2.0, 5.0, 4.0 ); - t.strictEqual( s instanceof Readable, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor does not require the `new` operator', function test( t ) { - var RandomStream = randomStream; - var s; - - s = randomStream( 2.0, 5.0, 4.0 ); - t.strictEqual( s instanceof RandomStream, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the constructor returns a readable stream (no new)', function test( t ) { - var s = randomStream( 2.0, 5.0, 4.0 ); - t.strictEqual( 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 = randomStream( 2.0, 5.0, 4.0 ); - - t.strictEqual( 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 = randomStream( 2.0, 5.0, 4.0 ); - - t.strictEqual( 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 = randomStream( 2.0, 5.0, 4.0 ); - - s.on( 'error', onError ); - s.on( 'close', onClose ); - - // If the stream is closed twice, the test will error... - s.destroy(); - s.destroy(); - - function onClose() { - t.ok( true, 'stream closes' ); - t.end(); - } - function onError( err ) { - t.ok( false, err.message ); - } -}); - -tape( 'attached to the returned stream is the underlying PRNG', function test( t ) { - var s = randomStream( 2.0, 5.0, 4.0 ); - - t.strictEqual( typeof s.PRNG, 'function', 'has property' ); - - s = randomStream( 2.0, 5.0, 4.0, { - 'prng': minstd.normalized - }); - t.strictEqual( s.PRNG, minstd.normalized, 'has property' ); - - t.end(); -}); - -tape( 'attached to the returned stream is the generator seed', function test( t ) { - var s = randomStream( 2.0, 5.0, 4.0, { - 'seed': 12345 - }); - - t.strictEqual( isUint32Array( s.seed ), true, 'has property' ); - t.strictEqual( s.seed[ 0 ], 12345, 'equal to provided seed' ); - - s = randomStream( 2.0, 5.0, 4.0, { - 'seed': 12345, - 'prng': minstd.normalized - }); - t.strictEqual( s.seed, null, 'equal to `null`' ); - - t.end(); -}); - -tape( 'attached to the returned stream is the generator seed (array seed)', function test( t ) { - var actual; - var seed; - var s; - var i; - - seed = [ 1234, 5678 ]; - s = randomStream( 2.0, 5.0, 4.0, { - 'seed': seed - }); - - actual = s.seed; - t.strictEqual( isUint32Array( actual ), true, 'has property' ); - for ( i = 0; i < seed.length; i++ ) { - t.strictEqual( actual[ i ], seed[ i ], 'returns expected value for word '+i ); - } - - t.end(); -}); - -tape( 'attached to the returned stream is the generator seed length', function test( t ) { - var s = randomStream( 2.0, 5.0, 4.0 ); - - t.strictEqual( typeof s.seedLength, 'number', 'has property' ); - - s = randomStream( 2.0, 5.0, 4.0, { - 'prng': minstd.normalized - }); - t.strictEqual( s.seedLength, null, 'equal to `null`' ); - - t.end(); -}); - -tape( 'attached to the returned stream is the generator state', function test( t ) { - var s = randomStream( 2.0, 5.0, 4.0 ); - - t.strictEqual( isUint32Array( s.state ), true, 'has property' ); - - s = randomStream( 2.0, 5.0, 4.0, { - 'prng': minstd.normalized - }); - t.strictEqual( s.state, null, 'equal to `null`' ); - - t.end(); -}); - -tape( 'attached to the returned stream is the generator state length', function test( t ) { - var s = randomStream( 2.0, 5.0, 4.0 ); - - t.strictEqual( typeof s.stateLength, 'number', 'has property' ); - - s = randomStream( 2.0, 5.0, 4.0, { - 'prng': minstd.normalized - }); - t.strictEqual( s.stateLength, null, 'equal to `null`' ); - - t.end(); -}); - -tape( 'attached to the returned stream is the generator state size', function test( t ) { - var s = randomStream( 2.0, 5.0, 4.0 ); - - t.strictEqual( typeof s.byteLength, 'number', 'has property' ); - - s = randomStream( 2.0, 5.0, 4.0, { - 'prng': minstd.normalized - }); - t.strictEqual( s.byteLength, null, 'equal to `null`' ); - - t.end(); -}); - -tape( 'the constructor returns a stream for generating pseudorandom numbers from a triangular distribution', function test( t ) { - var iStream; - var result; - var rand; - var opts; - var s; - - // Note: we assume that the underlying generator is the following PRNG... - rand = triangular( 2.0, 5.0, 4.0, { - 'seed': 12345 - }); - - opts = { - 'seed': 12345, - 'iter': 10, - 'sep': '\n' - }; - s = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - result = ''; - s.pipe( iStream ); - - function inspect( chunk ) { - t.strictEqual( isBuffer( chunk ), true, 'returns expected value' ); - result += chunk.toString(); - } - - function onEnd() { - var i; - - t.pass( 'stream ended' ); - - result = result.split( '\n' ); - t.strictEqual( result.length, 10, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - t.strictEqual( parseFloat( result[ i ] ), rand(), 'returns expected value. i: ' + i + '.' ); - } - t.end(); - } -}); - -tape( 'the constructor returns a stream for generating pseudorandom numbers from a triangular distribution (object mode)', function test( t ) { - var iStream; - var count; - var rand; - var opts; - var s; - - // Note: we assume that the underlying generator is the following PRNG... - rand = triangular( 2.0, 5.0, 4.0, { - 'seed': 12345 - }); - - opts = { - 'seed': 12345, - 'objectMode': true - }; - s = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'close', onClose ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - count = 0; - s.pipe( iStream ); - - function inspect( v ) { - count += 1; - t.strictEqual( rand(), v, '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 = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - s.pipe( iStream ); - - function inspect( v ) { - count += 1; - t.strictEqual( typeof v, 'number', 'returns expected value' ); - } - - function onEnd() { - t.strictEqual( count === niter, true, 'performs expected number of iterations' ); - t.end(); - } -}); - -tape( 'by default, the constructor generates newline-delimited pseudorandom numbers', function test( t ) { - var iStream; - var result; - var opts; - var s; - - opts = { - 'iter': 10 - }; - s = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - result = ''; - s.pipe( iStream ); - - function inspect( chunk ) { - result += chunk.toString(); - } - - function onEnd() { - var v; - var i; - - result = result.split( '\n' ); - t.strictEqual( result.length, opts.iter, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - v = parseFloat( result[ i ] ); - t.strictEqual( typeof v, 'number', 'returns expected value' ); - t.strictEqual( isnan( v ), false, 'is not NaN' ); - } - 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 = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'end', onEnd ); - - iStream = inspectStream( inspect ); - - result = ''; - s.pipe( iStream ); - - function inspect( chunk ) { - result += chunk.toString(); - } - - function onEnd() { - var v; - var i; - - result = result.split( opts.sep ); - t.strictEqual( result.length, opts.iter, 'has expected length' ); - for ( i = 0; i < result.length; i++ ) { - v = parseFloat( result[ i ] ); - t.strictEqual( typeof v, 'number', 'returns expected value' ); - t.strictEqual( isnan( v ), false, 'is not NaN' ); - } - t.end(); - } -}); - -tape( 'the constructor supports returning a seeded readable stream', function test( t ) { - var iStream; - var opts; - var seed; - var arr; - var s1; - var s2; - var i; - - seed = now(); - - opts = { - 'objectMode': true, - 'seed': seed, - 'iter': 10 - }; - s1 = randomStream( 2.0, 5.0, 4.0, opts ); - s1.on( 'end', onEnd1 ); - - s2 = randomStream( 2.0, 5.0, 4.0, opts ); - s2.on( 'end', onEnd2 ); - - t.notEqual( s1, s2, 'separate streams' ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect1 ); - - arr = []; - i = 0; - - s1.pipe( iStream ); - - function inspect1( v ) { - arr.push( v ); - } - - function onEnd1() { - var iStream; - var opts; - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect2 ); - - s2.pipe( iStream ); - } - - function inspect2( v ) { - t.strictEqual( v, arr[ i ], 'returns expected value' ); - i += 1; - } - - function onEnd2() { - t.end(); - } -}); - -tape( 'the constructor supports specifying the underlying PRNG', function test( t ) { - var iStream; - var opts; - var s; - - opts = { - 'prng': minstd.normalized, - 'objectMode': true, - 'iter': 10 - }; - s = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - s.pipe( iStream ); - - function inspect( v ) { - t.strictEqual( typeof v, 'number', 'returns expected value' ); - } - - function onEnd() { - t.end(); - } -}); - -tape( 'the constructor supports providing a seeded underlying PRNG', function test( t ) { - var iStream1; - var iStream2; - var randu; - var seed; - var opts; - var FLG; - var s1; - var s2; - var r1; - var r2; - - seed = now(); - - randu = minstd.factory({ - 'seed': seed - }); - opts = { - 'prng': randu.normalized, - 'objectMode': true, - 'iter': 10 - }; - s1 = randomStream( 2.0, 5.0, 4.0, opts ); - s1.on( 'end', onEnd ); - - randu = minstd.factory({ - 'seed': seed - }); - opts = { - 'prng': randu.normalized, - 'objectMode': true, - 'iter': 10 - }; - s2 = randomStream( 2.0, 5.0, 4.0, opts ); - s2.on( 'end', onEnd ); - - t.notEqual( s1, s2, 'separate streams' ); - - opts = { - 'objectMode': true - }; - iStream1 = inspectStream( opts, inspect1 ); - iStream2 = inspectStream( opts, inspect2 ); - - r1 = []; - r2 = []; - - s1.pipe( iStream1 ); - s2.pipe( iStream2 ); - - function inspect1( v ) { - r1.push( v ); - } - - function inspect2( v ) { - r2.push( v ); - } - - function onEnd() { - if ( FLG ) { - t.deepEqual( r1, r2, 'streams expected values' ); - return t.end(); - } - FLG = true; - } -}); - -tape( 'the constructor supports specifying the underlying generator state', function test( t ) { - var iStream; - var state; - var count; - var opts; - var arr; - var s; - - opts = { - 'objectMode': true, - 'iter': 10, - 'siter': 5 - }; - s = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'state', onState ); - s.on( 'end', onEnd1 ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect1 ); - - count = 0; - arr = []; - - // Move to a future state... - s.pipe( iStream ); - - function onState( s ) { - // Only capture the first emitted state... - if ( !state ) { - state = s; - } - } - - function inspect1( v ) { - count += 1; - if ( count > 5 ) { - arr.push( v ); - } - } - - function onEnd1() { - var iStream; - var opts; - var s; - - t.pass( 'first stream ended' ); - - // Create another stream using the captured state: - opts = { - 'objectMode': true, - 'iter': 5, - 'state': state - }; - s = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'end', onEnd2 ); - - t.deepEqual( state, s.state, 'same state' ); - - // Create a new inspect stream: - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect2 ); - - // Replay previously generated values... - count = 0; - s.pipe( iStream ); - } - - function inspect2( v ) { - count += 1; - t.strictEqual( v, arr[ count-1 ], 'returns expected value. i: '+(count-1)+'.' ); - } - - function onEnd2() { - t.pass( 'second stream ended' ); - t.end(); - } -}); - -tape( 'the constructor supports specifying a shared underlying generator state', function test( t ) { - var iStream; - var shared; - var state; - var count; - var opts; - var arr; - var s; - - opts = { - 'objectMode': true, - 'iter': 10, - 'siter': 4 - }; - s = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'state', onState ); - s.on( 'end', onEnd1 ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect1 ); - - count = 0; - arr = []; - - // Move to a future state... - s.pipe( iStream ); - - function onState( s ) { - // Only capture the first emitted state... - if ( !state ) { - state = s; - - // Create a copy of the state (to prevent mutation) which will be shared by more than one PRNG: - shared = new Uint32Array( state ); - } - } - - function inspect1( v ) { - count += 1; - if ( count > 4 ) { - arr.push( v ); - } - } - - function onEnd1() { - var iStream; - var opts; - var s; - - t.pass( 'first stream ended' ); - - // Create another stream using the captured state: - opts = { - 'objectMode': true, - 'iter': 3, - 'state': shared, - 'copy': false - }; - s = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'end', onEnd2 ); - - t.deepEqual( state, s.state, 'same state' ); - - // Create a new inspect stream: - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect2 ); - - // Replay previously generated values... - count = 0; - s.pipe( iStream ); - } - - function inspect2( v ) { - count += 1; - t.strictEqual( v, arr[ count-1 ], 'returns expected value. i: '+(count-1)+'.' ); - } - - function onEnd2() { - var iStream; - var opts; - var s; - - t.pass( 'second stream ended' ); - - // Create another stream using the captured state: - opts = { - 'objectMode': true, - 'iter': 3, - 'state': shared, - 'copy': false - }; - s = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'end', onEnd3 ); - - t.notDeepEqual( state, s.state, 'different state' ); - - // Create a new inspect stream: - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect3 ); - - // Continue replaying previously generated values... - s.pipe( iStream ); - } - - function inspect3( v ) { - count += 1; - t.strictEqual( v, arr[ count-1 ], 'returns expected value. i: '+(count-1)+'.' ); - } - - function onEnd3() { - t.pass( 'third stream ended' ); - t.end(); - } -}); - -tape( 'the returned stream supports setting the underlying generator state', function test( t ) { - var iStream; - var state; - var rand; - var opts; - var arr; - var s; - var i; - - rand = triangular( 2.0, 5.0, 4.0 ); - - // Move to a future state... - for ( i = 0; i < 5; i++ ) { - rand(); - } - // Capture the current state: - state = rand.state; - - // Move to a future state... - arr = []; - for ( i = 0; i < 5; i++ ) { - arr.push( rand() ); - } - // Create a random stream: - opts = { - 'objectMode': true, - 'iter': 5 - }; - s = randomStream( 2.0, 5.0, 4.0, opts ); - s.on( 'end', onEnd ); - - // Set the PRNG state: - s.state = state; - - // Create a new inspect stream: - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - // Replay previously generated values: - i = 0; - s.pipe( iStream ); - - function inspect( v ) { - t.strictEqual( v, arr[ i ], 'returns expected value. i: ' + i + '.' ); - i += 1; - } - - function onEnd() { - t.end(); - } -}); diff --git a/test/test.object_mode.js b/test/test.object_mode.js deleted file mode 100644 index 752fc8d..0000000 --- a/test/test.object_mode.js +++ /dev/null @@ -1,471 +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 Uint32Array = require( '@stdlib/array-uint32' ); -var UINT32_MAX = require( '@stdlib/constants-uint32-max' ); -var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); -var RandomStream = 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 minimum support `a` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '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() { - objectMode( value, 5.0, 4.0 ); - }; - } -}); - -tape( 'the function throws an error if maximum support `b` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '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() { - objectMode( 2.0, value, 4.0 ); - }; - } -}); - -tape( 'the function throws an error if mode `c` is not a number primitive', function test( t ) { - var values; - var i; - - values = [ - '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() { - objectMode( 2.0, 5.0, value ); - }; - } -}); - -tape( 'the function throws an error if the condition `a <= c <= b` is not satisfied', function test( t ) { - var values; - var i; - - values = [ - [ 0.0, 1.0, 2.0 ], - [ -2.0, -4.0, -3.0 ], - [ 2.0, 1.0, 1.5 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( arr ) { - return function badValue() { - objectMode( arr[0], arr[1], arr[2] ); - }; - } -}); - -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, - true, - false, - void 0, - null, - NaN, - 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( 2.0, 5.0, 4.0, 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( 2.0, 5.0, 4.0, { - 'iter': value - }); - }; - } -}); - -tape( 'if provided a `prng` option which is not a function, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - 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( 2.0, 5.0, 4.0, { - 'prng': value - }); - }; - } -}); - -tape( 'if provided a `copy` option which is not a boolean, 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() { - objectMode( 2.0, 5.0, 4.0, { - 'copy': value - }); - }; - } -}); - -tape( 'if provided a `seed` which is not a positive integer or a non-empty array-like object, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 0.0, - -5.0, - 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( 2.0, 5.0, 4.0, { - 'seed': value - }); - }; - } -}); - -tape( 'the function throws a range error if provided a `seed` which is an integer greater than the maximum unsigned 32-bit integer', function test( t ) { - var values; - var i; - - values = [ - UINT32_MAX + 1, - UINT32_MAX + 2, - UINT32_MAX + 3 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws a range error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - objectMode( 2.0, 5.0, 4.0, { - 'seed': value - }); - }; - } -}); - -tape( 'if provided a `state` option which is not a Uint32Array, 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( 2.0, 5.0, 4.0, { - 'state': value - }); - }; - } -}); - -tape( 'if provided an invalid `state` option, the function throws an error', function test( t ) { - var values; - var i; - - values = [ - new Uint32Array( 0 ), - new Uint32Array( 10 ), - new Uint32Array( 100 ) - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - objectMode( 2.0, 5.0, 4.0, { - 'state': 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( 2.0, 5.0, 4.0, { - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a stream instance', function test( t ) { - var s = objectMode( 2.0, 5.0, 4.0 ); - t.strictEqual( s instanceof RandomStream, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a stream instance (options)', function test( t ) { - var s = objectMode( 2.0, 5.0, 4.0, {} ); - t.strictEqual( s instanceof RandomStream, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a stream which streams numbers', function test( t ) { - var iStream; - var opts; - var s; - - opts = { - 'iter': 10 - }; - s = objectMode( 2.0, 5.0, 4.0, opts ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - s.pipe( iStream ); - - function inspect( v ) { - t.strictEqual( typeof v, 'number', '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( 2.0, 5.0, 4.0, opts ); - s.on( 'end', onEnd ); - - opts = { - 'objectMode': true - }; - iStream = inspectStream( opts, inspect ); - - s.pipe( iStream ); - - function inspect( v ) { - t.strictEqual( typeof v, 'number', 'returns expected value' ); - } - - function onEnd() { - t.end(); - } -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index 99bef92..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,330 +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 rand = require( '@stdlib/random-base-triangular' ); -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.strictEqual( 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.strictEqual( 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.strictEqual( 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.strictEqual( 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.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an `siter` option which is not a positive 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( {}, { - 'siter': values[ i ] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function sets the `iter` option', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'iter': 10 - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'sets option values' ); - t.end(); -}); - -tape( 'the function sets the `prng` option', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'prng': rand.PRNG - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'sets option values' ); - t.end(); -}); - -tape( 'the function sets the `seed` option', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'seed': rand.seed - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'sets option values' ); - t.end(); -}); - -tape( 'the function sets the `state` option', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'state': rand.state - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'sets option values' ); - t.end(); -}); - -tape( 'the function sets the `copy` option', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'copy': true - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'sets option values' ); - 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', - 'siter': 10, - 'iter': 100, - 'state': rand.state, - 'seed': rand.seed, - 'prng': rand.PRNG, - 'copy': true - }; - opts = {}; - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'sets option values' ); - - options = { - 'objectMode': false, - 'highWaterMark': 64, - 'encoding': 'utf8', - 'sep': '\t', - 'siter': 10, - 'iter': 100, - 'state': rand.state, - 'seed': rand.seed, - 'prng': rand.PRNG, - 'copy': false - }; - opts = {}; - err = validate( opts, options ); - - t.strictEqual( err, null, 'returns expected value' ); - 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.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'does not set any option values' ); - t.end(); -});