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 8b62833..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-15T02:43:10.800Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 2d6aaee..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/array/filled-by) 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 f988046..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/array/filled-by) 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 b2c1f9c..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: '42 6 * * 4' - - # 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 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send 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 + + ```
@@ -278,7 +269,7 @@ for ( i = 0; i < dt.length; i++ ) { ## 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]. @@ -347,13 +338,13 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [mdn-arraybuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer -[@stdlib/array/dtypes]: https://github.com/stdlib-js/array-dtypes +[@stdlib/array/dtypes]: https://github.com/stdlib-js/array-dtypes/tree/esm -[@stdlib/array/filled]: https://github.com/stdlib-js/array-filled +[@stdlib/array/filled]: https://github.com/stdlib-js/array-filled/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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 6fba606..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,342 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 bench = require( '@stdlib/bench-harness' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarrayBy = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 0.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=float64', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 0.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'float64', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=float32', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 0.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'float32', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=bool', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( true ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'bool', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=complex128', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( new Complex128( 3.0, 5.0 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'complex128', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=complex64', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( new Complex64( 3.0, 5.0 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'complex64', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=int32', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'int32', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=uint32', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'uint32', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=int16', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'int16', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=uint16', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'uint16', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=int8', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'int8', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=uint8', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'uint8', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=uint8c', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'uint8c', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s:dtype=generic', pkg ), function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarrayBy( 0, 'generic', clbk ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isArray( arr ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.bool.js b/benchmark/benchmark.length.bool.js deleted file mode 100644 index 52b3237..0000000 --- a/benchmark/benchmark.length.bool.js +++ /dev/null @@ -1,98 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( true ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'bool', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=bool,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 63c0843..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,99 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( new Complex128( 3.0, 5.0 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'complex128', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=complex128,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 186f811..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,99 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( new Complex64( 3.0, 5.0 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'complex64', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArrayLike( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=complex64,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 5ba3130..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 1.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'float32', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=float32,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 4a2be6c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 1.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'float64', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=float64,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.generic.js b/benchmark/benchmark.length.generic.js deleted file mode 100644 index 6522748..0000000 --- a/benchmark/benchmark.length.generic.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isArray = require( '@stdlib/assert-is-array' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 1.0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'generic', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=generic,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9ac94e9..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'int16', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=int16,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index a5ce4d0..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'int32', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=int32,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 6104616..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'int8', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=int8,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 3108633..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'uint16', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=uint16,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 602e232..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'uint32', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=uint32,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8664da3..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'uint8', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=uint8,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 76645b9..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var filledarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var clbk; - var arr; - var i; - - clbk = constantFunction( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = filledarray( len, 'uint8c', clbk ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( format( '%s:dtype=uint8c,len=%d', pkg, len ), f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index c138144..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/filled-by" -%% click B href "https://github.com/stdlib-js/array-filled-by/tree/main" -%% click C href "https://github.com/stdlib-js/array-filled-by/tree/production" -%% click D href "https://github.com/stdlib-js/array-filled-by/tree/esm" -%% click E href "https://github.com/stdlib-js/array-filled-by/tree/deno" -%% click F href "https://github.com/stdlib-js/array-filled-by/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/filled-by -[production-url]: https://github.com/stdlib-js/array-filled-by/tree/production -[deno-url]: https://github.com/stdlib-js/array-filled-by/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-filled-by/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-filled-by/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-filled-by/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-filled-by/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-filled-by/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 188fc9b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import filledarrayBy from '../docs/types/index'; -export = filledarrayBy; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4049a13..0000000 --- a/dist/index.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict";var k=function(n,e){return function(){try{return e||n((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}}};var b=k(function(R,c){"use strict";var p=require("@stdlib/assert-is-string").isPrimitive,d=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,q=require("@stdlib/array-base-assert-is-complex-floating-point-data-type"),M=require("@stdlib/array-base-assert-is-boolean-data-type"),f=require("@stdlib/assert-is-collection"),g=require("@stdlib/assert-is-arraybuffer"),m=require("@stdlib/assert-is-object"),u=require("@stdlib/assert-is-function"),v=require("@stdlib/array-ctors"),j=require("@stdlib/blas-ext-base-gfill-by"),V=require("@stdlib/array-base-filled-by"),A=require("@stdlib/assert-has-iterator-symbol-support"),y=require("@stdlib/symbol-iterator"),B=require("@stdlib/iter-length"),S=require("@stdlib/array-defaults"),o=require("@stdlib/string-format"),w=A(),h=S.get("dtypes.default");function x(n,e,t){var a,i,l;for(a=[],i=-1;l=n.next(),!l.done;)i+=1,a.push(e.call(t,i));return a}function C(n,e,t){var a;for(a=0;a1)throw new TypeError("invalid arguments. Must provide a length, typed array, array-like object, or an iterable.");if(i=v(t),i===null)throw new TypeError(o("invalid argument. Must provide a recognized data type. Value: `%s`.",t));return new i(0)}if(e<2)throw new TypeError("invalid arguments. Must provide a length, typed array, array-like object, or an iterable.");if(e-=1,u(arguments[e]))if(u(arguments[e-1])){if(n=arguments[e],e-=1,a=arguments[e],e===0)throw new TypeError("invalid arguments. Must provide a length, typed array, array-like object, or an iterable.")}else a=arguments[e];else if(e>=2){if(n=arguments[e],e-=1,a=arguments[e],!u(a))throw new TypeError(o("invalid argument. Callback argument must be a function. Value: `%s`.",a))}else throw new TypeError("invalid arguments. Must provide a length, typed array, array-like object, or an iterable.");if(e-=1,e>=0&&p(arguments[e])?(t=arguments[e],e-=1):t=h,i=v(t),i===null)throw new TypeError(o("invalid argument. Must provide a recognized data type. Value: `%s`.",t));if(t==="generic"){if(r=arguments[0],e===0){if(d(r)?s=r:f(r)&&(s=r.length),s!==void 0)return V(s,a,n);if(g(r))throw new Error("invalid arguments. Creating a generic array from an ArrayBuffer is not supported.");if(m(r)){if(w===!1)throw new TypeError(o("invalid argument. Environment lacks Symbol.iterator support. Must provide a length, typed array, or array-like object. Value: `%s`.",r));if(!u(r[y]))throw new TypeError(o("invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.",r));if(r=r[y](),!u(r.next))throw new TypeError(o("invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.",r));return x(r,a,n)}throw new TypeError(o("invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.",r))}else if(g(r))throw new Error("invalid arguments. Creating a generic array from an ArrayBuffer is not supported.");throw new TypeError(o("invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.",r))}if(e===0)if(r=arguments[0],f(r))l=new i(r.length);else if(g(r))l=new i(r);else if(d(r))l=new i(r);else if(m(r)){if(w===!1)throw new TypeError(o("invalid argument. Environment lacks Symbol.iterator support. Must provide a length, typed array, or array-like object. Value: `%s`.",r));if(!u(r[y]))throw new TypeError(o("invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.",r));if(r=r[y](),!u(r.next))throw new TypeError(o("invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.",r));l=new i(B(r))}else throw new TypeError(o("invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.",r));else e===1?l=new i(arguments[0],arguments[1]):l=new i(arguments[0],arguments[1],arguments[2]);return l.length>0&&(q(t)||M(t)?C(l,a,n):j(l.length,l,1,E)),l;function E(D,T){return a.call(n,T)}}c.exports=I});var O=b();module.exports=O; -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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. -*/ -/** -* @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. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 8a898ec..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' );\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ctors = require( '@stdlib/array-ctors' );\nvar gfillBy = require( '@stdlib/blas-ext-base-gfill-by' );\nvar filledArray = require( '@stdlib/array-base-filled-by' );\nvar hasIteratorSymbolSupport = require( '@stdlib/assert-has-iterator-symbol-support' );\nvar ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' );\nvar iterLength = require( '@stdlib/iter-length' );\nvar defaults = require( '@stdlib/array-defaults' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport();\nvar DEFAULT_DTYPE = defaults.get( 'dtypes.default' );\n\n\n// FUNCTIONS //\n\n/**\n* Creates a filled \"generic\" array from an iterator.\n*\n* @private\n* @param {Iterable} it - iterator\n* @param {Callback} clbk - callback function\n* @param {*} thisArg - callback function execution context\n* @returns {Array} filled array\n*/\nfunction filledArrayIterator( it, clbk, thisArg ) {\n\tvar arr;\n\tvar i;\n\tvar v;\n\n\tarr = [];\n\ti = -1;\n\twhile ( true ) {\n\t\tv = it.next();\n\t\tif ( v.done ) {\n\t\t\tbreak;\n\t\t}\n\t\ti += 1;\n\t\tarr.push( clbk.call( thisArg, i ) );\n\t}\n\treturn arr;\n}\n\n/**\n* Fills an array exposing accessors for getting and setting array elements.\n*\n* @private\n* @param {Collection} arr - input array\n* @param {Callback} clbk - callback function\n* @param {*} thisArg - callback function execution context\n* @returns {Collection} input array\n*/\nfunction filledAccessors( arr, clbk, thisArg ) {\n\tvar i;\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tarr.set( clbk.call( thisArg, i ), i );\n\t}\n\treturn arr;\n}\n\n\n// MAIN //\n\n/**\n* Creates a filled array according to a provided callback function.\n*\n* @param {(NonNegativeInteger|TypedArray|ArrayLikeObject|ArrayBuffer|Iterable)} [arg] - a length, typed array, array-like object, buffer, or iterable\n* @param {NonNegativeInteger} [byteOffset=0] - byte offset\n* @param {NonNegativeInteger} [length] - view length\n* @param {string} [dtype=\"float64\"] - data type\n* @param {Callback} [clbk] - callback to invoke\n* @param {*} [thisArg] - callback execution context\n* @throws {TypeError} must provide a recognized data type\n* @throws {TypeError} must provide a length, typed array, array-like object, buffer, or iterable\n* @throws {TypeError} callback argument must be a function.\n* @throws {Error} creating a generic array from an `ArrayBuffer` is not supported\n* @returns {(TypedArray|Array)} array or typed array\n*\n* @example\n* var arr = filledarrayBy();\n* // returns \n*\n* @example\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( 2, clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( 2, 'float32', clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( 2, 'generic', clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( [ 0.5, 0.5 ], clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* function clbk() {\n* return 1;\n* }\n*\n* var arr = filledarrayBy( [ 5, -3 ], 'int32', clbk );\n* // returns [ 1, 1 ]\n*\n* @example\n* function clbk1() {\n* return 10;\n* }\n*\n* function clbk2() {\n* return 1.0;\n* }\n*\n* var arr1 = filledarrayBy( [ 5, 3 ], 'int32', clbk1 );\n* var arr2 = filledarrayBy( arr1, clbk2 );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* function clbk1() {\n* return 1.0;\n* }\n*\n* function clbk2() {\n* return 2;\n* }\n*\n* var arr1 = filledarrayBy( [ 5, 3 ], 'int32', clbk1 );\n* var arr2 = filledarrayBy( arr1, 'uint32', clbk2 );\n* // returns [ 2, 2 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, 'float32', clbk );\n* // returns [ 1.0, 1.0, 1.0, 1.0 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, 8, clbk );\n* // returns [ 1.0 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, 8, 'float32', clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 32 );\n* var arr = filledarrayBy( buf, 8, 2, clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n*\n* function clbk() {\n* return 1;\n* }\n*\n* var buf = new ArrayBuffer( 32 );\n* var arr = filledarrayBy( buf, 8, 2, 'int32', clbk );\n* // returns [ 1, 1 ]\n*/\nfunction filledarrayBy() {\n\tvar thisArg;\n\tvar nargs;\n\tvar dtype;\n\tvar clbk;\n\tvar ctor;\n\tvar arr;\n\tvar len;\n\tvar arg;\n\n\tnargs = arguments.length;\n\n\t// If we weren't provided any arguments, return an empty array...\n\tif ( nargs === 0 ) {\n\t\tctor = ctors( DEFAULT_DTYPE );\n\t\treturn new ctor( 0 );\n\t}\n\t// Check if we were provided a dtype as the first argument...\n\tdtype = arguments[ 0 ];\n\tif ( isString( dtype ) ) {\n\t\t// Invoking this function with arguments `f( dtype, clbk[, thisArg] )` is not allowed (otherwise, we'd need to also allow `f( clbk[, thisArg] )`)...\n\t\tif ( nargs > 1 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' );\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\t// Return an empty array having the specified dtype:\n\t\treturn new ctor( 0 );\n\t}\n\t// For all other supported invocations, we need at least two arguments...\n\tif ( nargs < 2 ) {\n\t\tthrow new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' );\n\t}\n\t// At this point, we need to do some argument juggling...\n\tnargs -= 1; // henceforth, the number of available arguments is `nargs+1`\n\n\t// Determine whether the last argument is a callback or \"this\" context...\n\tif ( isFunction( arguments[ nargs ] ) ) {\n\t\t// If the last argument is a function, we need to check the next-to-last argument, and, if the next-to-last argument is a function, assume that the next-to-last argument is the callback and the last argument is a \"this\" context...\n\t\tif ( isFunction( arguments[ nargs-1 ] ) ) {\n\t\t\tthisArg = arguments[ nargs ];\n\t\t\tnargs -= 1;\n\t\t\tclbk = arguments[ nargs ];\n\n\t\t\t// Check if we were provided only a callback and a \"this\" context..\n\t\t\tif ( nargs === 0 ) {\n\t\t\t\tthrow new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' );\n\t\t\t}\n\t\t} else {\n\t\t\t// \"this\" context is left undefined...\n\t\t\tclbk = arguments[ nargs ];\n\t\t}\n\t}\n\t// If we were provided 3 or more arguments and the last argument was not a function, assume that we were provided a callback and a \"this\" context...\n\telse if ( nargs >= 2 ) {\n\t\tthisArg = arguments[ nargs ];\n\t\tnargs -= 1;\n\t\tclbk = arguments[ nargs ];\n\t\tif ( !isFunction( clbk ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) );\n\t\t}\n\t}\n\t// If we were only provided 2 arguments and the last argument was not a function, we've been provided an insufficient number of arguments...\n\telse {\n\t\tthrow new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' );\n\t}\n\t// Now that we've processed the callback arguments, let's continue working backward to see if we've been provided a `dtype` argument...\n\tnargs -= 1;\n\tif ( nargs >= 0 && isString( arguments[ nargs ] ) ) {\n\t\tdtype = arguments[ nargs ];\n\t\tnargs -= 1;\n\t} else {\n\t\tdtype = DEFAULT_DTYPE;\n\t}\n\tctor = ctors( dtype );\n\tif ( ctor === null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t}\n\t// At this point, we've resolved the output array data type, and now we can actually create the output array...\n\tif ( dtype === 'generic' ) {\n\t\targ = arguments[ 0 ];\n\t\tif ( nargs === 0 ) {\n\t\t\tif ( isNonNegativeInteger( arg ) ) {\n\t\t\t\tlen = arg;\n\t\t\t} else if ( isCollection( arg ) ) {\n\t\t\t\tlen = arg.length;\n\t\t\t}\n\t\t\tif ( len !== void 0 ) {\n\t\t\t\treturn filledArray( len, clbk, thisArg );\n\t\t\t}\n\t\t\tif ( isArrayBuffer( arg ) ) {\n\t\t\t\tthrow new Error( 'invalid arguments. Creating a generic array from an ArrayBuffer is not supported.' );\n\t\t\t}\n\t\t\tif ( isObject( arg ) ) {\n\t\t\t\tif ( HAS_ITERATOR_SYMBOL === false ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, typed array, or array-like object. Value: `%s`.', arg ) );\n\t\t\t\t}\n\t\t\t\tif ( !isFunction( arg[ ITERATOR_SYMBOL ] ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) );\n\t\t\t\t}\n\t\t\t\targ = arg[ ITERATOR_SYMBOL ]();\n\t\t\t\tif ( !isFunction( arg.next ) ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) );\n\t\t\t\t}\n\t\t\t\treturn filledArrayIterator( arg, clbk, thisArg );\n\t\t\t}\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) );\n\t\t} else if ( isArrayBuffer( arg ) ) {\n\t\t\tthrow new Error( 'invalid arguments. Creating a generic array from an ArrayBuffer is not supported.' );\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) );\n\t}\n\tif ( nargs === 0 ) { // length || array-like || ArrayBuffer || iterable\n\t\targ = arguments[ 0 ];\n\t\tif ( isCollection( arg ) ) {\n\t\t\tarr = new ctor( arg.length );\n\t\t} else if ( isArrayBuffer( arg ) ) {\n\t\t\tarr = new ctor( arg );\n\t\t} else if ( isNonNegativeInteger( arg ) ) {\n\t\t\tarr = new ctor( arg );\n\t\t} else if ( isObject( arg ) ) {\n\t\t\tif ( HAS_ITERATOR_SYMBOL === false ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, typed array, or array-like object. Value: `%s`.', arg ) );\n\t\t\t}\n\t\t\tif ( !isFunction( arg[ ITERATOR_SYMBOL ] ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) );\n\t\t\t}\n\t\t\targ = arg[ ITERATOR_SYMBOL ]();\n\t\t\tif ( !isFunction( arg.next ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) );\n\t\t\t}\n\t\t\tarr = new ctor( iterLength( arg ) );\n\t\t} else {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) );\n\t\t}\n\t} else if ( nargs === 1 ) {\n\t\tarr = new ctor( arguments[0], arguments[1] ); // (ArrayBuffer, byteOffset)\n\t} else {\n\t\tarr = new ctor( arguments[0], arguments[1], arguments[2] ); // (ArrayBuffer, byteOffset, length)\n\t}\n\tif ( arr.length > 0 ) {\n\t\tif ( isComplexDataType( dtype ) || isBooleanDataType( dtype ) ) {\n\t\t\tfilledAccessors( arr, clbk, thisArg );\n\t\t} else {\n\t\t\tgfillBy( arr.length, arr, 1, callback );\n\t\t}\n\t}\n\treturn arr;\n\n\t/**\n\t* Callback which wraps a provided callback and is invoked for each array element.\n\t*\n\t* @private\n\t* @param {*} value - element value\n\t* @param {NonNegativeInteger} aidx - array index\n\t* @param {NonNegativeInteger} sidx - strided index\n\t* @param {Collection} array - input array/collection\n\t* @returns {*} callback return value\n\t*/\n\tfunction callback( value, aidx ) {\n\t\treturn clbk.call( thisArg, aidx );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = filledarrayBy;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 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 filled array according to a provided callback function.\n*\n* @module @stdlib/array-filled-by\n*\n* @example\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* var arr = filledarrayBy();\n* // returns \n*\n* @example\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( 2, clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( 2, 'float32', clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( 2, 'generic', clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( [ 0.5, 0.5 ], clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk() {\n* return 1;\n* }\n*\n* var arr = filledarrayBy( [ 5, -3 ], 'int32', clbk );\n* // returns [ 1, 1 ]\n*\n* @example\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk1() {\n* return 10;\n* }\n*\n* function clbk2() {\n* return 1.0;\n* }\n*\n* var arr1 = filledarrayBy( [ 5, 3 ], 'int32', clbk1 );\n* var arr2 = filledarrayBy( arr1, clbk2 );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk1() {\n* return 1.0;\n* }\n*\n* function clbk2() {\n* return 2;\n* }\n*\n* var arr1 = filledarrayBy( [ 5, 3 ], 'int32', clbk1 );\n* var arr2 = filledarrayBy( arr1, 'uint32', clbk2 );\n* // returns [ 2, 2 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, 'float32', clbk );\n* // returns [ 1.0, 1.0, 1.0, 1.0 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, 8, clbk );\n* // returns [ 1.0 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, 8, 'float32', clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 32 );\n* var arr = filledarrayBy( buf, 8, 2, clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* var ArrayBuffer = require( '@stdlib/array-buffer' );\n* var filledarrayBy = require( '@stdlib/array-filled-by' );\n*\n* function clbk() {\n* return 1;\n* }\n*\n* var buf = new ArrayBuffer( 32 );\n* var arr = filledarrayBy( buf, 8, 2, 'int32', clbk );\n* // returns [ 1, 1 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,+DAAgE,EAC7FC,EAAoB,QAAS,gDAAiD,EAC9EC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,+BAAgC,EACzDC,EAAW,QAAS,0BAA2B,EAC/CC,EAAa,QAAS,4BAA6B,EACnDC,EAAQ,QAAS,qBAAsB,EACvCC,EAAU,QAAS,gCAAiC,EACpDC,EAAc,QAAS,8BAA+B,EACtDC,EAA2B,QAAS,4CAA6C,EACjFC,EAAkB,QAAS,yBAA0B,EACrDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAW,QAAS,wBAAyB,EAC7CC,EAAS,QAAS,uBAAwB,EAK1CC,EAAsBL,EAAyB,EAC/CM,EAAgBH,EAAS,IAAK,gBAAiB,EAcnD,SAASI,EAAqBC,EAAIC,EAAMC,EAAU,CACjD,IAAIC,EACA,EACAC,EAIJ,IAFAD,EAAM,CAAC,EACP,EAAI,GAEHC,EAAIJ,EAAG,KAAK,EACP,CAAAI,EAAE,MAGP,GAAK,EACLD,EAAI,KAAMF,EAAK,KAAMC,EAAS,CAAE,CAAE,EAEnC,OAAOC,CACR,CAWA,SAASE,EAAiBF,EAAKF,EAAMC,EAAU,CAC9C,IAAII,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAI,OAAQG,IAC5BH,EAAI,IAAKF,EAAK,KAAMC,EAASI,CAAE,EAAGA,CAAE,EAErC,OAAOH,CACR,CA4JA,SAASI,GAAgB,CACxB,IAAIL,EACAM,EACAC,EACAR,EACAS,EACAP,EACAQ,EACAC,EAKJ,GAHAJ,EAAQ,UAAU,OAGbA,IAAU,EACd,OAAAE,EAAOrB,EAAOS,CAAc,EACrB,IAAIY,EAAM,CAAE,EAIpB,GADAD,EAAQ,UAAW,CAAE,EAChB5B,EAAU4B,CAAM,EAAI,CAExB,GAAKD,EAAQ,EACZ,MAAM,IAAI,UAAW,2FAA4F,EAGlH,GADAE,EAAOrB,EAAOoB,CAAM,EACfC,IAAS,KACb,MAAM,IAAI,UAAWd,EAAQ,sEAAuEa,CAAM,CAAE,EAG7G,OAAO,IAAIC,EAAM,CAAE,CACpB,CAEA,GAAKF,EAAQ,EACZ,MAAM,IAAI,UAAW,2FAA4F,EAMlH,GAHAA,GAAS,EAGJpB,EAAY,UAAWoB,CAAM,CAAE,EAEnC,GAAKpB,EAAY,UAAWoB,EAAM,CAAE,CAAE,GAMrC,GALAN,EAAU,UAAWM,CAAM,EAC3BA,GAAS,EACTP,EAAO,UAAWO,CAAM,EAGnBA,IAAU,EACd,MAAM,IAAI,UAAW,2FAA4F,OAIlHP,EAAO,UAAWO,CAAM,UAIhBA,GAAS,GAIlB,GAHAN,EAAU,UAAWM,CAAM,EAC3BA,GAAS,EACTP,EAAO,UAAWO,CAAM,EACnB,CAACpB,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWL,EAAQ,uEAAwEK,CAAK,CAAE,MAK7G,OAAM,IAAI,UAAW,2FAA4F,EAWlH,GARAO,GAAS,EACJA,GAAS,GAAK3B,EAAU,UAAW2B,CAAM,CAAE,GAC/CC,EAAQ,UAAWD,CAAM,EACzBA,GAAS,GAETC,EAAQX,EAETY,EAAOrB,EAAOoB,CAAM,EACfC,IAAS,KACb,MAAM,IAAI,UAAWd,EAAQ,sEAAuEa,CAAM,CAAE,EAG7G,GAAKA,IAAU,UAAY,CAE1B,GADAG,EAAM,UAAW,CAAE,EACdJ,IAAU,EAAI,CAMlB,GALK1B,EAAsB8B,CAAI,EAC9BD,EAAMC,EACK3B,EAAc2B,CAAI,IAC7BD,EAAMC,EAAI,QAEND,IAAQ,OACZ,OAAOpB,EAAaoB,EAAKV,EAAMC,CAAQ,EAExC,GAAKhB,EAAe0B,CAAI,EACvB,MAAM,IAAI,MAAO,mFAAoF,EAEtG,GAAKzB,EAAUyB,CAAI,EAAI,CACtB,GAAKf,IAAwB,GAC5B,MAAM,IAAI,UAAWD,EAAQ,sIAAuIgB,CAAI,CAAE,EAE3K,GAAK,CAACxB,EAAYwB,EAAKnB,CAAgB,CAAE,EACxC,MAAM,IAAI,UAAWG,EAAQ,wGAAyGgB,CAAI,CAAE,EAG7I,GADAA,EAAMA,EAAKnB,CAAgB,EAAE,EACxB,CAACL,EAAYwB,EAAI,IAAK,EAC1B,MAAM,IAAI,UAAWhB,EAAQ,wGAAyGgB,CAAI,CAAE,EAE7I,OAAOb,EAAqBa,EAAKX,EAAMC,CAAQ,CAChD,CACA,MAAM,IAAI,UAAWN,EAAQ,wGAAyGgB,CAAI,CAAE,CAC7I,SAAY1B,EAAe0B,CAAI,EAC9B,MAAM,IAAI,MAAO,mFAAoF,EAEtG,MAAM,IAAI,UAAWhB,EAAQ,wGAAyGgB,CAAI,CAAE,CAC7I,CACA,GAAKJ,IAAU,EAEd,GADAI,EAAM,UAAW,CAAE,EACd3B,EAAc2B,CAAI,EACtBT,EAAM,IAAIO,EAAME,EAAI,MAAO,UAChB1B,EAAe0B,CAAI,EAC9BT,EAAM,IAAIO,EAAME,CAAI,UACT9B,EAAsB8B,CAAI,EACrCT,EAAM,IAAIO,EAAME,CAAI,UACTzB,EAAUyB,CAAI,EAAI,CAC7B,GAAKf,IAAwB,GAC5B,MAAM,IAAI,UAAWD,EAAQ,sIAAuIgB,CAAI,CAAE,EAE3K,GAAK,CAACxB,EAAYwB,EAAKnB,CAAgB,CAAE,EACxC,MAAM,IAAI,UAAWG,EAAQ,wGAAyGgB,CAAI,CAAE,EAG7I,GADAA,EAAMA,EAAKnB,CAAgB,EAAE,EACxB,CAACL,EAAYwB,EAAI,IAAK,EAC1B,MAAM,IAAI,UAAWhB,EAAQ,wGAAyGgB,CAAI,CAAE,EAE7IT,EAAM,IAAIO,EAAMhB,EAAYkB,CAAI,CAAE,CACnC,KACC,OAAM,IAAI,UAAWhB,EAAQ,wGAAyGgB,CAAI,CAAE,OAElIJ,IAAU,EACrBL,EAAM,IAAIO,EAAM,UAAU,CAAC,EAAG,UAAU,CAAC,CAAE,EAE3CP,EAAM,IAAIO,EAAM,UAAU,CAAC,EAAG,UAAU,CAAC,EAAG,UAAU,CAAC,CAAE,EAE1D,OAAKP,EAAI,OAAS,IACZpB,EAAmB0B,CAAM,GAAKzB,EAAmByB,CAAM,EAC3DJ,EAAiBF,EAAKF,EAAMC,CAAQ,EAEpCZ,EAASa,EAAI,OAAQA,EAAK,EAAGU,CAAS,GAGjCV,EAYP,SAASU,EAAUC,EAAOC,EAAO,CAChC,OAAOd,EAAK,KAAMC,EAASa,CAAK,CACjC,CACD,CAKAnC,EAAO,QAAU2B,ICrOjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isComplexDataType", "isBooleanDataType", "isCollection", "isArrayBuffer", "isObject", "isFunction", "ctors", "gfillBy", "filledArray", "hasIteratorSymbolSupport", "ITERATOR_SYMBOL", "iterLength", "defaults", "format", "HAS_ITERATOR_SYMBOL", "DEFAULT_DTYPE", "filledArrayIterator", "it", "clbk", "thisArg", "arr", "v", "filledAccessors", "i", "filledarrayBy", "nargs", "dtype", "ctor", "len", "arg", "callback", "value", "aidx", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 06f3146..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,157 +0,0 @@ - -{{alias}}( [dtype] ) - Creates a filled array. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|Array - Output array. - - Examples - -------- - > var arr = {{alias}}() - - > arr = {{alias}}( 'float32' ) - - - -{{alias}}( length[, dtype], clbk[, thisArg] ) - Returns a filled array according to a provided callback function and having - a specified length. - - Parameters - ---------- - length: integer - Array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: TypedArray|Array - Output array. - - Examples - -------- - > function clbk() { return 1.0; }; - > var arr = {{alias}}( 5, clbk ) - [ 1.0, 1.0, 1.0, 1.0, 1.0 ] - > arr = {{alias}}( 5, 'int32', clbk ) - [ 1, 1, 1, 1, 1 ] - - -{{alias}}( array[, dtype], clbk[, thisArg] ) - Creates a filled array from another array (or array-like object) according - to a provided callback function. - - Parameters - ---------- - array: ArrayLikeObject - Array from which to generate another array. - - dtype: string (optional) - Data type. Default: 'float64'. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: TypedArray|Array - Output array. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ], {{alias:@stdlib/utils/constant-function}}( 2.0 ) ) - [ 2.0, 2.0, 2.0 ] - > var arr2 = {{alias}}( arr1, 'float32', {{alias:@stdlib/utils/constant-function}}( 1.0 ) ) - [ 1.0, 1.0, 1.0 ] - - -{{alias}}( iterable[, dtype], clbk[, thisArg] ) - Creates a filled array from an iterable according to a provided callback - function. - - Parameters - ---------- - iterable: Iterable - Iterable from which to generate an array. - - dtype: string (optional) - Data type. Default: 'float64'. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: TypedArray|Array - Output array. - - Examples - -------- - > var arr1 = {{alias:@stdlib/iter/constant}}( 3.0, {'iter': 3} ); - > var arr2 = {{alias}}( arr1, 'float32', {{alias:@stdlib/utils/constant-function}}( 1.0 ) ) - [ 1.0, 1.0, 1.0 ] - - -{{alias}}( buffer[, byteOffset[, length]][, dtype], clbk[, thisArg] ) - Returns a filled typed array view of an ArrayBuffer according to a provided - callback function. - - The 'generic' array data type is *not* supported. - - Parameters - ---------- - buffer: ArrayBuffer - Underlying ArrayBuffer. - - byteOffset: integer (optional) - Integer byte offset specifying the location of the first typed array - element. Default: 0. - - length: integer (optional) - View length. If not provided, the view spans from the byteOffset to - the end of the underlying ArrayBuffer. - - dtype: string (optional) - Data type. Default: 'float64'. - - clbk: Function - Callback function. - - thisArg: any (optional) - Callback execution context. - - Returns - ------- - out: TypedArray - A typed array. - - Examples - -------- - > var buf = new {{alias:@stdlib/array/buffer}}( 16 ); - > var arr = {{alias}}( buf, 0, 4, 'float32', {{alias:@stdlib/utils/constant-function}}( 1.0 ) ) - [ 1.0, 1.0, 1.0, 1.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index bb876ed..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,606 +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. -*/ - -/// - -import { IterableIterator } from '@stdlib/types/iter'; -import filledarrayBy = require( './index' ); - - -/** -* Returns an iterator protocol-compliant object. -* -* @returns iterator protocol-compliant object -*/ -function iterator(): IterableIterator { - const obj: IterableIterator = { - [Symbol.iterator]: iterator, - 'next': next - }; - return obj; -} - -/** -* Implements the iterator protocol `next` method. -* -* @returns iterator protocol-compliant object -*/ -function next(): any { - return { - 'value': 1.0, - 'done': false - }; -} - -/** -* Callback function. -* -* @param i - current array index -* @returns return value -*/ -function clbk( i: number ): number { - return i; -} - - -// TESTS // - -// The function returns an array or typed array... -{ - filledarrayBy(); // $ExpectType ArrayOrTypedArray - filledarrayBy( 'float32' ); // $ExpectType ArrayOrTypedArray - - filledarrayBy( 10, clbk ); // $ExpectType ArrayOrTypedArray - filledarrayBy( 10, clbk, {} ); // $ExpectType ArrayOrTypedArray - - filledarrayBy( 10, 'int32', clbk ); // $ExpectType ArrayOrTypedArray - filledarrayBy( 10, 'int32', clbk, {} ); // $ExpectType ArrayOrTypedArray - - const x = new Float64Array( 10 ); - filledarrayBy( x, clbk ); // $ExpectType ArrayOrTypedArray - filledarrayBy( x, clbk, {} ); // $ExpectType ArrayOrTypedArray - - filledarrayBy( x, 'uint8', clbk ); // $ExpectType ArrayOrTypedArray - filledarrayBy( x, 'uint8', clbk, {} ); // $ExpectType ArrayOrTypedArray - - const y = [ 2.0, 2.0, 2.0 ]; - filledarrayBy( y, clbk ); // $ExpectType ArrayOrTypedArray - filledarrayBy( y, clbk, {} ); // $ExpectType ArrayOrTypedArray - - filledarrayBy( y, 'float64', clbk ); // $ExpectType ArrayOrTypedArray - filledarrayBy( y, 'float64', clbk, {} ); // $ExpectType ArrayOrTypedArray - - const it = iterator(); - filledarrayBy( it, clbk ); // $ExpectType ArrayOrTypedArray - filledarrayBy( it, clbk, {} ); // $ExpectType ArrayOrTypedArray - - filledarrayBy( it, 'uint8c', clbk ); // $ExpectType ArrayOrTypedArray - filledarrayBy( it, 'uint8c', clbk, {} ); // $ExpectType ArrayOrTypedArray - - const buf = new ArrayBuffer( 32 ); - filledarrayBy( buf, clbk ); // $ExpectType RealOrComplexTypedArray | BooleanArray - filledarrayBy( buf, clbk, {} ); // $ExpectType RealOrComplexTypedArray | BooleanArray - - filledarrayBy( buf, 'uint32', clbk ); // $ExpectType RealOrComplexTypedArray | BooleanArray - filledarrayBy( buf, 'uint32', clbk, {} ); // $ExpectType RealOrComplexTypedArray | BooleanArray - - filledarrayBy( buf, 8, clbk ); // $ExpectType RealOrComplexTypedArray | BooleanArray - filledarrayBy( buf, 8, clbk, {} ); // $ExpectType RealOrComplexTypedArray | BooleanArray - - filledarrayBy( buf, 8, 'uint16', clbk ); // $ExpectType RealOrComplexTypedArray | BooleanArray - filledarrayBy( buf, 8, 'uint16', clbk, {} ); // $ExpectType RealOrComplexTypedArray | BooleanArray - - filledarrayBy( buf, 8, 2, clbk ); // $ExpectType RealOrComplexTypedArray | BooleanArray - filledarrayBy( buf, 8, 2, clbk, {} ); // $ExpectType RealOrComplexTypedArray | BooleanArray - - filledarrayBy( buf, 8, 2, 'int16', clbk ); // $ExpectType RealOrComplexTypedArray | BooleanArray - filledarrayBy( buf, 8, 2, 'int16', clbk, {} ); // $ExpectType RealOrComplexTypedArray | BooleanArray -} - -// The compiler throws an error if a callback function argument is not a function... -{ - filledarrayBy( 'float64', '5' ); // $ExpectError - filledarrayBy( 'float64', 1.0 ); // $ExpectError - filledarrayBy( 'float64', false ); // $ExpectError - filledarrayBy( 'float64', true ); // $ExpectError - filledarrayBy( 'float64', null ); // $ExpectError - filledarrayBy( 'float64', undefined ); // $ExpectError - filledarrayBy( 'float64', [] ); // $ExpectError - filledarrayBy( 'float64', {} ); // $ExpectError - - filledarrayBy( 'float64', '5', {} ); // $ExpectError - filledarrayBy( 'float64', 1.0, {} ); // $ExpectError - filledarrayBy( 'float64', false, {} ); // $ExpectError - filledarrayBy( 'float64', true, {} ); // $ExpectError - filledarrayBy( 'float64', null, {} ); // $ExpectError - filledarrayBy( 'float64', undefined, {} ); // $ExpectError - filledarrayBy( 'float64', [], {} ); // $ExpectError - filledarrayBy( 'float64', {}, {} ); // $ExpectError - - filledarrayBy( 10, '5' ); // $ExpectError - filledarrayBy( 10, 1.0 ); // $ExpectError - filledarrayBy( 10, false ); // $ExpectError - filledarrayBy( 10, true ); // $ExpectError - filledarrayBy( 10, null ); // $ExpectError - filledarrayBy( 10, undefined ); // $ExpectError - filledarrayBy( 10, [] ); // $ExpectError - filledarrayBy( 10, {} ); // $ExpectError - - filledarrayBy( 10, '5', {} ); // $ExpectError - filledarrayBy( 10, 1.0, {} ); // $ExpectError - filledarrayBy( 10, false, {} ); // $ExpectError - filledarrayBy( 10, true, {} ); // $ExpectError - filledarrayBy( 10, null, {} ); // $ExpectError - filledarrayBy( 10, undefined, {} ); // $ExpectError - filledarrayBy( 10, [], {} ); // $ExpectError - filledarrayBy( 10, {}, {} ); // $ExpectError - - filledarrayBy( 10, 'float64', '5' ); // $ExpectError - filledarrayBy( 10, 'float64', 1.0 ); // $ExpectError - filledarrayBy( 10, 'float64', false ); // $ExpectError - filledarrayBy( 10, 'float64', true ); // $ExpectError - filledarrayBy( 10, 'float64', null ); // $ExpectError - filledarrayBy( 10, 'float64', undefined ); // $ExpectError - filledarrayBy( 10, 'float64', [] ); // $ExpectError - filledarrayBy( 10, 'float64', {} ); // $ExpectError - - filledarrayBy( 10, 'float64', '5', {} ); // $ExpectError - filledarrayBy( 10, 'float64', 1.0, {} ); // $ExpectError - filledarrayBy( 10, 'float64', false, {} ); // $ExpectError - filledarrayBy( 10, 'float64', true, {} ); // $ExpectError - filledarrayBy( 10, 'float64', null, {} ); // $ExpectError - filledarrayBy( 10, 'float64', undefined, {} ); // $ExpectError - filledarrayBy( 10, 'float64', [], {} ); // $ExpectError - filledarrayBy( 10, 'float64', {}, {} ); // $ExpectError - - const x = new Float64Array( 10 ); - filledarrayBy( x, '5' ); // $ExpectError - filledarrayBy( x, 1.0 ); // $ExpectError - filledarrayBy( x, false ); // $ExpectError - filledarrayBy( x, true ); // $ExpectError - filledarrayBy( x, null ); // $ExpectError - filledarrayBy( x, undefined ); // $ExpectError - filledarrayBy( x, [] ); // $ExpectError - filledarrayBy( x, {} ); // $ExpectError - - filledarrayBy( x, '5', {} ); // $ExpectError - filledarrayBy( x, 1.0, {} ); // $ExpectError - filledarrayBy( x, false, {} ); // $ExpectError - filledarrayBy( x, true, {} ); // $ExpectError - filledarrayBy( x, null, {} ); // $ExpectError - filledarrayBy( x, undefined, {} ); // $ExpectError - filledarrayBy( x, [], {} ); // $ExpectError - filledarrayBy( x, {}, {} ); // $ExpectError - - filledarrayBy( x, 'float64', '5' ); // $ExpectError - filledarrayBy( x, 'float64', 1.0 ); // $ExpectError - filledarrayBy( x, 'float64', false ); // $ExpectError - filledarrayBy( x, 'float64', true ); // $ExpectError - filledarrayBy( x, 'float64', null ); // $ExpectError - filledarrayBy( x, 'float64', undefined ); // $ExpectError - filledarrayBy( x, 'float64', [] ); // $ExpectError - filledarrayBy( x, 'float64', {} ); // $ExpectError - - filledarrayBy( x, 'float64', '5', {} ); // $ExpectError - filledarrayBy( x, 'float64', 1.0, {} ); // $ExpectError - filledarrayBy( x, 'float64', false, {} ); // $ExpectError - filledarrayBy( x, 'float64', true, {} ); // $ExpectError - filledarrayBy( x, 'float64', null, {} ); // $ExpectError - filledarrayBy( x, 'float64', undefined, {} ); // $ExpectError - filledarrayBy( x, 'float64', [], {} ); // $ExpectError - filledarrayBy( x, 'float64', {}, {} ); // $ExpectError - - const y = [ 2.0, 2.0, 2.0 ]; - filledarrayBy( y, '5' ); // $ExpectError - filledarrayBy( y, 1.0 ); // $ExpectError - filledarrayBy( y, false ); // $ExpectError - filledarrayBy( y, true ); // $ExpectError - filledarrayBy( y, null ); // $ExpectError - filledarrayBy( y, undefined ); // $ExpectError - filledarrayBy( y, [] ); // $ExpectError - filledarrayBy( y, {} ); // $ExpectError - - filledarrayBy( y, '5', {} ); // $ExpectError - filledarrayBy( y, 1.0, {} ); // $ExpectError - filledarrayBy( y, false, {} ); // $ExpectError - filledarrayBy( y, true, {} ); // $ExpectError - filledarrayBy( y, null, {} ); // $ExpectError - filledarrayBy( y, undefined, {} ); // $ExpectError - filledarrayBy( y, [], {} ); // $ExpectError - filledarrayBy( y, {}, {} ); // $ExpectError - - filledarrayBy( y, 'float64', '5' ); // $ExpectError - filledarrayBy( y, 'float64', 1.0 ); // $ExpectError - filledarrayBy( y, 'float64', false ); // $ExpectError - filledarrayBy( y, 'float64', true ); // $ExpectError - filledarrayBy( y, 'float64', null ); // $ExpectError - filledarrayBy( y, 'float64', undefined ); // $ExpectError - filledarrayBy( y, 'float64', [] ); // $ExpectError - filledarrayBy( y, 'float64', {} ); // $ExpectError - - filledarrayBy( y, 'float64', '5', {} ); // $ExpectError - filledarrayBy( y, 'float64', 1.0, {} ); // $ExpectError - filledarrayBy( y, 'float64', false, {} ); // $ExpectError - filledarrayBy( y, 'float64', true, {} ); // $ExpectError - filledarrayBy( y, 'float64', null, {} ); // $ExpectError - filledarrayBy( y, 'float64', undefined, {} ); // $ExpectError - filledarrayBy( y, 'float64', [], {} ); // $ExpectError - filledarrayBy( y, 'float64', {}, {} ); // $ExpectError - - const it = iterator(); - filledarrayBy( it, '5' ); // $ExpectError - filledarrayBy( it, 1.0 ); // $ExpectError - filledarrayBy( it, false ); // $ExpectError - filledarrayBy( it, true ); // $ExpectError - filledarrayBy( it, null ); // $ExpectError - filledarrayBy( it, undefined ); // $ExpectError - filledarrayBy( it, [] ); // $ExpectError - filledarrayBy( it, {} ); // $ExpectError - - filledarrayBy( it, '5', {} ); // $ExpectError - filledarrayBy( it, 1.0, {} ); // $ExpectError - filledarrayBy( it, false, {} ); // $ExpectError - filledarrayBy( it, true, {} ); // $ExpectError - filledarrayBy( it, null, {} ); // $ExpectError - filledarrayBy( it, undefined, {} ); // $ExpectError - filledarrayBy( it, [], {} ); // $ExpectError - filledarrayBy( it, {}, {} ); // $ExpectError - - filledarrayBy( it, 'float64', '5' ); // $ExpectError - filledarrayBy( it, 'float64', 1.0 ); // $ExpectError - filledarrayBy( it, 'float64', false ); // $ExpectError - filledarrayBy( it, 'float64', true ); // $ExpectError - filledarrayBy( it, 'float64', null ); // $ExpectError - filledarrayBy( it, 'float64', undefined ); // $ExpectError - filledarrayBy( it, 'float64', [] ); // $ExpectError - filledarrayBy( it, 'float64', {} ); // $ExpectError - - filledarrayBy( it, 'float64', '5', {} ); // $ExpectError - filledarrayBy( it, 'float64', 1.0, {} ); // $ExpectError - filledarrayBy( it, 'float64', false, {} ); // $ExpectError - filledarrayBy( it, 'float64', true, {} ); // $ExpectError - filledarrayBy( it, 'float64', null, {} ); // $ExpectError - filledarrayBy( it, 'float64', undefined, {} ); // $ExpectError - filledarrayBy( it, 'float64', [], {} ); // $ExpectError - filledarrayBy( it, 'float64', {}, {} ); // $ExpectError - - const buf = new ArrayBuffer( 32 ); - filledarrayBy( buf, '5' ); // $ExpectError - filledarrayBy( buf, 1.0 ); // $ExpectError - filledarrayBy( buf, false ); // $ExpectError - filledarrayBy( buf, true ); // $ExpectError - filledarrayBy( buf, null ); // $ExpectError - filledarrayBy( buf, undefined ); // $ExpectError - filledarrayBy( buf, [] ); // $ExpectError - filledarrayBy( buf, {} ); // $ExpectError - - filledarrayBy( buf, '5', {} ); // $ExpectError - filledarrayBy( buf, 1.0, {} ); // $ExpectError - filledarrayBy( buf, false, {} ); // $ExpectError - filledarrayBy( buf, true, {} ); // $ExpectError - filledarrayBy( buf, null, {} ); // $ExpectError - filledarrayBy( buf, undefined, {} ); // $ExpectError - filledarrayBy( buf, [], {} ); // $ExpectError - filledarrayBy( buf, {}, {} ); // $ExpectError - - filledarrayBy( buf, 'float64', '5' ); // $ExpectError - filledarrayBy( buf, 'float64', 1.0 ); // $ExpectError - filledarrayBy( buf, 'float64', false ); // $ExpectError - filledarrayBy( buf, 'float64', true ); // $ExpectError - filledarrayBy( buf, 'float64', null ); // $ExpectError - filledarrayBy( buf, 'float64', undefined ); // $ExpectError - filledarrayBy( buf, 'float64', [] ); // $ExpectError - filledarrayBy( buf, 'float64', {} ); // $ExpectError - - filledarrayBy( buf, 'float64', '5', {} ); // $ExpectError - filledarrayBy( buf, 'float64', 1.0, {} ); // $ExpectError - filledarrayBy( buf, 'float64', false, {} ); // $ExpectError - filledarrayBy( buf, 'float64', true, {} ); // $ExpectError - filledarrayBy( buf, 'float64', null, {} ); // $ExpectError - filledarrayBy( buf, 'float64', undefined, {} ); // $ExpectError - filledarrayBy( buf, 'float64', [], {} ); // $ExpectError - filledarrayBy( buf, 'float64', {}, {} ); // $ExpectError - - filledarrayBy( buf, 8, '5' ); // $ExpectError - filledarrayBy( buf, 8, 1.0 ); // $ExpectError - filledarrayBy( buf, 8, false ); // $ExpectError - filledarrayBy( buf, 8, true ); // $ExpectError - filledarrayBy( buf, 8, null ); // $ExpectError - filledarrayBy( buf, 8, undefined ); // $ExpectError - filledarrayBy( buf, 8, [] ); // $ExpectError - filledarrayBy( buf, 8, {} ); // $ExpectError - - filledarrayBy( buf, 8, '5', {} ); // $ExpectError - filledarrayBy( buf, 8, 1.0, {} ); // $ExpectError - filledarrayBy( buf, 8, false, {} ); // $ExpectError - filledarrayBy( buf, 8, true, {} ); // $ExpectError - filledarrayBy( buf, 8, null, {} ); // $ExpectError - filledarrayBy( buf, 8, undefined, {} ); // $ExpectError - filledarrayBy( buf, 8, [], {} ); // $ExpectError - filledarrayBy( buf, 8, {}, {} ); // $ExpectError - - filledarrayBy( buf, 8, 'float64', '5' ); // $ExpectError - filledarrayBy( buf, 8, 'float64', 1.0 ); // $ExpectError - filledarrayBy( buf, 8, 'float64', false ); // $ExpectError - filledarrayBy( buf, 8, 'float64', true ); // $ExpectError - filledarrayBy( buf, 8, 'float64', null ); // $ExpectError - filledarrayBy( buf, 8, 'float64', undefined ); // $ExpectError - filledarrayBy( buf, 8, 'float64', [] ); // $ExpectError - filledarrayBy( buf, 8, 'float64', {} ); // $ExpectError - - filledarrayBy( buf, 8, 'float64', '5', {} ); // $ExpectError - filledarrayBy( buf, 8, 'float64', 1.0, {} ); // $ExpectError - filledarrayBy( buf, 8, 'float64', false, {} ); // $ExpectError - filledarrayBy( buf, 8, 'float64', true, {} ); // $ExpectError - filledarrayBy( buf, 8, 'float64', null, {} ); // $ExpectError - filledarrayBy( buf, 8, 'float64', undefined, {} ); // $ExpectError - filledarrayBy( buf, 8, 'float64', [], {} ); // $ExpectError - filledarrayBy( buf, 8, 'float64', {}, {} ); // $ExpectError - - filledarrayBy( buf, 8, 2, '5' ); // $ExpectError - filledarrayBy( buf, 8, 2, 1.0 ); // $ExpectError - filledarrayBy( buf, 8, 2, false ); // $ExpectError - filledarrayBy( buf, 8, 2, true ); // $ExpectError - filledarrayBy( buf, 8, 2, null ); // $ExpectError - filledarrayBy( buf, 8, 2, undefined ); // $ExpectError - filledarrayBy( buf, 8, 2, [] ); // $ExpectError - filledarrayBy( buf, 8, 2, {} ); // $ExpectError - - filledarrayBy( buf, 8, 2, '5', {} ); // $ExpectError - filledarrayBy( buf, 8, 2, 1.0, {} ); // $ExpectError - filledarrayBy( buf, 8, 2, false, {} ); // $ExpectError - filledarrayBy( buf, 8, 2, true, {} ); // $ExpectError - filledarrayBy( buf, 8, 2, null, {} ); // $ExpectError - filledarrayBy( buf, 8, 2, undefined, {} ); // $ExpectError - filledarrayBy( buf, 8, 2, [], {} ); // $ExpectError - filledarrayBy( buf, 8, 2, {}, {} ); // $ExpectError - - filledarrayBy( buf, 8, 2, 'float64', '5' ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', 1.0 ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', false ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', true ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', null ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', undefined ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', [] ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', {} ); // $ExpectError - - filledarrayBy( buf, 8, 2, 'float64', '5', {} ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', 1.0, {} ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', false, {} ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', true, {} ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', null, {} ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', undefined, {} ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', [], {} ); // $ExpectError - filledarrayBy( buf, 8, 2, 'float64', {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function is not provided a valid length, typed array, array-like object, `ArrayBuffer`, or iterable argument... -{ - filledarrayBy( false, clbk ); // $ExpectError - filledarrayBy( true, clbk ); // $ExpectError - filledarrayBy( null, clbk ); // $ExpectError - filledarrayBy( {}, clbk ); // $ExpectError - - filledarrayBy( false, clbk, {} ); // $ExpectError - filledarrayBy( true, clbk, {} ); // $ExpectError - filledarrayBy( null, clbk, {} ); // $ExpectError - filledarrayBy( {}, clbk, {} ); // $ExpectError - - filledarrayBy( false, 'float64', clbk ); // $ExpectError - filledarrayBy( true, 'float64', clbk ); // $ExpectError - filledarrayBy( null, 'float64', clbk ); // $ExpectError - filledarrayBy( undefined, 'float64', clbk ); // $ExpectError - filledarrayBy( {}, 'float64', clbk ); // $ExpectError - - filledarrayBy( false, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( true, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( null, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( undefined, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( {}, 'float64', clbk, {} ); // $ExpectError - - filledarrayBy( '5', 8, clbk ); // $ExpectError - filledarrayBy( 1.0, 8, clbk ); // $ExpectError - filledarrayBy( false, 8, clbk ); // $ExpectError - filledarrayBy( true, 8, clbk ); // $ExpectError - filledarrayBy( null, 8, clbk ); // $ExpectError - filledarrayBy( undefined, 8, clbk ); // $ExpectError - filledarrayBy( [], 8, clbk ); // $ExpectError - filledarrayBy( {}, 8, clbk ); // $ExpectError - filledarrayBy( ( x: number ): number => x, 8, clbk ); // $ExpectError - - filledarrayBy( '5', 8, clbk, {} ); // $ExpectError - filledarrayBy( 1.0, 8, clbk, {} ); // $ExpectError - filledarrayBy( false, 8, clbk, {} ); // $ExpectError - filledarrayBy( true, 8, clbk, {} ); // $ExpectError - filledarrayBy( null, 8, clbk, {} ); // $ExpectError - filledarrayBy( undefined, 8, clbk, {} ); // $ExpectError - filledarrayBy( [], 8, clbk, {} ); // $ExpectError - filledarrayBy( {}, 8, clbk, {} ); // $ExpectError - filledarrayBy( ( x: number ): number => x, 8, clbk, {} ); // $ExpectError - - filledarrayBy( '5', 8, 'float64', clbk ); // $ExpectError - filledarrayBy( 1.0, 8, 'float64', clbk ); // $ExpectError - filledarrayBy( false, 8, 'float64', clbk ); // $ExpectError - filledarrayBy( true, 8, 'float64', clbk ); // $ExpectError - filledarrayBy( null, 8, 'float64', clbk ); // $ExpectError - filledarrayBy( undefined, 8, 'float64', clbk ); // $ExpectError - filledarrayBy( [], 8, 'float64', clbk ); // $ExpectError - filledarrayBy( {}, 8, 'float64', clbk ); // $ExpectError - filledarrayBy( ( x: number ): number => x, 8, 'float64', clbk ); // $ExpectError - - filledarrayBy( '5', 8, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( 1.0, 8, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( false, 8, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( true, 8, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( null, 8, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( undefined, 8, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( [], 8, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( {}, 8, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( ( x: number ): number => x, 8, 'float64', clbk, {} ); // $ExpectError - - filledarrayBy( '5', 8, 2, clbk ); // $ExpectError - filledarrayBy( 1.0, 8, 2, clbk ); // $ExpectError - filledarrayBy( false, 8, 2, clbk ); // $ExpectError - filledarrayBy( true, 8, 2, clbk ); // $ExpectError - filledarrayBy( null, 8, 2, clbk ); // $ExpectError - filledarrayBy( undefined, 8, 2, clbk ); // $ExpectError - filledarrayBy( [], 8, 2, clbk ); // $ExpectError - filledarrayBy( {}, 8, 2, clbk ); // $ExpectError - filledarrayBy( ( x: number ): number => x, 8, 2, clbk ); // $ExpectError - - filledarrayBy( '5', 8, 2, clbk, {} ); // $ExpectError - filledarrayBy( 1.0, 8, 2, clbk, {} ); // $ExpectError - filledarrayBy( false, 8, 2, clbk, {} ); // $ExpectError - filledarrayBy( true, 8, 2, clbk, {} ); // $ExpectError - filledarrayBy( null, 8, 2, clbk, {} ); // $ExpectError - filledarrayBy( undefined, 8, 2, clbk, {} ); // $ExpectError - filledarrayBy( [], 8, 2, clbk, {} ); // $ExpectError - filledarrayBy( {}, 8, 2, clbk, {} ); // $ExpectError - filledarrayBy( ( x: number ): number => x, 8, 2, clbk, {} ); // $ExpectError - - filledarrayBy( '5', 8, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( 1.0, 8, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( false, 8, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( true, 8, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( null, 8, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( undefined, 8, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( [], 8, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( {}, 8, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( ( x: number ): number => x, 8, 2, 'float64', clbk ); // $ExpectError - - filledarrayBy( '5', 8, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( 1.0, 8, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( false, 8, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( true, 8, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( null, 8, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( undefined, 8, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( [], 8, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( {}, 8, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( ( x: number ): number => x, 8, 2, 'float64', clbk, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a byte offset argument which is not a number... -{ - const buf = new ArrayBuffer( 32 ); - - filledarrayBy( buf, false, clbk ); // $ExpectError - filledarrayBy( buf, true, clbk ); // $ExpectError - filledarrayBy( buf, null, clbk ); // $ExpectError - filledarrayBy( buf, [], clbk ); // $ExpectError - filledarrayBy( buf, {}, clbk ); // $ExpectError - - filledarrayBy( buf, false, clbk, {} ); // $ExpectError - filledarrayBy( buf, true, clbk, {} ); // $ExpectError - filledarrayBy( buf, null, clbk, {} ); // $ExpectError - filledarrayBy( buf, [], clbk, {} ); // $ExpectError - filledarrayBy( buf, {}, clbk, {} ); // $ExpectError - filledarrayBy( buf, ( x: number ): number => x, clbk, {} ); // $ExpectError - - filledarrayBy( buf, '5', 'float64', clbk ); // $ExpectError - filledarrayBy( buf, false, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, true, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, null, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, undefined, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, [], 'float64', clbk ); // $ExpectError - filledarrayBy( buf, {}, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, ( x: number ): number => x, 'float64', clbk ); // $ExpectError - - filledarrayBy( buf, '5', 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, false, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, true, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, null, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, undefined, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, [], 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, {}, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, ( x: number ): number => x, 'float64', clbk, {} ); // $ExpectError - - filledarrayBy( buf, false, 2, clbk ); // $ExpectError - filledarrayBy( buf, true, 2, clbk ); // $ExpectError - filledarrayBy( buf, null, 2, clbk ); // $ExpectError - filledarrayBy( buf, [], 2, clbk ); // $ExpectError - filledarrayBy( buf, {}, 2, clbk ); // $ExpectError - filledarrayBy( buf, ( x: number ): number => x, 2, clbk ); // $ExpectError - - filledarrayBy( buf, false, 2, clbk, {} ); // $ExpectError - filledarrayBy( buf, true, 2, clbk, {} ); // $ExpectError - filledarrayBy( buf, null, 2, clbk, {} ); // $ExpectError - filledarrayBy( buf, [], 2, clbk, {} ); // $ExpectError - filledarrayBy( buf, {}, 2, clbk, {} ); // $ExpectError - filledarrayBy( buf, ( x: number ): number => x, 2, clbk, {} ); // $ExpectError - - filledarrayBy( buf, '5', 2, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, false, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, true, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, null, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, undefined, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, [], 2, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, {}, 2, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, ( x: number ): number => x, 2, 'float64', clbk ); // $ExpectError - - filledarrayBy( buf, '5', 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, false, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, true, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, null, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, undefined, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, [], 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, {}, 2, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, ( x: number ): number => x, 2, 'float64', clbk, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a view length argument which is not a number... -{ - const buf = new ArrayBuffer( 32 ); - - filledarrayBy( buf, 8, false, clbk ); // $ExpectError - filledarrayBy( buf, 8, true, clbk ); // $ExpectError - filledarrayBy( buf, 8, null, clbk ); // $ExpectError - filledarrayBy( buf, 8, [], clbk ); // $ExpectError - filledarrayBy( buf, 8, {}, clbk ); // $ExpectError - - filledarrayBy( buf, 8, false, clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, true, clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, null, clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, [], clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, {}, clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, ( x: number ): number => x, clbk, {} ); // $ExpectError - - filledarrayBy( buf, 8, '5', 'float64', clbk ); // $ExpectError - filledarrayBy( buf, 8, false, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, 8, true, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, 8, null, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, 8, undefined, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, 8, [], 'float64', clbk ); // $ExpectError - filledarrayBy( buf, 8, {}, 'float64', clbk ); // $ExpectError - filledarrayBy( buf, 8, ( x: number ): number => x, 'float64', clbk ); // $ExpectError - - filledarrayBy( buf, 8, '5', 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, false, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, true, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, null, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, undefined, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, [], 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, {}, 'float64', clbk, {} ); // $ExpectError - filledarrayBy( buf, 8, ( x: number ): number => x, 'float64', clbk, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided too many arguments... -{ - const buf = new ArrayBuffer( 32 ); - - filledarrayBy( buf, 8, 2, 'float64', 1, clbk, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a381..0000000 --- a/examples/index.js +++ /dev/null @@ -1,37 +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. -*/ - -'use strict'; - -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var dtypes = require( '@stdlib/array-typed-real-dtypes' ); -var filledarrayBy = require( './../lib' ); - -// Create a pseudorandom number generator: -var rand = discreteUniform( 0, 100 ); - -// Get a list of array data types: -var dt = dtypes(); - -// Generate filled arrays... -var arr; -var i; -for ( i = 0; i < dt.length; i++ ) { - arr = filledarrayBy( 10, dt[ i ], rand ); - console.log( arr ); -} 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 606ef7c..fde6688 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection, RealOrComplexTypedArray, BooleanArray, DataType } from '@stdlib/types/array'; import { IterableIterator } from '@stdlib/types/iter'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6f157fa --- /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{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.3-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-boolean-data-type@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-object@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-ctors@v0.3.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-ext-base-gfill-by@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-filled-by@v0.2.3-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-iterator-symbol-support@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/iter-length@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.4.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";var v=f(),g=j.get("dtypes.default");function c(){var f,j,c,b,y,x,u,E;if(0===(j=arguments.length))return new(y=d(g))(0);if(r(c=arguments[0])){if(j>1)throw new TypeError(w("00h05"));if(null===(y=d(c)))throw new TypeError(w("00h2Y",c));return new y(0)}if(j<2)throw new TypeError(w("00h05"));if(h(arguments[j-=1]))if(h(arguments[j-1])){if(f=arguments[j],b=arguments[j-=1],0===j)throw new TypeError(w("00h05"))}else b=arguments[j];else{if(!(j>=2))throw new TypeError(w("00h05"));if(f=arguments[j],!h(b=arguments[j-=1]))throw new TypeError(w("00h2b",b))}if((j-=1)>=0&&r(arguments[j])?(c=arguments[j],j-=1):c=g,null===(y=d(c)))throw new TypeError(w("00h2Y",c));if("generic"===c){if(E=arguments[0],0===j){if(e(E)?u=E:i(E)&&(u=E.length),void 0!==u)return m(u,b,f);if(n(E))throw new Error(w("00h04"));if(o(E)){if(!1===v)throw new TypeError(w("00h2Z",E));if(!h(E[p]))throw new TypeError(w("00h2a",E));if(E=E[p](),!h(E.next))throw new TypeError(w("00h2a",E));return function(r,e,t){var s,i;for(s=[],i=-1;!r.next().done;)i+=1,s.push(e.call(t,i));return s}(E,b,f)}throw new TypeError(w("00h2a",E))}if(n(E))throw new Error(w("00h04"));throw new TypeError(w("00h2a",E))}if(0===j)if(i(E=arguments[0]))x=new y(E.length);else if(n(E))x=new y(E);else if(e(E))x=new y(E);else{if(!o(E))throw new TypeError(w("00h2a",E));if(!1===v)throw new TypeError(w("00h2Z",E));if(!h(E[p]))throw new TypeError(w("00h2a",E));if(E=E[p](),!h(E.next))throw new TypeError(w("00h2a",E));x=new y(a(E))}else x=1===j?new y(arguments[0],arguments[1]):new y(arguments[0],arguments[1],arguments[2]);return x.length>0&&(t(c)||s(c)?function(r,e,t){var s;for(s=0;s\n*\n* @example\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( 2, clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( 2, 'float32', clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( 2, 'generic', clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* function clbk() {\n* return 1.0;\n* }\n*\n* var arr = filledarrayBy( [ 0.5, 0.5 ], clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* function clbk() {\n* return 1;\n* }\n*\n* var arr = filledarrayBy( [ 5, -3 ], 'int32', clbk );\n* // returns [ 1, 1 ]\n*\n* @example\n* function clbk1() {\n* return 10;\n* }\n*\n* function clbk2() {\n* return 1.0;\n* }\n*\n* var arr1 = filledarrayBy( [ 5, 3 ], 'int32', clbk1 );\n* var arr2 = filledarrayBy( arr1, clbk2 );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* function clbk1() {\n* return 1.0;\n* }\n*\n* function clbk2() {\n* return 2;\n* }\n*\n* var arr1 = filledarrayBy( [ 5, 3 ], 'int32', clbk1 );\n* var arr2 = filledarrayBy( arr1, 'uint32', clbk2 );\n* // returns [ 2, 2 ]\n*\n* @example\n* import ArrayBuffer from '@stdlib/array-buffer';\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* import ArrayBuffer from '@stdlib/array-buffer';\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, 'float32', clbk );\n* // returns [ 1.0, 1.0, 1.0, 1.0 ]\n*\n* @example\n* import ArrayBuffer from '@stdlib/array-buffer';\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, 8, clbk );\n* // returns [ 1.0 ]\n*\n* @example\n* import ArrayBuffer from '@stdlib/array-buffer';\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 16 );\n* var arr = filledarrayBy( buf, 8, 'float32', clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* import ArrayBuffer from '@stdlib/array-buffer';\n*\n* function clbk() {\n* return 1.0;\n* }\n*\n* var buf = new ArrayBuffer( 32 );\n* var arr = filledarrayBy( buf, 8, 2, clbk );\n* // returns [ 1.0, 1.0 ]\n*\n* @example\n* import ArrayBuffer from '@stdlib/array-buffer';\n*\n* function clbk() {\n* return 1;\n* }\n*\n* var buf = new ArrayBuffer( 32 );\n* var arr = filledarrayBy( buf, 8, 2, 'int32', clbk );\n* // returns [ 1, 1 ]\n*/\nfunction filledarrayBy() {\n\tvar thisArg;\n\tvar nargs;\n\tvar dtype;\n\tvar clbk;\n\tvar ctor;\n\tvar arr;\n\tvar len;\n\tvar arg;\n\n\tnargs = arguments.length;\n\n\t// If we weren't provided any arguments, return an empty array...\n\tif ( nargs === 0 ) {\n\t\tctor = ctors( DEFAULT_DTYPE );\n\t\treturn new ctor( 0 );\n\t}\n\t// Check if we were provided a dtype as the first argument...\n\tdtype = arguments[ 0 ];\n\tif ( isString( dtype ) ) {\n\t\t// Invoking this function with arguments `f( dtype, clbk[, thisArg] )` is not allowed (otherwise, we'd need to also allow `f( clbk[, thisArg] )`)...\n\t\tif ( nargs > 1 ) {\n\t\t\tthrow new TypeError( format('00h05') );\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00h2Y', dtype ) );\n\t\t}\n\t\t// Return an empty array having the specified dtype:\n\t\treturn new ctor( 0 );\n\t}\n\t// For all other supported invocations, we need at least two arguments...\n\tif ( nargs < 2 ) {\n\t\tthrow new TypeError( format('00h05') );\n\t}\n\t// At this point, we need to do some argument juggling...\n\tnargs -= 1; // henceforth, the number of available arguments is `nargs+1`\n\n\t// Determine whether the last argument is a callback or \"this\" context...\n\tif ( isFunction( arguments[ nargs ] ) ) {\n\t\t// If the last argument is a function, we need to check the next-to-last argument, and, if the next-to-last argument is a function, assume that the next-to-last argument is the callback and the last argument is a \"this\" context...\n\t\tif ( isFunction( arguments[ nargs-1 ] ) ) {\n\t\t\tthisArg = arguments[ nargs ];\n\t\t\tnargs -= 1;\n\t\t\tclbk = arguments[ nargs ];\n\n\t\t\t// Check if we were provided only a callback and a \"this\" context..\n\t\t\tif ( nargs === 0 ) {\n\t\t\t\tthrow new TypeError( format('00h05') );\n\t\t\t}\n\t\t} else {\n\t\t\t// \"this\" context is left undefined...\n\t\t\tclbk = arguments[ nargs ];\n\t\t}\n\t}\n\t// If we were provided 3 or more arguments and the last argument was not a function, assume that we were provided a callback and a \"this\" context...\n\telse if ( nargs >= 2 ) {\n\t\tthisArg = arguments[ nargs ];\n\t\tnargs -= 1;\n\t\tclbk = arguments[ nargs ];\n\t\tif ( !isFunction( clbk ) ) {\n\t\t\tthrow new TypeError( format( '00h2b', clbk ) );\n\t\t}\n\t}\n\t// If we were only provided 2 arguments and the last argument was not a function, we've been provided an insufficient number of arguments...\n\telse {\n\t\tthrow new TypeError( format('00h05') );\n\t}\n\t// Now that we've processed the callback arguments, let's continue working backward to see if we've been provided a `dtype` argument...\n\tnargs -= 1;\n\tif ( nargs >= 0 && isString( arguments[ nargs ] ) ) {\n\t\tdtype = arguments[ nargs ];\n\t\tnargs -= 1;\n\t} else {\n\t\tdtype = DEFAULT_DTYPE;\n\t}\n\tctor = ctors( dtype );\n\tif ( ctor === null ) {\n\t\tthrow new TypeError( format( '00h2Y', dtype ) );\n\t}\n\t// At this point, we've resolved the output array data type, and now we can actually create the output array...\n\tif ( dtype === 'generic' ) {\n\t\targ = arguments[ 0 ];\n\t\tif ( nargs === 0 ) {\n\t\t\tif ( isNonNegativeInteger( arg ) ) {\n\t\t\t\tlen = arg;\n\t\t\t} else if ( isCollection( arg ) ) {\n\t\t\t\tlen = arg.length;\n\t\t\t}\n\t\t\tif ( len !== void 0 ) {\n\t\t\t\treturn filledArray( len, clbk, thisArg );\n\t\t\t}\n\t\t\tif ( isArrayBuffer( arg ) ) {\n\t\t\t\tthrow new Error( format('00h04') );\n\t\t\t}\n\t\t\tif ( isObject( arg ) ) {\n\t\t\t\tif ( HAS_ITERATOR_SYMBOL === false ) {\n\t\t\t\t\tthrow new TypeError( format( '00h2Z', arg ) );\n\t\t\t\t}\n\t\t\t\tif ( !isFunction( arg[ ITERATOR_SYMBOL ] ) ) {\n\t\t\t\t\tthrow new TypeError( format( '00h2a', arg ) );\n\t\t\t\t}\n\t\t\t\targ = arg[ ITERATOR_SYMBOL ]();\n\t\t\t\tif ( !isFunction( arg.next ) ) {\n\t\t\t\t\tthrow new TypeError( format( '00h2a', arg ) );\n\t\t\t\t}\n\t\t\t\treturn filledArrayIterator( arg, clbk, thisArg );\n\t\t\t}\n\t\t\tthrow new TypeError( format( '00h2a', arg ) );\n\t\t} else if ( isArrayBuffer( arg ) ) {\n\t\t\tthrow new Error( format('00h04') );\n\t\t}\n\t\tthrow new TypeError( format( '00h2a', arg ) );\n\t}\n\tif ( nargs === 0 ) { // length || array-like || ArrayBuffer || iterable\n\t\targ = arguments[ 0 ];\n\t\tif ( isCollection( arg ) ) {\n\t\t\tarr = new ctor( arg.length );\n\t\t} else if ( isArrayBuffer( arg ) ) {\n\t\t\tarr = new ctor( arg );\n\t\t} else if ( isNonNegativeInteger( arg ) ) {\n\t\t\tarr = new ctor( arg );\n\t\t} else if ( isObject( arg ) ) {\n\t\t\tif ( HAS_ITERATOR_SYMBOL === false ) {\n\t\t\t\tthrow new TypeError( format( '00h2Z', arg ) );\n\t\t\t}\n\t\t\tif ( !isFunction( arg[ ITERATOR_SYMBOL ] ) ) {\n\t\t\t\tthrow new TypeError( format( '00h2a', arg ) );\n\t\t\t}\n\t\t\targ = arg[ ITERATOR_SYMBOL ]();\n\t\t\tif ( !isFunction( arg.next ) ) {\n\t\t\t\tthrow new TypeError( format( '00h2a', arg ) );\n\t\t\t}\n\t\t\tarr = new ctor( iterLength( arg ) );\n\t\t} else {\n\t\t\tthrow new TypeError( format( '00h2a', arg ) );\n\t\t}\n\t} else if ( nargs === 1 ) {\n\t\tarr = new ctor( arguments[0], arguments[1] ); // (ArrayBuffer, byteOffset)\n\t} else {\n\t\tarr = new ctor( arguments[0], arguments[1], arguments[2] ); // (ArrayBuffer, byteOffset, length)\n\t}\n\tif ( arr.length > 0 ) {\n\t\tif ( isComplexDataType( dtype ) || isBooleanDataType( dtype ) ) {\n\t\t\tfilledAccessors( arr, clbk, thisArg );\n\t\t} else {\n\t\t\tgfillBy( arr.length, arr, 1, callback );\n\t\t}\n\t}\n\treturn arr;\n\n\t/**\n\t* Callback which wraps a provided callback and is invoked for each array element.\n\t*\n\t* @private\n\t* @param {*} value - element value\n\t* @param {NonNegativeInteger} aidx - array index\n\t* @param {NonNegativeInteger} sidx - strided index\n\t* @param {Collection} array - input array/collection\n\t* @returns {*} callback return value\n\t*/\n\tfunction callback( value, aidx ) {\n\t\treturn clbk.call( thisArg, aidx );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default filledarrayBy;\n"],"names":["HAS_ITERATOR_SYMBOL","hasIteratorSymbolSupport","DEFAULT_DTYPE","defaults","get","filledarrayBy","thisArg","nargs","dtype","clbk","ctor","arr","len","arg","arguments","length","ctors","isString","TypeError","format","isFunction","isNonNegativeInteger","isCollection","filledArray","isArrayBuffer","Error","isObject","ITERATOR_SYMBOL","next","it","i","done","push","call","filledArrayIterator","iterLength","isComplexDataType","isBooleanDataType","set","filledAccessors","gfillBy","value","aidx"],"mappings":";;sjDA0CA,IAAIA,EAAsBC,IACtBC,EAAgBC,EAASC,IAAK,kBA2MlC,SAASC,IACR,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAAe,KAHfN,EAAQO,UAAUC,QAKjB,OAAO,IADPL,EAAOM,EAAOd,IACG,GAIlB,GAAKe,EADLT,EAAQM,UAAW,IACM,CAExB,GAAKP,EAAQ,EACZ,MAAM,IAAIW,UAAWC,EAAO,UAG7B,GAAc,QADdT,EAAOM,EAAOR,IAEb,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAGvC,OAAO,IAAIE,EAAM,EACjB,CAED,GAAKH,EAAQ,EACZ,MAAM,IAAIW,UAAWC,EAAO,UAM7B,GAAKC,EAAYN,UAHjBP,GAAS,IAKR,GAAKa,EAAYN,UAAWP,EAAM,KAMjC,GALAD,EAAUQ,UAAWP,GAErBE,EAAOK,UADPP,GAAS,GAIM,IAAVA,EACJ,MAAM,IAAIW,UAAWC,EAAO,eAI7BV,EAAOK,UAAWP,OAIf,MAAKA,GAAS,GAUlB,MAAM,IAAIW,UAAWC,EAAO,UAN5B,GAHAb,EAAUQ,UAAWP,IAGfa,EADNX,EAAOK,UADPP,GAAS,IAGR,MAAM,IAAIW,UAAWC,EAAQ,QAASV,GAMvC,CAUD,IARAF,GAAS,IACK,GAAKU,EAAUH,UAAWP,KACvCC,EAAQM,UAAWP,GACnBA,GAAS,GAETC,EAAQN,EAGK,QADdQ,EAAOM,EAAOR,IAEb,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAGvC,GAAe,YAAVA,EAAsB,CAE1B,GADAK,EAAMC,UAAW,GACF,IAAVP,EAAc,CAMlB,GALKc,EAAsBR,GAC1BD,EAAMC,EACKS,EAAcT,KACzBD,EAAMC,EAAIE,aAEE,IAARH,EACJ,OAAOW,EAAaX,EAAKH,EAAMH,GAEhC,GAAKkB,EAAeX,GACnB,MAAM,IAAIY,MAAON,EAAO,UAEzB,GAAKO,EAAUb,GAAQ,CACtB,IAA6B,IAAxBb,EACJ,MAAM,IAAIkB,UAAWC,EAAQ,QAASN,IAEvC,IAAMO,EAAYP,EAAKc,IACtB,MAAM,IAAIT,UAAWC,EAAQ,QAASN,IAGvC,GADAA,EAAMA,EAAKc,MACLP,EAAYP,EAAIe,MACrB,MAAM,IAAIV,UAAWC,EAAQ,QAASN,IAEvC,OAvSJ,SAA8BgB,EAAIpB,EAAMH,GACvC,IAAIK,EACAmB,EAKJ,IAFAnB,EAAM,GACNmB,GAAK,GAEAD,EAAGD,OACAG,MAGPD,GAAK,EACLnB,EAAIqB,KAAMvB,EAAKwB,KAAM3B,EAASwB,IAE/B,OAAOnB,CACR,CAuRWuB,CAAqBrB,EAAKJ,EAAMH,EACvC,CACD,MAAM,IAAIY,UAAWC,EAAQ,QAASN,GACzC,CAAS,GAAKW,EAAeX,GAC1B,MAAM,IAAIY,MAAON,EAAO,UAEzB,MAAM,IAAID,UAAWC,EAAQ,QAASN,GACtC,CACD,GAAe,IAAVN,EAEJ,GAAKe,EADLT,EAAMC,UAAW,IAEhBH,EAAM,IAAID,EAAMG,EAAIE,aACd,GAAKS,EAAeX,GAC1BF,EAAM,IAAID,EAAMG,QACV,GAAKQ,EAAsBR,GACjCF,EAAM,IAAID,EAAMG,OACV,KAAKa,EAAUb,GAarB,MAAM,IAAIK,UAAWC,EAAQ,QAASN,IAZtC,IAA6B,IAAxBb,EACJ,MAAM,IAAIkB,UAAWC,EAAQ,QAASN,IAEvC,IAAMO,EAAYP,EAAKc,IACtB,MAAM,IAAIT,UAAWC,EAAQ,QAASN,IAGvC,GADAA,EAAMA,EAAKc,MACLP,EAAYP,EAAIe,MACrB,MAAM,IAAIV,UAAWC,EAAQ,QAASN,IAEvCF,EAAM,IAAID,EAAMyB,EAAYtB,GAG5B,MAEDF,EADqB,IAAVJ,EACL,IAAIG,EAAMI,UAAU,GAAIA,UAAU,IAElC,IAAIJ,EAAMI,UAAU,GAAIA,UAAU,GAAIA,UAAU,IASvD,OAPKH,EAAII,OAAS,IACZqB,EAAmB5B,IAAW6B,EAAmB7B,GAjTxD,SAA0BG,EAAKF,EAAMH,GACpC,IAAIwB,EACJ,IAAMA,EAAI,EAAGA,EAAInB,EAAII,OAAQe,IAC5BnB,EAAI2B,IAAK7B,EAAKwB,KAAM3B,EAASwB,GAAKA,EAGpC,CA4SGS,CAAiB5B,EAAKF,EAAMH,GAE5BkC,EAAS7B,EAAII,OAAQJ,EAAK,GAe5B,SAAmB8B,EAAOC,GACzB,OAAOjC,EAAKwB,KAAM3B,EAASoC,EAC3B,KAdM/B,CAeR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index d115cf0..0000000 --- a/lib/index.js +++ /dev/null @@ -1,192 +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. -*/ - -'use strict'; - -/** -* Create a filled array according to a provided callback function. -* -* @module @stdlib/array-filled-by -* -* @example -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* var arr = filledarrayBy(); -* // returns -* -* @example -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk() { -* return 1.0; -* } -* -* var arr = filledarrayBy( 2, clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk() { -* return 1.0; -* } -* -* var arr = filledarrayBy( 2, 'float32', clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk() { -* return 1.0; -* } -* -* var arr = filledarrayBy( 2, 'generic', clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk() { -* return 1.0; -* } -* -* var arr = filledarrayBy( [ 0.5, 0.5 ], clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk() { -* return 1; -* } -* -* var arr = filledarrayBy( [ 5, -3 ], 'int32', clbk ); -* // returns [ 1, 1 ] -* -* @example -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk1() { -* return 10; -* } -* -* function clbk2() { -* return 1.0; -* } -* -* var arr1 = filledarrayBy( [ 5, 3 ], 'int32', clbk1 ); -* var arr2 = filledarrayBy( arr1, clbk2 ); -* // returns [ 1.0, 1.0 ] -* -* @example -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk1() { -* return 1.0; -* } -* -* function clbk2() { -* return 2; -* } -* -* var arr1 = filledarrayBy( [ 5, 3 ], 'int32', clbk1 ); -* var arr2 = filledarrayBy( arr1, 'uint32', clbk2 ); -* // returns [ 2, 2 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk() { -* return 1.0; -* } -* -* var buf = new ArrayBuffer( 16 ); -* var arr = filledarrayBy( buf, clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk() { -* return 1.0; -* } -* -* var buf = new ArrayBuffer( 16 ); -* var arr = filledarrayBy( buf, 'float32', clbk ); -* // returns [ 1.0, 1.0, 1.0, 1.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk() { -* return 1.0; -* } -* -* var buf = new ArrayBuffer( 16 ); -* var arr = filledarrayBy( buf, 8, clbk ); -* // returns [ 1.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk() { -* return 1.0; -* } -* -* var buf = new ArrayBuffer( 16 ); -* var arr = filledarrayBy( buf, 8, 'float32', clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk() { -* return 1.0; -* } -* -* var buf = new ArrayBuffer( 32 ); -* var arr = filledarrayBy( buf, 8, 2, clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* var filledarrayBy = require( '@stdlib/array-filled-by' ); -* -* function clbk() { -* return 1; -* } -* -* var buf = new ArrayBuffer( 32 ); -* var arr = filledarrayBy( buf, 8, 2, 'int32', clbk ); -* // returns [ 1, 1 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index d2128f5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,416 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isObject = require( '@stdlib/assert-is-object' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ctors = require( '@stdlib/array-ctors' ); -var gfillBy = require( '@stdlib/blas-ext-base-gfill-by' ); -var filledArray = require( '@stdlib/array-base-filled-by' ); -var hasIteratorSymbolSupport = require( '@stdlib/assert-has-iterator-symbol-support' ); -var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' ); -var iterLength = require( '@stdlib/iter-length' ); -var defaults = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); - - -// VARIABLES // - -var HAS_ITERATOR_SYMBOL = hasIteratorSymbolSupport(); -var DEFAULT_DTYPE = defaults.get( 'dtypes.default' ); - - -// FUNCTIONS // - -/** -* Creates a filled "generic" array from an iterator. -* -* @private -* @param {Iterable} it - iterator -* @param {Callback} clbk - callback function -* @param {*} thisArg - callback function execution context -* @returns {Array} filled array -*/ -function filledArrayIterator( it, clbk, thisArg ) { - var arr; - var i; - var v; - - arr = []; - i = -1; - while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - i += 1; - arr.push( clbk.call( thisArg, i ) ); - } - return arr; -} - -/** -* Fills an array exposing accessors for getting and setting array elements. -* -* @private -* @param {Collection} arr - input array -* @param {Callback} clbk - callback function -* @param {*} thisArg - callback function execution context -* @returns {Collection} input array -*/ -function filledAccessors( arr, clbk, thisArg ) { - var i; - for ( i = 0; i < arr.length; i++ ) { - arr.set( clbk.call( thisArg, i ), i ); - } - return arr; -} - - -// MAIN // - -/** -* Creates a filled array according to a provided callback function. -* -* @param {(NonNegativeInteger|TypedArray|ArrayLikeObject|ArrayBuffer|Iterable)} [arg] - a length, typed array, array-like object, buffer, or iterable -* @param {NonNegativeInteger} [byteOffset=0] - byte offset -* @param {NonNegativeInteger} [length] - view length -* @param {string} [dtype="float64"] - data type -* @param {Callback} [clbk] - callback to invoke -* @param {*} [thisArg] - callback execution context -* @throws {TypeError} must provide a recognized data type -* @throws {TypeError} must provide a length, typed array, array-like object, buffer, or iterable -* @throws {TypeError} callback argument must be a function. -* @throws {Error} creating a generic array from an `ArrayBuffer` is not supported -* @returns {(TypedArray|Array)} array or typed array -* -* @example -* var arr = filledarrayBy(); -* // returns -* -* @example -* function clbk() { -* return 1.0; -* } -* -* var arr = filledarrayBy( 2, clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* function clbk() { -* return 1.0; -* } -* -* var arr = filledarrayBy( 2, 'float32', clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* function clbk() { -* return 1.0; -* } -* -* var arr = filledarrayBy( 2, 'generic', clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* function clbk() { -* return 1.0; -* } -* -* var arr = filledarrayBy( [ 0.5, 0.5 ], clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* function clbk() { -* return 1; -* } -* -* var arr = filledarrayBy( [ 5, -3 ], 'int32', clbk ); -* // returns [ 1, 1 ] -* -* @example -* function clbk1() { -* return 10; -* } -* -* function clbk2() { -* return 1.0; -* } -* -* var arr1 = filledarrayBy( [ 5, 3 ], 'int32', clbk1 ); -* var arr2 = filledarrayBy( arr1, clbk2 ); -* // returns [ 1.0, 1.0 ] -* -* @example -* function clbk1() { -* return 1.0; -* } -* -* function clbk2() { -* return 2; -* } -* -* var arr1 = filledarrayBy( [ 5, 3 ], 'int32', clbk1 ); -* var arr2 = filledarrayBy( arr1, 'uint32', clbk2 ); -* // returns [ 2, 2 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* -* function clbk() { -* return 1.0; -* } -* -* var buf = new ArrayBuffer( 16 ); -* var arr = filledarrayBy( buf, clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* -* function clbk() { -* return 1.0; -* } -* -* var buf = new ArrayBuffer( 16 ); -* var arr = filledarrayBy( buf, 'float32', clbk ); -* // returns [ 1.0, 1.0, 1.0, 1.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* -* function clbk() { -* return 1.0; -* } -* -* var buf = new ArrayBuffer( 16 ); -* var arr = filledarrayBy( buf, 8, clbk ); -* // returns [ 1.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* -* function clbk() { -* return 1.0; -* } -* -* var buf = new ArrayBuffer( 16 ); -* var arr = filledarrayBy( buf, 8, 'float32', clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* -* function clbk() { -* return 1.0; -* } -* -* var buf = new ArrayBuffer( 32 ); -* var arr = filledarrayBy( buf, 8, 2, clbk ); -* // returns [ 1.0, 1.0 ] -* -* @example -* var ArrayBuffer = require( '@stdlib/array-buffer' ); -* -* function clbk() { -* return 1; -* } -* -* var buf = new ArrayBuffer( 32 ); -* var arr = filledarrayBy( buf, 8, 2, 'int32', clbk ); -* // returns [ 1, 1 ] -*/ -function filledarrayBy() { - var thisArg; - var nargs; - var dtype; - var clbk; - var ctor; - var arr; - var len; - var arg; - - nargs = arguments.length; - - // If we weren't provided any arguments, return an empty array... - if ( nargs === 0 ) { - ctor = ctors( DEFAULT_DTYPE ); - return new ctor( 0 ); - } - // Check if we were provided a dtype as the first argument... - dtype = arguments[ 0 ]; - if ( isString( dtype ) ) { - // Invoking this function with arguments `f( dtype, clbk[, thisArg] )` is not allowed (otherwise, we'd need to also allow `f( clbk[, thisArg] )`)... - if ( nargs > 1 ) { - throw new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' ); - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); - } - // Return an empty array having the specified dtype: - return new ctor( 0 ); - } - // For all other supported invocations, we need at least two arguments... - if ( nargs < 2 ) { - throw new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' ); - } - // At this point, we need to do some argument juggling... - nargs -= 1; // henceforth, the number of available arguments is `nargs+1` - - // Determine whether the last argument is a callback or "this" context... - if ( isFunction( arguments[ nargs ] ) ) { - // If the last argument is a function, we need to check the next-to-last argument, and, if the next-to-last argument is a function, assume that the next-to-last argument is the callback and the last argument is a "this" context... - if ( isFunction( arguments[ nargs-1 ] ) ) { - thisArg = arguments[ nargs ]; - nargs -= 1; - clbk = arguments[ nargs ]; - - // Check if we were provided only a callback and a "this" context.. - if ( nargs === 0 ) { - throw new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' ); - } - } else { - // "this" context is left undefined... - clbk = arguments[ nargs ]; - } - } - // If we were provided 3 or more arguments and the last argument was not a function, assume that we were provided a callback and a "this" context... - else if ( nargs >= 2 ) { - thisArg = arguments[ nargs ]; - nargs -= 1; - clbk = arguments[ nargs ]; - if ( !isFunction( clbk ) ) { - throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); - } - } - // If we were only provided 2 arguments and the last argument was not a function, we've been provided an insufficient number of arguments... - else { - throw new TypeError( 'invalid arguments. Must provide a length, typed array, array-like object, or an iterable.' ); - } - // Now that we've processed the callback arguments, let's continue working backward to see if we've been provided a `dtype` argument... - nargs -= 1; - if ( nargs >= 0 && isString( arguments[ nargs ] ) ) { - dtype = arguments[ nargs ]; - nargs -= 1; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); - } - // At this point, we've resolved the output array data type, and now we can actually create the output array... - if ( dtype === 'generic' ) { - arg = arguments[ 0 ]; - if ( nargs === 0 ) { - if ( isNonNegativeInteger( arg ) ) { - len = arg; - } else if ( isCollection( arg ) ) { - len = arg.length; - } - if ( len !== void 0 ) { - return filledArray( len, clbk, thisArg ); - } - if ( isArrayBuffer( arg ) ) { - throw new Error( 'invalid arguments. Creating a generic array from an ArrayBuffer is not supported.' ); - } - if ( isObject( arg ) ) { - if ( HAS_ITERATOR_SYMBOL === false ) { - throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, typed array, or array-like object. Value: `%s`.', arg ) ); - } - if ( !isFunction( arg[ ITERATOR_SYMBOL ] ) ) { - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); - } - arg = arg[ ITERATOR_SYMBOL ](); - if ( !isFunction( arg.next ) ) { - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); - } - return filledArrayIterator( arg, clbk, thisArg ); - } - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); - } else if ( isArrayBuffer( arg ) ) { - throw new Error( 'invalid arguments. Creating a generic array from an ArrayBuffer is not supported.' ); - } - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); - } - if ( nargs === 0 ) { // length || array-like || ArrayBuffer || iterable - arg = arguments[ 0 ]; - if ( isCollection( arg ) ) { - arr = new ctor( arg.length ); - } else if ( isArrayBuffer( arg ) ) { - arr = new ctor( arg ); - } else if ( isNonNegativeInteger( arg ) ) { - arr = new ctor( arg ); - } else if ( isObject( arg ) ) { - if ( HAS_ITERATOR_SYMBOL === false ) { - throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, typed array, or array-like object. Value: `%s`.', arg ) ); - } - if ( !isFunction( arg[ ITERATOR_SYMBOL ] ) ) { - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); - } - arg = arg[ ITERATOR_SYMBOL ](); - if ( !isFunction( arg.next ) ) { - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); - } - arr = new ctor( iterLength( arg ) ); - } else { - throw new TypeError( format( 'invalid argument. Must provide a length, typed array, array-like object, or an iterable. Value: `%s`.', arg ) ); - } - } else if ( nargs === 1 ) { - arr = new ctor( arguments[0], arguments[1] ); // (ArrayBuffer, byteOffset) - } else { - arr = new ctor( arguments[0], arguments[1], arguments[2] ); // (ArrayBuffer, byteOffset, length) - } - if ( arr.length > 0 ) { - if ( isComplexDataType( dtype ) || isBooleanDataType( dtype ) ) { - filledAccessors( arr, clbk, thisArg ); - } else { - gfillBy( arr.length, arr, 1, callback ); - } - } - return arr; - - /** - * Callback which wraps a provided callback and is invoked for each array element. - * - * @private - * @param {*} value - element value - * @param {NonNegativeInteger} aidx - array index - * @param {NonNegativeInteger} sidx - strided index - * @param {Collection} array - input array/collection - * @returns {*} callback return value - */ - function callback( value, aidx ) { - return clbk.call( thisArg, aidx ); - } -} - - -// EXPORTS // - -module.exports = filledarrayBy; diff --git a/package.json b/package.json index b1d16c6..026d062 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.3.1", "description": "Create a filled array according to a provided callback function.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,75 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.2", - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.2", - "@stdlib/array-base-filled-by": "^0.2.3", - "@stdlib/array-ctors": "^0.3.1", - "@stdlib/array-defaults": "^0.4.1", - "@stdlib/assert-has-iterator-symbol-support": "^0.2.3", - "@stdlib/assert-is-arraybuffer": "^0.2.3", - "@stdlib/assert-is-collection": "^0.2.3", - "@stdlib/assert-is-function": "^0.2.3", - "@stdlib/assert-is-nonnegative-integer": "^0.2.3", - "@stdlib/assert-is-object": "^0.2.3", - "@stdlib/assert-is-string": "^0.2.3", - "@stdlib/blas-ext-base-gfill-by": "^0.2.3", - "@stdlib/iter-length": "^0.2.3", - "@stdlib/string-format": "^0.2.3", - "@stdlib/symbol-iterator": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-bool": "^0.1.2", - "@stdlib/array-buffer": "^0.2.3", - "@stdlib/array-complex128": "^0.3.2", - "@stdlib/array-complex64": "^0.3.2", - "@stdlib/array-float32": "^0.2.3", - "@stdlib/array-float64": "^0.2.3", - "@stdlib/array-int16": "^0.2.3", - "@stdlib/array-int32": "^0.2.3", - "@stdlib/array-int8": "^0.2.3", - "@stdlib/array-typed-real-dtypes": "^0.2.3", - "@stdlib/array-uint16": "^0.2.3", - "@stdlib/array-uint32": "^0.2.3", - "@stdlib/array-uint8": "^0.2.3", - "@stdlib/array-uint8c": "^0.2.3", - "@stdlib/assert-instance-of": "^0.3.1", - "@stdlib/assert-is-array": "^0.2.3", - "@stdlib/assert-is-typed-array": "^0.2.3", - "@stdlib/assert-is-typed-array-like": "^0.2.3", - "@stdlib/complex-float32-ctor": "^0.1.1", - "@stdlib/complex-float64-ctor": "^0.1.2", - "@stdlib/iter-constant": "^0.2.3", - "@stdlib/math-base-special-pow": "^0.3.1", - "@stdlib/random-base-discrete-uniform": "^0.2.2", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.3", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.3", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.2", - "@stdlib/utils-constant-function": "^0.2.3", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dabf69c --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca0cf25..0000000 --- a/test/test.js +++ /dev/null @@ -1,4397 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-len */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var iterConstant = require( '@stdlib/iter-constant' ); -var constantFunction = require( '@stdlib/utils-constant-function' ); -var hasIteratorSymbolSupport = require( '@stdlib/assert-has-iterator-symbol-support' ); -var filledarrayBy = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': !hasIteratorSymbolSupport() -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof filledarrayBy, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if only provided callback arguments', function test( t ) { - t.throws( clbk1, TypeError, 'throws an error' ); - t.throws( clbk2, TypeError, 'throws an error' ); - t.throws( clbk3, TypeError, 'throws an error' ); - t.end(); - - function clbk1() { - filledarrayBy( constantFunction( 1.0 ) ); - } - - function clbk2() { - filledarrayBy( constantFunction( 1.0 ), {} ); - } - - function clbk3() { - filledarrayBy( constantFunction( 1.0 ), constantFunction( 1.0 ) ); - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (length; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( 10, value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (typed array; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( new Float64Array( 10 ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (array-like object; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( [ 1, 2, 3 ], value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (arraybuffer)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 8 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (arraybuffer; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 8 ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (arraybuffer, byteoffset)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 16 ), 8, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (arraybuffer, byteoffset; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 16 ), 8, value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (arraybuffer, byteoffset, length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 16 ), 8, 1, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (arraybuffer, byteoffset, length; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 16 ), 8, 1, value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (iterator)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( iterConstant( 1.0 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid callback argument (iterator; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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() { - filledarrayBy( iterConstant( 1.0 ), value, {} ); - }; - } -}); - -tape( 'the function throws an error if only provided data type and callback arguments', function test( t ) { - t.throws( clbk1, TypeError, 'throws an error' ); - t.throws( clbk2, TypeError, 'throws an error' ); - t.throws( clbk3, TypeError, 'throws an error' ); - t.end(); - - function clbk1() { - filledarrayBy( 'float64', constantFunction( 1.0 ) ); - } - - function clbk2() { - filledarrayBy( 'float64', constantFunction( 1.0 ), {} ); - } - - function clbk3() { - filledarrayBy( 'float64', constantFunction( 1.0 ), constantFunction( 1.0 ) ); - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( 10, value, constantFunction( 1.0 ) ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( 10, value, constantFunction( 1.0 ), {} ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( new Float64Array( 10 ), value, constantFunction( 1.0 ) ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( new Float64Array( 10 ), value, constantFunction( 1.0 ), {} ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( [ 1, 2, 3 ], value, constantFunction( 1.0 ) ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( [ 1, 2, 3 ], value, constantFunction( 1.0 ), {} ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 16 ), value, constantFunction( 1.0 ) ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 16 ), value, constantFunction( 1.0 ), {} ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer, byteOffset)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 16 ), 0, value, constantFunction( 1.0 ) ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer, byteOffset; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 16 ), 0, value, constantFunction( 1.0 ), {} ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer, byteOffset, length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 16 ), 0, 1, value, constantFunction( 1.0 ) ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (ArrayBuffer, byteOffset, length; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'filledarrayBy', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32', - 'GENERIC' - ]; - - 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() { - filledarrayBy( new ArrayBuffer( 16 ), 0, 1, value, constantFunction( 1.0 ), {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a generic array', function test( t ) { - var values; - var i; - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'generic', constantFunction( 1.0 ) ); - }; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a generic array (thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'generic', constantFunction( 1.0 ), {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a generic array (no iterator symbol support)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport - }); - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'generic', constantFunction( 1.0 ) ); - }; - } - - function hasSupport() { - return false; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a generic array (no iterator symbol support; thisArg)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport - }); - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'generic', constantFunction( 1.0 ), {} ); - }; - } - - function hasSupport() { - return false; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a generic array (iterator symbol support)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport - }); - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'generic', constantFunction( 1.0 ) ); - }; - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a generic array (iterator symbol support; thisArg)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport - }); - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'generic', constantFunction( 1.0 ), {} ); - }; - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided a valid iterable when attempting to create a generic array (non-function iterator symbol property)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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 obj = { - '__ITERATOR_SYMBOL__': value - }; - filledarrayBy( obj, 'generic', constantFunction( 1.0 ) ); - }; - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided a valid iterable when attempting to create a generic array (non-function iterator symbol property; thisArg)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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 obj = { - '__ITERATOR_SYMBOL__': value - }; - filledarrayBy( obj, 'generic', constantFunction( 1.0 ), {} ); - }; - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided a valid iterable when attempting to create a generic array (`next` property is not a function)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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 obj = { - '__ITERATOR_SYMBOL__': iterator - }; - filledarrayBy( obj, 'generic', constantFunction( 1.0 ) ); - }; - - function iterator() { - return { - 'next': value - }; - } - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided a valid iterable when attempting to create a generic array (`next` property is not a function; thisArg)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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 obj = { - '__ITERATOR_SYMBOL__': iterator - }; - filledarrayBy( obj, 'generic', constantFunction( 1.0 ), {} ); - }; - - function iterator() { - return { - 'next': value - }; - } - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a typed array', function test( t ) { - var values; - var i; - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'float64', constantFunction( 1.0 ) ); - }; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a typed array (thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'float64', constantFunction( 1.0 ), {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a typed array (no iterator symbol support)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport - }); - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'float64', constantFunction( 1.0 ) ); - }; - } - - function hasSupport() { - return false; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a typed array (no iterator symbol support; thisArg)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport - }); - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'float64', constantFunction( 1.0 ), {} ); - }; - } - - function hasSupport() { - return false; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a typed array (iterator symbol support)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport - }); - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'float64', constantFunction( 1.0 ) ); - }; - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided a length, typed array, array-like object, or an iterable when attempting to create a typed array (iterator symbol support; thisArg)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport - }); - - values = [ - '5', - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 'float64', constantFunction( 1.0 ), {} ); - }; - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided a valid iterable when attempting to create a typed array (non-function iterator symbol property)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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 obj = { - '__ITERATOR_SYMBOL__': value - }; - filledarrayBy( obj, 'float64', constantFunction( 1.0 ) ); - }; - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided a valid iterable when attempting to create a typed array (non-function iterator symbol property; thisArg)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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 obj = { - '__ITERATOR_SYMBOL__': value - }; - filledarrayBy( obj, 'float64', constantFunction( 1.0 ), {} ); - }; - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided a valid iterable when attempting to create a typed array (`next` property is not a function)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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 obj = { - '__ITERATOR_SYMBOL__': iterator - }; - filledarrayBy( obj, 'float64', constantFunction( 1.0 ) ); - }; - - function iterator() { - return { - 'next': value - }; - } - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided a valid iterable when attempting to create a typed array (`next` property is not a function; thisArg)', function test( t ) { - var filledarrayBy; - var values; - var i; - - filledarrayBy = proxyquire( './../lib/main.js', { - '@stdlib/assert-has-iterator-symbol-support': hasSupport, - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [] - ]; - - 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 obj = { - '__ITERATOR_SYMBOL__': iterator - }; - filledarrayBy( obj, 'float64', constantFunction( 1.0 ), {} ); - }; - - function iterator() { - return { - 'next': value - }; - } - } - - function hasSupport() { - return true; - } -}); - -tape( 'the function throws an error if not provided valid arguments when attempting to create a generic array (arraybuffer, byteoffset)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 1, 'generic', constantFunction( 1.0 ) ); - }; - } -}); - -tape( 'the function throws an error if not provided valid arguments when attempting to create a generic array (arraybuffer, byteoffset; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 1, 'generic', constantFunction( 1.0 ), {} ); - }; - } -}); - -tape( 'the function throws an error if not provided valid arguments when attempting to create a generic array (arraybuffer, byteoffset, length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 1, 1, 'generic', constantFunction( 1.0 ) ); - }; - } -}); - -tape( 'the function throws an error if not provided valid arguments when attempting to create a generic array (arraybuffer, byteoffset, length; thisArg)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - true, - false, - null, - void 0, - {}, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - filledarrayBy( value, 1, 1, 'generic', constantFunction( 1.0 ), {} ); - }; - } -}); - -tape( 'the function returns a filled array (default)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( 0 ); - arr = filledarrayBy(); - - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float64)', function test( t ) { - var expected; - var arr; - - expected = new Float64Array( 0 ); - arr = filledarrayBy( 'float64' ); - - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float32)', function test( t ) { - var expected; - var arr; - - expected = new Float32Array( 0 ); - arr = filledarrayBy( 'float32' ); - - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=bool)', function test( t ) { - var expected; - var arr; - - expected = new BooleanArray( 0 ); - arr = filledarrayBy( 'bool' ); - - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex128)', function test( t ) { - var expected; - var arr; - - expected = new Complex128Array( 0 ); - arr = filledarrayBy( 'complex128' ); - - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex64)', function test( t ) { - var expected; - var arr; - - expected = new Complex64Array( 0 ); - arr = filledarrayBy( 'complex64' ); - - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int32)', function test( t ) { - var expected; - var arr; - - expected = new Int32Array( 0 ); - arr = filledarrayBy( 'int32' ); - - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint32)', function test( t ) { - var expected; - var arr; - - expected = new Uint32Array( 0 ); - arr = filledarrayBy( 'uint32' ); - - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int16)', function test( t ) { - var expected; - var arr; - - expected = new Int16Array( 0 ); - arr = filledarrayBy( 'int16' ); - - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint16)', function test( t ) { - var expected; - var arr; - - expected = new Uint16Array( 0 ); - arr = filledarrayBy( 'uint16' ); - - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int8)', function test( t ) { - var expected; - var arr; - - expected = new Int8Array( 0 ); - arr = filledarrayBy( 'int8' ); - - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8)', function test( t ) { - var expected; - var arr; - - expected = new Uint8Array( 0 ); - arr = filledarrayBy( 'uint8' ); - - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8c)', function test( t ) { - var expected; - var arr; - - expected = new Uint8ClampedArray( 0 ); - arr = filledarrayBy( 'uint8c' ); - - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = []; - arr = filledarrayBy( 'generic' ); - - t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (default, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = filledarrayBy( 5, clbk ); - - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (default, length=0)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Float64Array(); - - clbk = constantFunction( 1.0 ); - arr = filledarrayBy( 0, clbk ); - - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (default, length; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var arr; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - - indices = []; - ctx = { - 'count': 0 - }; - arr = filledarrayBy( 5, clbk, ctx ); - - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - expected = [ 0, 1, 2, 3, 4 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled array (default, length; thisArg=function)', function test( t ) { - var expected; - var indices; - var ctx; - var arr; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - - indices = []; - ctx = { - 'count': 0 - }; - arr = filledarrayBy( 5, clbk, context ); - - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - expected = [ 0, 1, 2, 3, 4 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this(); // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } - - function context() { - ctx.count += 1; - } -}); - -tape( 'the function returns a filled array (dtype=float64, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = filledarrayBy( 5, 'float64', clbk ); - - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float64, length; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var arr; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - - indices = []; - ctx = { - 'count': 0 - }; - arr = filledarrayBy( 5, 'float64', clbk, ctx ); - - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - expected = [ 0, 1, 2, 3, 4 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled array (dtype=float64, length; thisArg=function)', function test( t ) { - var expected; - var indices; - var ctx; - var arr; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - - indices = []; - ctx = { - 'count': 0 - }; - arr = filledarrayBy( 5, 'float64', clbk, context ); - - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - expected = [ 0, 1, 2, 3, 4 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this(); // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } - - function context() { - ctx.count += 1; - } -}); - -tape( 'the function returns a filled array (dtype=float32, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = filledarrayBy( 5, 'float32', clbk ); - - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=bool, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Uint8Array( [ 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( true ); - arr = filledarrayBy( 5, 'bool', clbk ); - - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( reinterpretBoolean( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex128, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex128( 1.0, 1.0 ) ); - arr = filledarrayBy( 5, 'complex128', clbk ); - - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex64, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex64( 1.0, 1.0 ) ); - arr = filledarrayBy( 5, 'complex64', clbk ); - - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( arr, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int32, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Int32Array( [ 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = filledarrayBy( 5, 'int32', clbk ); - - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint32, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Uint32Array( [ 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = filledarrayBy( 5, 'uint32', clbk ); - - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int16, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Int16Array( [ 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = filledarrayBy( 5, 'int16', clbk ); - - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint16, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Uint16Array( [ 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = filledarrayBy( 5, 'uint16', clbk ); - - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int8, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Int8Array( [ 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = filledarrayBy( 5, 'int8', clbk ); - - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Uint8Array( [ 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = filledarrayBy( 5, 'uint8', clbk ); - - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8c, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = new Uint8ClampedArray( [ 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = filledarrayBy( 5, 'uint8c', clbk ); - - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=generic, length)', function test( t ) { - var expected; - var clbk; - var arr; - - expected = [ 1, 1, 1, 1, 1 ]; - - clbk = constantFunction( 1 ); - arr = filledarrayBy( 5, 'generic', clbk ); - - t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (default, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (default, array; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - ctx = { - 'count': 0 - }; - indices = []; - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0, 1, 2 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled array (dtype=float64, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, 'float64', clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float64, array; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - ctx = { - 'count': 0 - }; - indices = []; - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, 'float64', clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0, 1, 2 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled array (dtype=float32, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float32Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, 'float32', clbk ); - - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=bool, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint8Array( [ 0, 0, 0, 0 ] ); - - clbk = constantFunction( false ); - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = filledarrayBy( arr, 'bool', clbk ); - - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( reinterpretBoolean( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex128, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex128( 1.0, 1.0 ) ); - arr = [ 1.0, 2.0 ]; - out = filledarrayBy( arr, 'complex128', clbk ); - - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex64, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex64( 1.0, 1.0 ) ); - arr = [ 1.0, 2.0 ]; - out = filledarrayBy( arr, 'complex64', clbk ); - - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int32, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Int32Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, 'int32', clbk ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint32, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint32Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, 'uint32', clbk ); - - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int16, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Int16Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, 'int16', clbk ); - - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint16, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint16Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, 'uint16', clbk ); - - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int8, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Int8Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, 'int8', clbk ); - - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint8Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, 'uint8', clbk ); - - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8c, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint8ClampedArray( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, 'uint8c', clbk ); - - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=generic, array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = [ 1.0, 1.0, 1.0 ]; - - clbk = constantFunction( 1.0 ); - arr = [ 1.0, 2.0, 3.0 ]; - out = filledarrayBy( arr, 'generic', clbk ); - - t.strictEqual( instanceOf( out, Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (default, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (default, typed array; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - ctx = { - 'count': 0 - }; - indices = []; - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0, 1, 2 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled array (dtype=float64, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, 'float64', clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float64, typed array; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - ctx = { - 'count': 0 - }; - indices = []; - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0, 1, 2 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled array (dtype=float32, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float32Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, 'float32', clbk ); - - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=bool, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint8Array( [ 1, 1, 1, 1 ] ); - - clbk = constantFunction( true ); - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = filledarrayBy( arr, 'bool', clbk ); - - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( reinterpretBoolean( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex128, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex128( 1.0, 1.0 ) ); - arr = new Float64Array( [ 1.0, 2.0 ] ); - out = filledarrayBy( arr, 'complex128', clbk ); - - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex64, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex64( 1.0, 1.0 ) ); - arr = new Float64Array( [ 1.0, 2.0 ] ); - out = filledarrayBy( arr, 'complex64', clbk ); - - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int32, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Int32Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, 'int32', clbk ); - - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint32, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint32Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, 'uint32', clbk ); - - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int16, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Int16Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, 'int16', clbk ); - - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint16, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint16Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, 'uint16', clbk ); - - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int8, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Int8Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, 'int8', clbk ); - - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint8Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, 'uint8', clbk ); - - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8c, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint8ClampedArray( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, 'uint8c', clbk ); - - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=generic, typed array)', function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = [ 1.0, 1.0, 1.0 ]; - - clbk = constantFunction( 1.0 ); - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = filledarrayBy( arr, 'generic', clbk ); - - t.strictEqual( instanceOf( out, Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (default, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float64Array( [ 1.0 ] ); - - clbk = constantFunction( 1.0 ); - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (default, arraybuffer; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var buf; - var out; - - expected = new Float64Array( [ 1.0 ] ); - - ctx = { - 'count': 0 - }; - indices = []; - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled typed array (dtype=float64, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float64Array( [ 1.0 ] ); - - clbk = constantFunction( 1.0 ); - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, 'float64', clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float64, arraybuffer; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var buf; - var out; - - expected = new Float64Array( [ 1.0 ] ); - - ctx = { - 'count': 0 - }; - indices = []; - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, 'float64', clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled typed array (dtype=float32, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float32Array( [ 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, 'float32', clbk ); - - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=bool, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint8Array( [ 0, 0, 0, 0 ] ); - - clbk = constantFunction( false ); - buf = new ArrayBuffer( 4 ); - out = filledarrayBy( buf, 'bool', clbk ); - - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( reinterpretBoolean( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=complex128, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex128( 1.0, 1.0 ) ); - buf = new ArrayBuffer( 32 ); - out = filledarrayBy( buf, 'complex128', clbk ); - - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=complex64, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex64( 1.0, 1.0 ) ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 'complex64', clbk ); - - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=int32, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Int32Array( [ 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, 'int32', clbk ); - - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint32, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint32Array( [ 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, 'uint32', clbk ); - - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=int16, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Int16Array( [ 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, 'int16', clbk ); - - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint16, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint16Array( [ 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, 'uint16', clbk ); - - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=int8, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Int8Array( [ 1, 1, 1, 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, 'int8', clbk ); - - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint8, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint8Array( [ 1, 1, 1, 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, 'uint8', clbk ); - - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint8c, arraybuffer)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint8ClampedArray( [ 1, 1, 1, 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, 'uint8c', clbk ); - - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided an ArrayBuffer when attempting to create a generic array (dtype=generic, arraybuffer)', function test( t ) { - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - var buf = new ArrayBuffer( 8 ); - return filledarrayBy( buf, 'generic', constantFunction( 1.0 ) ); - } -}); - -tape( 'the function throws an error if provided an ArrayBuffer when attempting to create a generic array (dtype=generic, arraybuffer; thisArg)', function test( t ) { - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - var buf = new ArrayBuffer( 8 ); - return filledarrayBy( buf, 'generic', constantFunction( 1.0 ), {} ); - } -}); - -tape( 'the function returns a filled typed array (default, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - buf = new ArrayBuffer( 32 ); - out = filledarrayBy( buf, 8, clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (default, arraybuffer, byteoffset; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var buf; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - ctx = { - 'count': 0 - }; - indices = []; - buf = new ArrayBuffer( 32 ); - out = filledarrayBy( buf, 8, clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0, 1, 2 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled typed array (dtype=float64, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - buf = new ArrayBuffer( 32 ); - out = filledarrayBy( buf, 8, 'float64', clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float64, arraybuffer, byteoffset; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var buf; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - ctx = { - 'count': 0 - }; - indices = []; - buf = new ArrayBuffer( 32 ); - out = filledarrayBy( buf, 8, 'float64', clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0, 1, 2 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled typed array (dtype=float32, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float32Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 'float32', clbk ); - - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=bool, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint8Array( [ 1, 1, 1, 1 ] ); - - clbk = constantFunction( true ); - buf = new ArrayBuffer( 6 ); - out = filledarrayBy( buf, 2, 'bool', clbk ); - - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( reinterpretBoolean( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=complex128, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex128( 1.0, 1.0 ) ); - buf = new ArrayBuffer( 48 ); - out = filledarrayBy( buf, 16, 'complex128', clbk ); - - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=complex64, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex64( 1.0, 1.0 ) ); - buf = new ArrayBuffer( 24 ); - out = filledarrayBy( buf, 8, 'complex64', clbk ); - - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=int32, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Int32Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 'int32', clbk ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint32, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint32Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 'uint32', clbk ); - - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=int16, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Int16Array( [ 1, 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 'int16', clbk ); - - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint16, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint16Array( [ 1, 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 'uint16', clbk ); - - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=int8, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Int8Array( [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 'int8', clbk ); - - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint8, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint8Array( [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 'uint8', clbk ); - - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint8c, arraybuffer, byteoffset)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint8ClampedArray( [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 'uint8c', clbk ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided an ArrayBuffer when attempting to create a generic array (dtype=generic, arraybuffer, byteoffset)', function test( t ) { - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - var buf = new ArrayBuffer( 8 ); - return filledarrayBy( buf, 4, 'generic', constantFunction( 1.0 ) ); - } -}); - -tape( 'the function throws an error if provided an ArrayBuffer when attempting to create a generic array (dtype=generic, arraybuffer, byteoffset; thisArg)', function test( t ) { - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - var buf = new ArrayBuffer( 8 ); - return filledarrayBy( buf, 4, 'generic', constantFunction( 1.0 ), {} ); - } -}); - -tape( 'the function returns a filled typed array (default, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float64Array( [ 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - buf = new ArrayBuffer( 32 ); - out = filledarrayBy( buf, 8, 2, clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (default, arraybuffer, byteoffset, length; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var buf; - var out; - - expected = new Float64Array( [ 1.0, 1.0 ] ); - - ctx = { - 'count': 0 - }; - indices = []; - buf = new ArrayBuffer( 32 ); - out = filledarrayBy( buf, 8, 2, clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0, 1 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled typed array (dtype=float64, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float64Array( [ 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - buf = new ArrayBuffer( 32 ); - out = filledarrayBy( buf, 8, 2, 'float64', clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float64, arraybuffer, byteoffset, length; thisArg)', function test( t ) { - var expected; - var indices; - var ctx; - var buf; - var out; - - expected = new Float64Array( [ 1.0, 1.0 ] ); - - ctx = { - 'count': 0 - }; - indices = []; - buf = new ArrayBuffer( 32 ); - out = filledarrayBy( buf, 8, 2, 'float64', clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0, 1 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled typed array (dtype=float32, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float32Array( [ 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 2, 'float32', clbk ); - - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=bool, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint8Array( [ 0, 0, 0, 0 ] ); - - clbk = constantFunction( false ); - buf = new ArrayBuffer( 8 ); - out = filledarrayBy( buf, 2, 4, 'bool', clbk ); - - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( reinterpretBoolean( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=complex128, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex128( 1.0, 1.0 ) ); - buf = new ArrayBuffer( 64 ); - out = filledarrayBy( buf, 16, 2, 'complex128', clbk ); - - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=complex64, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex64( 1.0, 1.0 ) ); - buf = new ArrayBuffer( 32 ); - out = filledarrayBy( buf, 8, 2, 'complex64', clbk ); - - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Int32Array( [ 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 2, 'int32', clbk ); - - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint32, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint32Array( [ 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 2, 'uint32', clbk ); - - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=int16, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Int16Array( [ 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 2, 'int16', clbk ); - - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint16, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint16Array( [ 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 2, 'uint16', clbk ); - - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=int8, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Int8Array( [ 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 2, 'int8', clbk ); - - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint8, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint8Array( [ 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 2, 'uint8', clbk ); - - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled typed array (dtype=uint8c, arraybuffer, byteoffset, length)', function test( t ) { - var expected; - var clbk; - var buf; - var out; - - expected = new Uint8ClampedArray( [ 1, 1 ] ); - - clbk = constantFunction( 1 ); - buf = new ArrayBuffer( 16 ); - out = filledarrayBy( buf, 4, 2, 'uint8c', clbk ); - - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function throws an error if provided an ArrayBuffer when attempting to create a generic array (dtype=generic, arraybuffer, byteoffset, length)', function test( t ) { - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - var buf = new ArrayBuffer( 8 ); - return filledarrayBy( buf, 4, 1, 'generic', constantFunction( 1.0 ) ); - } -}); - -tape( 'the function throws an error if provided an ArrayBuffer when attempting to create a generic array (dtype=generic, arraybuffer, byteoffset, length; thisArg)', function test( t ) { - t.throws( foo, Error, 'throws an error' ); - t.end(); - - function foo() { - var buf = new ArrayBuffer( 8 ); - return filledarrayBy( buf, 4, 1, 'generic', constantFunction( 1.0 ), {} ); - } -}); - -tape( 'the function returns a filled array (default, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = iterConstant( 3.0, { - 'iter': 3 - }); - out = filledarrayBy( arr, clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (default, iterator; thisArg)', opts, function test( t ) { - var expected; - var indices; - var ctx; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - arr = iterConstant( 3.0, { - 'iter': 3 - }); - ctx = { - 'count': 0 - }; - indices = []; - out = filledarrayBy( arr, clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0, 1, 2 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled array (dtype=float64, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = iterConstant( 3.0, { - 'iter': 3 - }); - out = filledarrayBy( arr, 'float64', clbk ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=float64, iterator; thisArg)', opts, function test( t ) { - var expected; - var indices; - var ctx; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0 ] ); - - arr = iterConstant( 3.0, { - 'iter': 3 - }); - ctx = { - 'count': 0 - }; - indices = []; - out = filledarrayBy( arr, 'float64', clbk, ctx ); - - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - expected = [ 0, 1, 2 ]; - t.strictEqual( ctx.count, expected.length, 'returns expected value' ); - t.deepEqual( indices, expected, 'returns expected value' ); - - t.end(); - - function clbk( i ) { - this.count += 1; // eslint-disable-line no-invalid-this - indices.push( i ); - return 1.0; - } -}); - -tape( 'the function returns a filled array (dtype=float32, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float32Array( [ 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( 1.0 ); - arr = iterConstant( 3.0, { - 'iter': 3 - }); - out = filledarrayBy( arr, 'float32', clbk ); - - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=bool, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint8Array( [ 1, 1, 1, 1 ] ); - - clbk = constantFunction( true ); - arr = iterConstant( false, { - 'iter': 4 - }); - out = filledarrayBy( arr, 'bool', clbk ); - - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( reinterpretBoolean( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex128, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float64Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex128( 1.0, 1.0 ) ); - arr = iterConstant( new Complex128( 3.0, 3.0 ), { - 'iter': 2 - }); - out = filledarrayBy( arr, 'complex128', clbk ); - - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret128( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=complex64, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0 ] ); - - clbk = constantFunction( new Complex64( 1.0, 1.0 ) ); - arr = iterConstant( new Complex64( 3.0, 3.0 ), { - 'iter': 2 - }); - out = filledarrayBy( arr, 'complex64', clbk ); - - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length/2, 'returns expected value' ); - t.deepEqual( reinterpret64( out, 0 ), expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int32, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Int32Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = iterConstant( 3, { - 'iter': 3 - }); - out = filledarrayBy( arr, 'int32', clbk ); - - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint32, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint32Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = iterConstant( 3, { - 'iter': 3 - }); - out = filledarrayBy( arr, 'uint32', clbk ); - - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int16, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Int16Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = iterConstant( 3, { - 'iter': 3 - }); - out = filledarrayBy( arr, 'int16', clbk ); - - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint16, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint16Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = iterConstant( 3, { - 'iter': 3 - }); - out = filledarrayBy( arr, 'uint16', clbk ); - - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=int8, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Int8Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = iterConstant( 3, { - 'iter': 3 - }); - out = filledarrayBy( arr, 'int8', clbk ); - - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint8Array( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = iterConstant( 3, { - 'iter': 3 - }); - out = filledarrayBy( arr, 'uint8', clbk ); - - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=uint8c, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = new Uint8ClampedArray( [ 1, 1, 1 ] ); - - clbk = constantFunction( 1 ); - arr = iterConstant( 3, { - 'iter': 3 - }); - out = filledarrayBy( arr, 'uint8c', clbk ); - - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a filled array (dtype=generic, iterator)', opts, function test( t ) { - var expected; - var clbk; - var arr; - var out; - - expected = [ 1.0, 1.0, 1.0 ]; - - clbk = constantFunction( 1.0 ); - arr = iterConstant( 3, { - 'iter': 3 - }); - out = filledarrayBy( arr, 'generic', clbk ); - - t.strictEqual( instanceOf( out, Array ), true, 'returns expected value' ); - t.strictEqual( out.length, expected.length, 'returns expected value' ); - t.deepEqual( out, expected, 'returns expected value' ); - - t.end(); -});