From 8c7cc402bc5389c3b4d57e6fe6144a7e57f0a29d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 04:31:56 +0000 Subject: [PATCH 01/85] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6d6c9ed..dadcc89 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.1.1", "@stdlib/ndarray-base-next-cartesian-index": "github:stdlib-js/ndarray-base-next-cartesian-index#main", "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From db7dc1690c079185758bbaec349ae923b0ec4dc0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 13:38:14 +0000 Subject: [PATCH 02/85] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 191 - package.json | 69 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 41 files changed, 6203 insertions(+), 5001 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 3acd3a9..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 corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - 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 a994cbb..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/ndarray/iter/entries) 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 c1c45e7..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 4e4cadb..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - 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 corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - 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 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 + + ```
@@ -210,7 +203,7 @@ while ( true ) { ## 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]. @@ -272,7 +265,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c1ef205..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc8ace7..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +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. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c4b50de..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var O=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=O(function(k,c){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),E=require('@stdlib/assert-is-plain-object/dist'),j=require('@stdlib/ndarray-base-assert-is-order/dist'),T=require('@stdlib/assert-is-ndarray-like/dist'),x=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/array-base-copy-indexed/dist'),I=require('@stdlib/ndarray-base-numel/dist'),L=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function g(e){var r,i,u,t,a,s,n,d,m,v,o;if(!T(e))throw new TypeError(l('null4f',e));if(t={order:e.order},arguments.length>1){if(r=arguments[1],!E(r))throw new TypeError(l('null2V',r));if(x(r,"order")){if(!j(r.order))throw new TypeError(l('null5C',"order",r.order));t.order=r.order}}return i=e.shape,u=i.length,m=F(i),v=I(m),v===0&&(s=!0),t.order==="row-major"?d=u-1:d=0,o=-1,n=z(u),a={},f(a,"next",h),f(a,"return",y),p&&f(a,p,w),a;function h(){return o+=1,s||o>=v?{done:!0}:(o>0&&(n=L(i,t.order,n,d,n)),{value:[n.slice(),e.get.apply(e,n)],done:!1})}function y(b){return s=!0,arguments.length?{value:b,done:!0}:{done:!0}}function w(){return g(e,t)}}c.exports=g -});var P=q();module.exports=P; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5d4d5f0..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar copyIndexed = require( '@stdlib/array-base-copy-indexed' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Copy the input shape:\n\tsh = copyIndexed( shape );\n\n\t// Check whether the input array is empty...\n\tN = numel( sh );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x.shape );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAc,QAAS,iCAAkC,EACzDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACpB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQF,EAAE,MACVG,EAAQD,EAAM,OAGdO,EAAKd,EAAaO,CAAM,EAGxBQ,EAAId,EAAOa,CAAG,EACTC,IAAM,IACVJ,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPG,EAAI,GAGJJ,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQO,CAAK,EAChCxB,EAAaiB,EAAM,SAAUQ,CAAI,EAG5BpB,GACJL,EAAaiB,EAAMZ,EAAgBqB,CAAQ,EAErCT,EAQP,SAASO,GAAO,CAEf,OADAD,GAAK,EACAL,GAAOK,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRJ,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASM,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOf,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC9IjB,IAAIiB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "copyIndexed", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "sh", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76b6497..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1d2638..57848e2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ec0ac69 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function p(j){var h,v,u,b,f,c,g,x,y,w,E;if(!s(j))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",j));if(b={order:j.order},arguments.length>1){if(!r(h=arguments[1]))throw new TypeError(l("invalid argument. Options argument must be an object. Value: `%s`.",h));if(n(h,"order")){if(!t(h.order))throw new TypeError(l("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",h.order));b.order=h.order}}return u=(v=j.shape).length,y=o(v),0===(w=m(y))&&(c=!0),x="row-major"===b.order?u-1:0,E=-1,g=d(u),e(f={},"next",T),e(f,"return",z),i&&e(f,i,O),f;function T(){return E+=1,c||E>=w?{done:!0}:(E>0&&(g=a(v,b.order,g,x,g)),{value:[g.slice(),j.get.apply(j,g)],done:!1})}function z(e){return c=!0,arguments.length?{value:e,done:!0}:{done:!0}}function O(){return p(j,b)}}export{p as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5c9325b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport copyIndexed from '@stdlib/array-base-copy-indexed';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Copy the input shape:\n\tsh = copyIndexed( shape );\n\n\t// Check whether the input array is empty...\n\tN = numel( sh );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","sh","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","copyIndexed","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;8jCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,MAASf,EAAEe,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,SAAY,CACrC,IAAMmB,EAASnB,EAAQc,OACtB,MAAM,IAAIF,UAAWC,EAAQ,wEAAyE,QAASb,EAAQc,QAExHX,EAAKW,MAAQd,EAAQc,KACrB,CACD,CAkCD,OA/BAZ,GADAD,EAAQF,EAAEE,OACIe,OAGdR,EAAKY,EAAanB,GAIP,KADXQ,EAAIY,EAAOb,MAEVH,GAAM,GAINE,EADmB,cAAfJ,EAAKW,MACHZ,EAAQ,EAER,EAGPQ,GAAK,EAGLJ,EAAMgB,EAAOpB,GAIbqB,EADAnB,EAAO,CAAA,EACY,OAAQoB,GAC3BD,EAAanB,EAAM,SAAUqB,GAGxBC,GACJH,EAAanB,EAAMsB,EAAgBC,GAE7BvB,EAQP,SAASoB,IAER,OADAd,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRJ,EAAMuB,EAAoB5B,EAAOE,EAAKW,MAAOR,EAAKC,EAAKD,IAGjD,CACNwB,MAAS,CAAExB,EAAIyB,QAAShC,EAAEiC,IAAIC,MAAOlC,EAAGO,IACxCsB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAzB,GAAM,EACDU,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO7B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 537334d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x.shape ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 ba0eac4..0000000 --- a/lib/main.js +++ /dev/null @@ -1,191 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var copyIndexed = require( '@stdlib/array-base-copy-indexed' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var sh; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = x.shape; - ndims = shape.length; - - // Copy the input shape: - sh = copyIndexed( shape ); - - // Check whether the input array is empty... - N = numel( sh ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index dadcc89..ed67ac7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-copy-indexed": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "github:stdlib-js/ndarray-base-next-cartesian-index#main", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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" - }, - "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..a1f25c2 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + 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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From c05f3089070734e60a0fa366765bddf93910b144 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:21:10 +0000 Subject: [PATCH 03/85] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a368a6..206e23d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 0c35078ac75b10233c1ec8c311a00bc7cad7c996 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:22:46 +0000 Subject: [PATCH 04/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 57848e2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ec0ac69..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-copy-indexed@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function p(j){var h,v,u,b,f,c,g,x,y,w,E;if(!s(j))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",j));if(b={order:j.order},arguments.length>1){if(!r(h=arguments[1]))throw new TypeError(l("invalid argument. Options argument must be an object. Value: `%s`.",h));if(n(h,"order")){if(!t(h.order))throw new TypeError(l("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",h.order));b.order=h.order}}return u=(v=j.shape).length,y=o(v),0===(w=m(y))&&(c=!0),x="row-major"===b.order?u-1:0,E=-1,g=d(u),e(f={},"next",T),e(f,"return",z),i&&e(f,i,O),f;function T(){return E+=1,c||E>=w?{done:!0}:(E>0&&(g=a(v,b.order,g,x,g)),{value:[g.slice(),j.get.apply(j,g)],done:!1})}function z(e){return c=!0,arguments.length?{value:e,done:!0}:{done:!0}}function O(){return p(j,b)}}export{p as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5c9325b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport copyIndexed from '@stdlib/array-base-copy-indexed';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = x.shape;\n\tndims = shape.length;\n\n\t// Copy the input shape:\n\tsh = copyIndexed( shape );\n\n\t// Check whether the input array is empty...\n\tN = numel( sh );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","sh","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","copyIndexed","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;8jCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAKnG,GAHAI,EAAO,CACNW,MAASf,EAAEe,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNjB,EAAUe,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEb,IAEpG,GAAKkB,EAAYlB,EAAS,SAAY,CACrC,IAAMmB,EAASnB,EAAQc,OACtB,MAAM,IAAIF,UAAWC,EAAQ,wEAAyE,QAASb,EAAQc,QAExHX,EAAKW,MAAQd,EAAQc,KACrB,CACD,CAkCD,OA/BAZ,GADAD,EAAQF,EAAEE,OACIe,OAGdR,EAAKY,EAAanB,GAIP,KADXQ,EAAIY,EAAOb,MAEVH,GAAM,GAINE,EADmB,cAAfJ,EAAKW,MACHZ,EAAQ,EAER,EAGPQ,GAAK,EAGLJ,EAAMgB,EAAOpB,GAIbqB,EADAnB,EAAO,CAAA,EACY,OAAQoB,GAC3BD,EAAanB,EAAM,SAAUqB,GAGxBC,GACJH,EAAanB,EAAMsB,EAAgBC,GAE7BvB,EAQP,SAASoB,IAER,OADAd,GAAK,EACAL,GAAOK,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRJ,EAAMuB,EAAoB5B,EAAOE,EAAKW,MAAOR,EAAKC,EAAKD,IAGjD,CACNwB,MAAS,CAAExB,EAAIyB,QAAShC,EAAEiC,IAAIC,MAAOlC,EAAGO,IACxCsB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAzB,GAAM,EACDU,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO7B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a1f25c2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f0d592294901a8130726913ccb0dc126ff955cff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:23:48 +0000 Subject: [PATCH 05/85] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 69 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 41 files changed, 6203 insertions(+), 5005 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 3acd3a9..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 corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - 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 a994cbb..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/ndarray/iter/entries) 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 c1c45e7..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 4e4cadb..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - 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 corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - 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 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 + + ```
@@ -210,7 +203,7 @@ while ( true ) { ## 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]. @@ -272,7 +265,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c1ef205..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc8ace7..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +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. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7befa4d..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x.shape );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76b6497..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1d2638..57848e2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ee77adc --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function p(j){var h,v,u,f,b,g,c,x,y,w;if(!s(j))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",j));if(f={order:j.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("invalid argument. Options argument must be an object. Value: `%s`.",h));if(n(h,"order")){if(!t(h.order))throw new TypeError(l("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",h.order));f.order=h.order}}return u=(v=o(j)).length,0===(y=m(v))&&(g=!0),x="row-major"===f.order?u-1:0,w=-1,c=d(u),r(b={},"next",E),r(b,"return",T),i&&r(b,i,z),b;function E(){return w+=1,g||w>=y?{done:!0}:(w>0&&(c=a(v,f.order,c,x,c)),{value:[c.slice(),j.get.apply(j,c)],done:!1})}function T(r){return g=!0,arguments.length?{value:r,done:!0}:{done:!0}}function z(){return p(j,f)}}export{p as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c786e26 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;2jCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAKnG,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEZ,IAEpG,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,wEAAyE,QAASZ,EAAQa,QAExHV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 537334d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x.shape ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 8785ebd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 206e23d..2fe0cf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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" - }, - "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..5b57ed5 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + 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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 9e752a3103bfe394649ab4c93cfc579e1006c3d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:24:04 +0000 Subject: [PATCH 06/85] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 841e4b1..87c674a 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.1.0-esm/index.mjs'; ``` #### nditerEntries( x\[, options] ) @@ -149,7 +149,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.1.0-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 2488ff1b5d4df623fe864cd74ffeaa2fcfb71bb9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:24:05 +0000 Subject: [PATCH 07/85] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 87c674a..54b0f58 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-entries/tags). For example, + ```javascript import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.1.0-esm/index.mjs'; ``` @@ -149,7 +154,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.1.0-esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From aeec9f2bf17fa9a953a505947390e7de39754140 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 15:21:19 +0000 Subject: [PATCH 08/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..2c08074 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( 'null5C,LF', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 5a368a6..206e23d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From bf36b4ca21d89d35b7db65962056117d44e140d8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 22:54:15 +0000 Subject: [PATCH 09/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 57848e2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ee77adc..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function p(j){var h,v,u,f,b,g,c,x,y,w;if(!s(j))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",j));if(f={order:j.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("invalid argument. Options argument must be an object. Value: `%s`.",h));if(n(h,"order")){if(!t(h.order))throw new TypeError(l("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",h.order));f.order=h.order}}return u=(v=o(j)).length,0===(y=m(v))&&(g=!0),x="row-major"===f.order?u-1:0,w=-1,c=d(u),r(b={},"next",E),r(b,"return",T),i&&r(b,i,z),b;function E(){return w+=1,g||w>=y?{done:!0}:(w>0&&(c=a(v,f.order,c,x,c)),{value:[c.slice(),j.get.apply(j,c)],done:!1})}function T(r){return g=!0,arguments.length?{value:r,done:!0}:{done:!0}}function z(){return p(j,f)}}export{p as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c786e26..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;2jCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAKnG,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEZ,IAEpG,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,wEAAyE,QAASZ,EAAQa,QAExHV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5b57ed5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 89c6b0f01031d27d69804ed0ae686a1430b8d10f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 22:55:18 +0000 Subject: [PATCH 10/85] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 69 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 42 files changed, 6203 insertions(+), 5006 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f1dc81d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T04:38:49.223Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 3acd3a9..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 corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - 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 a994cbb..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/ndarray/iter/entries) 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 c1c45e7..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 4e4cadb..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - 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 corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - 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 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 + + ```
@@ -210,7 +203,7 @@ while ( true ) { ## 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]. @@ -272,7 +265,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c1ef205..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc8ace7..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +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. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7befa4d..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x.shape );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76b6497..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1d2638..57848e2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..289972c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(p){var h,v,f,c,b,u,g,x,y,w;if(!t(p))throw new TypeError(a("null4f,Pc",p));if(c={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(a("null2V,FD",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(a("null5C,LF","order",h.order));c.order=h.order}}return f=(v=o(p)).length,0===(y=m(v))&&(u=!0),x="row-major"===c.order?f-1:0,w=-1,g=i(f),r(b={},"next",E),r(b,"return",T),d&&r(b,d,F),b;function E(){return w+=1,u||w>=y?{done:!0}:(w>0&&(g=l(v,c.order,g,x,g)),{value:[g.slice(),p.get.apply(p,g)],done:!1})}function T(r){return u=!0,arguments.length?{value:r,done:!0}:{done:!0}}function F(){return j(p,c)}}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a918d6d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'null5C,LF', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,YAAab,IAK3C,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaZ,IAE3C,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,YAAa,QAASZ,EAAQa,QAE5DV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 537334d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x.shape ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 2c08074..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'null5C,LF', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 206e23d..2fe0cf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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" - }, - "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..4886b76 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + 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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From d35d24c6d5da7116b12ad502152c080051dfe1c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 20:27:44 +0000 Subject: [PATCH 11/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..2c08074 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( 'null5C,LF', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 5a368a6..206e23d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From c14e774277ea797a9d5d4d389e5a006152dce5a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 20:28:44 +0000 Subject: [PATCH 12/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 57848e2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 289972c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(p){var h,v,f,c,b,u,g,x,y,w;if(!t(p))throw new TypeError(a("null4f,Pc",p));if(c={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(a("null2V,FD",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(a("null5C,LF","order",h.order));c.order=h.order}}return f=(v=o(p)).length,0===(y=m(v))&&(u=!0),x="row-major"===c.order?f-1:0,w=-1,g=i(f),r(b={},"next",E),r(b,"return",T),d&&r(b,d,F),b;function E(){return w+=1,u||w>=y?{done:!0}:(w>0&&(g=l(v,c.order,g,x,g)),{value:[g.slice(),p.get.apply(p,g)],done:!1})}function T(r){return u=!0,arguments.length?{value:r,done:!0}:{done:!0}}function F(){return j(p,c)}}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a918d6d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'null5C,LF', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,YAAab,IAK3C,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaZ,IAE3C,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,YAAa,QAASZ,EAAQa,QAE5DV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4886b76..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 21c39eaac572acfbdd8999ec45710197aa6e7e49 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 20:29:38 +0000 Subject: [PATCH 13/85] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 69 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 41 files changed, 6203 insertions(+), 5005 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 3acd3a9..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 corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - 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 a994cbb..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/ndarray/iter/entries) 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 c1c45e7..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 4e4cadb..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - 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 corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - 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 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 + + ```
@@ -210,7 +203,7 @@ while ( true ) { ## 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]. @@ -272,7 +265,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c1ef205..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc8ace7..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +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. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7befa4d..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x.shape );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1d2638..57848e2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..289972c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(p){var h,v,f,c,b,u,g,x,y,w;if(!t(p))throw new TypeError(a("null4f,Pc",p));if(c={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(a("null2V,FD",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(a("null5C,LF","order",h.order));c.order=h.order}}return f=(v=o(p)).length,0===(y=m(v))&&(u=!0),x="row-major"===c.order?f-1:0,w=-1,g=i(f),r(b={},"next",E),r(b,"return",T),d&&r(b,d,F),b;function E(){return w+=1,u||w>=y?{done:!0}:(w>0&&(g=l(v,c.order,g,x,g)),{value:[g.slice(),p.get.apply(p,g)],done:!1})}function T(r){return u=!0,arguments.length?{value:r,done:!0}:{done:!0}}function F(){return j(p,c)}}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a918d6d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'null5C,LF', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,YAAab,IAK3C,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaZ,IAE3C,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,YAAa,QAASZ,EAAQa,QAE5DV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 537334d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x.shape ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 2c08074..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'null5C,LF', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 206e23d..2fe0cf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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" - }, - "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..58e4c20 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + 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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 7006fccf5b2030d2226bddf04da72ab8d17b7a15 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 22:21:20 +0000 Subject: [PATCH 14/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..2c08074 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( 'null5C,LF', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 5a368a6..206e23d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 7d7458ff213cb9c15196dc6f8abb51e993618eee Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 22:38:25 +0000 Subject: [PATCH 15/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 57848e2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 289972c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(p){var h,v,f,c,b,u,g,x,y,w;if(!t(p))throw new TypeError(a("null4f,Pc",p));if(c={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(a("null2V,FD",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(a("null5C,LF","order",h.order));c.order=h.order}}return f=(v=o(p)).length,0===(y=m(v))&&(u=!0),x="row-major"===c.order?f-1:0,w=-1,g=i(f),r(b={},"next",E),r(b,"return",T),d&&r(b,d,F),b;function E(){return w+=1,u||w>=y?{done:!0}:(w>0&&(g=l(v,c.order,g,x,g)),{value:[g.slice(),p.get.apply(p,g)],done:!1})}function T(r){return u=!0,arguments.length?{value:r,done:!0}:{done:!0}}function F(){return j(p,c)}}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a918d6d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'null5C,LF', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,YAAab,IAK3C,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaZ,IAE3C,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,YAAa,QAASZ,EAAQa,QAE5DV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 58e4c20..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 717941c7fac32195a76850551949ccabe6da5ff3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 Nov 2023 22:39:43 +0000 Subject: [PATCH 16/85] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 69 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 41 files changed, 6203 insertions(+), 5005 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 3acd3a9..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 corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - 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 a994cbb..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/ndarray/iter/entries) 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 c1c45e7..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 4e4cadb..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - 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 corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - 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 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 + + ```
@@ -210,7 +203,7 @@ while ( true ) { ## 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]. @@ -272,7 +265,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c1ef205..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc8ace7..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +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. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1d2638..57848e2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..289972c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(p){var h,v,f,c,b,u,g,x,y,w;if(!t(p))throw new TypeError(a("null4f,Pc",p));if(c={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(a("null2V,FD",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(a("null5C,LF","order",h.order));c.order=h.order}}return f=(v=o(p)).length,0===(y=m(v))&&(u=!0),x="row-major"===c.order?f-1:0,w=-1,g=i(f),r(b={},"next",E),r(b,"return",T),d&&r(b,d,F),b;function E(){return w+=1,u||w>=y?{done:!0}:(w>0&&(g=l(v,c.order,g,x,g)),{value:[g.slice(),p.get.apply(p,g)],done:!1})}function T(r){return u=!0,arguments.length?{value:r,done:!0}:{done:!0}}function F(){return j(p,c)}}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a918d6d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'null5C,LF', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,YAAab,IAK3C,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaZ,IAE3C,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,YAAa,QAASZ,EAAQa,QAE5DV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 2c08074..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'null5C,LF', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 206e23d..2fe0cf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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" - }, - "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..bfbea60 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + 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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From de449288eea403a62b6372892f38d18d5d2b4821 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 12:51:15 +0000 Subject: [PATCH 17/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..2c08074 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( 'null5C,LF', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 8163435..97a86a1 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 7cc588d11715ddcf35ca08afa56ffe8b67c91d26 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 16:56:06 +0000 Subject: [PATCH 18/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 57848e2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 289972c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(p){var h,v,f,c,b,u,g,x,y,w;if(!t(p))throw new TypeError(a("null4f,Pc",p));if(c={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(a("null2V,FD",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(a("null5C,LF","order",h.order));c.order=h.order}}return f=(v=o(p)).length,0===(y=m(v))&&(u=!0),x="row-major"===c.order?f-1:0,w=-1,g=i(f),r(b={},"next",E),r(b,"return",T),d&&r(b,d,F),b;function E(){return w+=1,u||w>=y?{done:!0}:(w>0&&(g=l(v,c.order,g,x,g)),{value:[g.slice(),p.get.apply(p,g)],done:!1})}function T(r){return u=!0,arguments.length?{value:r,done:!0}:{done:!0}}function F(){return j(p,c)}}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a918d6d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'null5C,LF', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,YAAab,IAK3C,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaZ,IAE3C,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,YAAa,QAASZ,EAAQa,QAE5DV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bfbea60..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9e21b52476244a443302b61729c7c2d2b974b570 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 16:57:19 +0000 Subject: [PATCH 19/85] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 69 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 41 files changed, 6205 insertions(+), 5007 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 3acd3a9..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 corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - 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 a994cbb..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/ndarray/iter/entries) 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 c1c45e7..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 4e4cadb..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - 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 corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - 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 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 + + ```
@@ -218,7 +211,7 @@ while ( true ) { ## 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]. @@ -280,13 +273,13 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c1ef205..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc8ace7..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +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. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1d2638..57848e2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..289972c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(p){var h,v,f,c,b,u,g,x,y,w;if(!t(p))throw new TypeError(a("null4f,Pc",p));if(c={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(a("null2V,FD",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(a("null5C,LF","order",h.order));c.order=h.order}}return f=(v=o(p)).length,0===(y=m(v))&&(u=!0),x="row-major"===c.order?f-1:0,w=-1,g=i(f),r(b={},"next",E),r(b,"return",T),d&&r(b,d,F),b;function E(){return w+=1,u||w>=y?{done:!0}:(w>0&&(g=l(v,c.order,g,x,g)),{value:[g.slice(),p.get.apply(p,g)],done:!1})}function T(r){return u=!0,arguments.length?{value:r,done:!0}:{done:!0}}function F(){return j(p,c)}}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a918d6d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'null5C,LF', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,YAAab,IAK3C,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaZ,IAE3C,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,YAAa,QAASZ,EAAQa,QAE5DV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 2c08074..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'null5C,LF', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 97a86a1..2fe0cf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/bench": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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" - }, - "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..1882a6d --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + 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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 6d59d834688d968ebb2f32443198a3f8da2a9464 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 11:43:11 +0000 Subject: [PATCH 20/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..2c08074 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( 'null4f,Pc', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( 'null2V,FD', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( 'null5C,LF', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 8c679f5..3524261 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From a21bebf2790c16cf5d229b1255cd3f6e9ee45eda Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 08:57:58 +0000 Subject: [PATCH 21/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 57848e2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 289972c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(p){var h,v,f,c,b,u,g,x,y,w;if(!t(p))throw new TypeError(a("null4f,Pc",p));if(c={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(a("null2V,FD",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(a("null5C,LF","order",h.order));c.order=h.order}}return f=(v=o(p)).length,0===(y=m(v))&&(u=!0),x="row-major"===c.order?f-1:0,w=-1,g=i(f),r(b={},"next",E),r(b,"return",T),d&&r(b,d,F),b;function E(){return w+=1,u||w>=y?{done:!0}:(w>0&&(g=l(v,c.order,g,x,g)),{value:[g.slice(),p.get.apply(p,g)],done:!1})}function T(r){return u=!0,arguments.length?{value:r,done:!0}:{done:!0}}function F(){return j(p,c)}}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a918d6d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'null5C,LF', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,YAAab,IAK3C,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaZ,IAE3C,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,YAAa,QAASZ,EAAQa,QAE5DV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1882a6d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 94a2d22fb43f9fc485b7d0554c0eaf4e81a8616b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 08:58:50 +0000 Subject: [PATCH 22/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 69 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 42 files changed, 6205 insertions(+), 5003 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index da1fe5d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T04:50:34.534Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 3acd3a9..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 corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - 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 a994cbb..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/ndarray/iter/entries) 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 c1c45e7..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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 4e4cadb..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - 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 corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - 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 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - 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 + + ```
@@ -218,7 +211,7 @@ while ( true ) { ## 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]. @@ -280,13 +273,13 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c1ef205..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc8ace7..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +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. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1d2638..57848e2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..289972c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(p){var h,v,f,c,b,u,g,x,y,w;if(!t(p))throw new TypeError(a("null4f,Pc",p));if(c={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(a("null2V,FD",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(a("null5C,LF","order",h.order));c.order=h.order}}return f=(v=o(p)).length,0===(y=m(v))&&(u=!0),x="row-major"===c.order?f-1:0,w=-1,g=i(f),r(b={},"next",E),r(b,"return",T),d&&r(b,d,F),b;function E(){return w+=1,u||w>=y?{done:!0}:(w>0&&(g=l(v,c.order,g,x,g)),{value:[g.slice(),p.get.apply(p,g)],done:!1})}function T(r){return u=!0,arguments.length?{value:r,done:!0}:{done:!0}}function F(){return j(p,c)}}export{j as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a918d6d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'null5C,LF', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,YAAab,IAK3C,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaZ,IAE3C,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,YAAa,QAASZ,EAAQa,QAE5DV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 2c08074..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'null4f,Pc', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'null2V,FD', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'null5C,LF', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 3524261..2fe0cf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/bench": "^0.2.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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" - }, - "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..514d650 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + 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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 33053446853d7be5d4a211b6bc392c123a3448e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 06:57:41 +0000 Subject: [PATCH 23/85] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 33922f7..b8ecb6c 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 6a161119a6757aa8facb8a2e907a3fae32df9c87 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 13:41:24 +0000 Subject: [PATCH 24/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 57848e2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 289972c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function j(p){var h,v,f,c,b,u,g,x,y,w;if(!t(p))throw new TypeError(a("null4f,Pc",p));if(c={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(a("null2V,FD",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(a("null5C,LF","order",h.order));c.order=h.order}}return f=(v=o(p)).length,0===(y=m(v))&&(u=!0),x="row-major"===c.order?f-1:0,w=-1,g=i(f),r(b={},"next",E),r(b,"return",T),d&&r(b,d,F),b;function E(){return w+=1,u||w>=y?{done:!0}:(w>0&&(g=l(v,c.order,g,x,g)),{value:[g.slice(),p.get.apply(p,g)],done:!1})}function T(r){return u=!0,arguments.length?{value:r,done:!0}:{done:!0}}function F(){return j(p,c)}}export{j as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a918d6d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'null4f,Pc', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'null2V,FD', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'null5C,LF', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,YAAab,IAK3C,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,YAAaZ,IAE3C,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,YAAa,QAASZ,EAAQa,QAE5DV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 514d650..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e8f943c6e30e77c0323595943176ea73a61d11b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 13:42:05 +0000 Subject: [PATCH 25/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 69 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 43 files changed, 6205 insertions(+), 5009 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 20cbbbe..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T04:17:07.210Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 3acd3a9..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 corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - 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 a994cbb..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/ndarray/iter/entries) 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 c92f5c4..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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 9935c59..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - 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 e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 + + ```
@@ -218,7 +211,7 @@ while ( true ) { ## 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]. @@ -280,13 +273,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cc8ace7..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +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. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index f1d2638..57848e2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9145fdf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function p(j){var h,v,u,f,b,g,c,x,y,w;if(!s(j))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",j));if(f={order:j.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("invalid argument. Options argument must be an object. Value: `%s`.",h));if(n(h,"order")){if(!t(h.order))throw new TypeError(l("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",h.order));f.order=h.order}}return u=(v=o(j)).length,0===(y=m(v))&&(g=!0),x="row-major"===f.order?u-1:0,w=-1,c=d(u),r(b={},"next",E),r(b,"return",T),i&&r(b,i,z),b;function E(){return w+=1,g||w>=y?{done:!0}:(w>0&&(c=a(v,f.order,c,x,c)),{value:[c.slice(),j.get.apply(j,c)],done:!1})}function T(r){return g=!0,arguments.length?{value:r,done:!0}:{done:!0}}function z(){return p(j,f)}}export{p as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c786e26 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;2jCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAKnG,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEZ,IAEpG,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,wEAAyE,QAASZ,EAAQa,QAExHV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 8785ebd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index b8ecb6c..2fe0cf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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.1.2" - }, - "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..73d690b --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + 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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From a69359202f1b4748a7e1aa8f51684345942d3fe7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 07:27:45 +0000 Subject: [PATCH 26/85] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 33922f7..b8ecb6c 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From e31c7c46f0923dfd28df080c2c10a7b3a304244e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:02:33 +0000 Subject: [PATCH 27/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 57848e2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( `@stdlib/ndarray/array` ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9145fdf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function p(j){var h,v,u,f,b,g,c,x,y,w;if(!s(j))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",j));if(f={order:j.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("invalid argument. Options argument must be an object. Value: `%s`.",h));if(n(h,"order")){if(!t(h.order))throw new TypeError(l("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",h.order));f.order=h.order}}return u=(v=o(j)).length,0===(y=m(v))&&(g=!0),x="row-major"===f.order?u-1:0,w=-1,c=d(u),r(b={},"next",E),r(b,"return",T),i&&r(b,i,z),b;function E(){return w+=1,g||w>=y?{done:!0}:(w>0&&(c=a(v,f.order,c,x,c)),{value:[c.slice(),j.get.apply(j,c)],done:!1})}function T(r){return g=!0,arguments.length?{value:r,done:!0}:{done:!0}}function z(){return p(j,f)}}export{p as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c786e26..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;2jCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAKnG,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEZ,IAEpG,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,wEAAyE,QAASZ,EAAQa,QAExHV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 73d690b..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 33a2b6a72310f208981c90017f0b6d1fea47ada7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:03:01 +0000 Subject: [PATCH 28/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 69 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 43 files changed, 6205 insertions(+), 5014 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index da04ed5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T05:06:44.114Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 3acd3a9..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 corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - 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 a994cbb..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/ndarray/iter/entries) 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 c92f5c4..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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 9935c59..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - 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 e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - 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 + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9145fdf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function p(j){var h,v,u,f,b,g,c,x,y,w;if(!s(j))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",j));if(f={order:j.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("invalid argument. Options argument must be an object. Value: `%s`.",h));if(n(h,"order")){if(!t(h.order))throw new TypeError(l("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",h.order));f.order=h.order}}return u=(v=o(j)).length,0===(y=m(v))&&(g=!0),x="row-major"===f.order?u-1:0,w=-1,c=d(u),r(b={},"next",E),r(b,"return",T),i&&r(b,i,z),b;function E(){return w+=1,g||w>=y?{done:!0}:(w>0&&(c=a(v,f.order,c,x,c)),{value:[c.slice(),j.get.apply(j,c)],done:!1})}function T(r){return g=!0,arguments.length?{value:r,done:!0}:{done:!0}}function z(){return p(j,f)}}export{p as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c786e26 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;2jCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAKnG,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEZ,IAEpG,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,wEAAyE,QAASZ,EAAQa,QAExHV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 8785ebd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index b8ecb6c..2fe0cf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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.1.2" - }, - "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..b7363b9 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + 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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 0a39aaa82e21e178e3ee7a1218fafe9d791c128b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 14:17:41 +0000 Subject: [PATCH 29/85] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ee97df8..53b2921 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.0", "@stdlib/ndarray-base-numel": "^0.2.0", "@stdlib/ndarray-shape": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/symbol-iterator": "^0.2.0", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" From 66f8a01bd32cd952c24b79659ebb5712abc086cc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 21:07:24 +0000 Subject: [PATCH 30/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9145fdf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import{assign as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function p(j){var h,v,u,f,b,g,c,x,y,w;if(!s(j))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",j));if(f={order:j.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("invalid argument. Options argument must be an object. Value: `%s`.",h));if(n(h,"order")){if(!t(h.order))throw new TypeError(l("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",h.order));f.order=h.order}}return u=(v=o(j)).length,0===(y=m(v))&&(g=!0),x="row-major"===f.order?u-1:0,w=-1,c=d(u),r(b={},"next",E),r(b,"return",T),i&&r(b,i,z),b;function E(){return w+=1,g||w>=y?{done:!0}:(w>0&&(c=a(v,f.order,c,x,c)),{value:[c.slice(),j.get.apply(j,c)],done:!1})}function T(r){return g=!0,arguments.length?{value:r,done:!0}:{done:!0}}function z(){return p(j,f)}}export{p as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c786e26..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;2jCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAKnG,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEZ,IAEpG,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,wEAAyE,QAASZ,EAAQa,QAExHV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b7363b9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ec16756381da425ac3cb6c7161f311a73beadd7c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 21:08:06 +0000 Subject: [PATCH 31/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 69 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 42 files changed, 6205 insertions(+), 5017 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 ebb6075..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - 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 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b7009ca --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.0-esm/index.mjs";import{assign as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function p(j){var h,v,u,f,b,g,c,x,y,w;if(!s(j))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",j));if(f={order:j.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("invalid argument. Options argument must be an object. Value: `%s`.",h));if(n(h,"order")){if(!t(h.order))throw new TypeError(l("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",h.order));f.order=h.order}}return u=(v=o(j)).length,0===(y=m(v))&&(g=!0),x="row-major"===f.order?u-1:0,w=-1,c=d(u),r(b={},"next",E),r(b,"return",T),i&&r(b,i,z),b;function E(){return w+=1,g||w>=y?{done:!0}:(w>0&&(c=a(v,f.order,c,x,c)),{value:[c.slice(),j.get.apply(j,c)],done:!1})}function T(r){return g=!0,arguments.length?{value:r,done:!0}:{done:!0}}function z(){return p(j,f)}}export{p as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..c786e26 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;2jCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAKnG,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEZ,IAEpG,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,wEAAyE,QAASZ,EAAQa,QAExHV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 8785ebd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 53b2921..0f8d01e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/ndarray-base-assert-is-order": "^0.2.0", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-shape": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/symbol-iterator": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.2.0", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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.0" - }, - "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..496c3e6 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + 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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 1a3860967dc80cdaafd4bff92a5859da1a441f5d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 22:10:59 +0000 Subject: [PATCH 32/85] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5ba6220..a86f22e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.0-esm/index.mjs'; ``` #### nditerEntries( x\[, options] ) @@ -149,7 +149,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.0-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From f608fe7d2ff309cf6a6b4a2e2a605a2ecb0b9b82 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 22:10:59 +0000 Subject: [PATCH 33/85] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a86f22e..8c71a03 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-entries/tags). For example, + ```javascript import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.0-esm/index.mjs'; ``` @@ -149,7 +154,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.0-esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 5daf199a1b48ca2d625ede586a5f3a23ad5531ae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 00:27:48 +0000 Subject: [PATCH 34/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 4a36cf6..2c17e3b 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", "@stdlib/ndarray-base-numel": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1" From 01bb1a524e354ed3a623284b693366b8fe6141d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 05:52:31 +0000 Subject: [PATCH 35/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6263 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b7009ca..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.0-esm/index.mjs";import{assign as a}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function p(j){var h,v,u,f,b,g,c,x,y,w;if(!s(j))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",j));if(f={order:j.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("invalid argument. Options argument must be an object. Value: `%s`.",h));if(n(h,"order")){if(!t(h.order))throw new TypeError(l("invalid option. `%s` option must be a recognized order. Option: `%s`.","order",h.order));f.order=h.order}}return u=(v=o(j)).length,0===(y=m(v))&&(g=!0),x="row-major"===f.order?u-1:0,w=-1,c=d(u),r(b={},"next",E),r(b,"return",T),i&&r(b,i,z),b;function E(){return w+=1,g||w>=y?{done:!0}:(w>0&&(c=a(v,f.order,c,x,c)),{value:[c.slice(),j.get.apply(j,c)],done:!1})}function T(r){return g=!0,arguments.length?{value:r,done:!0}:{done:!0}}function z(){return p(j,f)}}export{p as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index c786e26..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","next","end","iteratorSymbol","factory","done","nextCartesianIndex","value","slice","get","apply"],"mappings":";;2jCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAKnG,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,qEAAsEZ,IAEpG,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,wEAAyE,QAASZ,EAAQa,QAExHV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,OAAQmB,GAC3BD,EAAalB,EAAM,SAAUoB,GAGxBC,GACJH,EAAalB,EAAMqB,EAAgBC,GAE7BtB,EAQP,SAASmB,IAER,OADAd,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACNmB,MAAQ,IAGLlB,EAAI,IACRH,EAAMsB,EAAoB3B,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGjD,CACNuB,MAAS,CAAEvB,EAAIwB,QAAS/B,EAAEgC,IAAIC,MAAOjC,EAAGO,IACxCqB,MAAQ,GAET,CASD,SAASH,EAAKK,GAEb,OADAxB,GAAM,EACDS,UAAUC,OACP,CACNc,MAASA,EACTF,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASD,IACR,OAAO5B,EAAeC,EAAGI,EACzB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 496c3e6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a71ddbcd05a91842cf4fa801f20bc5981b239fac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 05:52:58 +0000 Subject: [PATCH 36/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 69 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ----- 42 files changed, 4870 insertions(+), 5011 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6dc3626 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 2c17e3b..e2dbc4e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.0", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.0", - "@stdlib/ndarray-zeros": "^0.2.0", - "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.1" - }, - "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..cf7cabe --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From de1213011867e69697bb0f6f106e9a6f94a26312 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 07:27:22 +0000 Subject: [PATCH 37/85] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9713775..70b0121 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.1-esm/index.mjs'; ``` #### nditerEntries( x\[, options] ) @@ -149,7 +149,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.1-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From fdab17473cdc76f071cd69b1efe34859083ff309 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 07:27:23 +0000 Subject: [PATCH 38/85] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 70b0121..384bc07 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-entries/tags). For example, + ```javascript import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.1-esm/index.mjs'; ``` @@ -149,7 +154,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.1-esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From dbc4ff35fa7fefffed6bc4a044fe4c53db2f78bc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 06:50:18 +0000 Subject: [PATCH 39/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 42fbfa0..4d6fa88 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", "@stdlib/ndarray-base-numel": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 8651f4651120a07b449096a331ddd2fb5422c108 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 12:17:56 +0000 Subject: [PATCH 40/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6dc3626..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cf7cabe..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 864f4765d0274aff03daf5162f9d991ec1c05838 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 12:18:25 +0000 Subject: [PATCH 41/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ----- 43 files changed, 4870 insertions(+), 5014 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 75396c6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T04:53:10.431Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6b33910 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 4d6fa88..e2dbc4e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "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.1" - }, - "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..5ea3ffd --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 58aef91f7676b94cfd95fcada1be4ee7e72f8c9f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 06:06:19 +0000 Subject: [PATCH 42/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 42fbfa0..4d6fa88 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", "@stdlib/ndarray-base-numel": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 53c9bf401f9cce4f70d83cb69d3819ee3f699811 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 11:19:52 +0000 Subject: [PATCH 43/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6b33910..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5ea3ffd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 307486ecffbc7d4781f9b65a88143f8105673f7a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 11:20:07 +0000 Subject: [PATCH 44/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ----- 43 files changed, 4870 insertions(+), 5017 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index cbe620b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T04:08:04.287Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6b33910 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 4d6fa88..e2dbc4e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "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.1" - }, - "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..5ea3ffd --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From e050145b52e7f6106e91ba8ad5420cf3597704ad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 02:29:57 +0000 Subject: [PATCH 45/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 42fbfa0..4d6fa88 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", "@stdlib/ndarray-base-numel": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From da765aafb1554403f859c648004177b497883c57 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 07:56:37 +0000 Subject: [PATCH 46/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6b33910..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5ea3ffd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 630a329b2574e73f0401fb1ed9fbda9617ca0135 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 07:57:05 +0000 Subject: [PATCH 47/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ----- 42 files changed, 4870 insertions(+), 5018 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +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: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6b33910 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 4d6fa88..e2dbc4e 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "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.1" - }, - "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..5ea3ffd --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From aa02a38d282a72e7d8574d3a67b36eab3973fb12 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:25:30 +0000 Subject: [PATCH 48/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 4ea29d4..88bb586 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 98c2de427005285a67c1aac937d5945b70d88d12 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:45:26 +0000 Subject: [PATCH 49/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6b33910..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5ea3ffd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0ea8754b5bf8bd5515204dfdf84125a804fa9645 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:45:41 +0000 Subject: [PATCH 50/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 108 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ----- 42 files changed, 4870 insertions(+), 5132 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7d31987 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 88bb586..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "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.2" - }, - "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..e19c81a --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From d575d7585964c6a286917d798d87adc8efee168e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:53:54 +0000 Subject: [PATCH 51/85] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d5b9cb..752f374 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.2-esm/index.mjs'; ``` #### nditerEntries( x\[, options] ) @@ -149,7 +149,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.2-esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From aa38393d3134719bb79402115dbcb67db025dc0f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 21:53:55 +0000 Subject: [PATCH 52/85] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 752f374..e38d4cc 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-iter-entries/tags). For example, + ```javascript import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.2-esm/index.mjs'; ``` @@ -149,7 +154,7 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@v0.2.2-esm/index.mjs'; +import nditerEntries from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-entries@esm/index.mjs'; // Define an input array: var x = array( zeroTo( 27 ), { From 3b395ac23ffe7f74bc1612e825cbb8c09cddca21 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 06:56:36 +0000 Subject: [PATCH 53/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 5721fa7..8ce377d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 06fbbfd1e5a4a06f2454fe28ecca20a99bf2d1c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 11:36:27 +0000 Subject: [PATCH 54/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7d31987..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e19c81a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bc45d47711a882edd695dd47993d46796c018238 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 11:36:43 +0000 Subject: [PATCH 55/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 78 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ----- 43 files changed, 4870 insertions(+), 5105 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7185075..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T04:59:44.281Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8bca082 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 8ce377d..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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.2" - }, - "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..bb52204 --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 73fc07219883304df8b78010808cda7418eb495d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 22:08:50 +0000 Subject: [PATCH 56/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 5721fa7..8ce377d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 528a753a1c3307336e94aab202a06f636b6bed0d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 4 Aug 2024 01:23:01 +0000 Subject: [PATCH 57/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8bca082..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bb52204..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4fcdd374d024211b8f3c7e12bc6c3254407a5bb6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 4 Aug 2024 01:23:19 +0000 Subject: [PATCH 58/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 108 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ----- 43 files changed, 4870 insertions(+), 5135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b7a659c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T20:28:13.674Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8bca082 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 8ce377d..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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.2" - }, - "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..bb52204 --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 93193bebb06c69839e902edbdb6381d608b0c6f7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 07:15:38 +0000 Subject: [PATCH 59/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 3cd8fb1..85078c7 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 8599e71eecbfddccef3641ce3d72915b8561c840 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 11:34:43 +0000 Subject: [PATCH 60/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8bca082..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bb52204..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1a44bf8a5a977cd1aada23d4099d58db0e948298 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 11:35:00 +0000 Subject: [PATCH 61/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 108 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ----- 43 files changed, 4870 insertions(+), 5135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4bd5454..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T05:19:42.090Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8bca082 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 85078c7..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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.2" - }, - "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..bb52204 --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 76fa243a93cbe4eb9df1bd28fd7db16d30ee0ac1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 07:31:40 +0000 Subject: [PATCH 62/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 3cd8fb1..85078c7 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From fb5f78a16e2d724d4e64b7cb1bad6f53913318fa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 12:08:50 +0000 Subject: [PATCH 63/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8bca082..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bb52204..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From df5d9ceafc34eddac4425fd2c8bdb761e8ae8166 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 12:09:15 +0000 Subject: [PATCH 64/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 108 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ----- 43 files changed, 4870 insertions(+), 5135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index bbb8a34..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T05:31:31.351Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8bca082 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 85078c7..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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.2" - }, - "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..bb52204 --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From a1f2b68e66ed5724a0bde2d36e208e4bde793f9f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 07:24:14 +0000 Subject: [PATCH 65/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 3cd8fb1..85078c7 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From cc68432c9fcd4db2a8e2f48c1fa183a9d986f743 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 11:20:52 +0000 Subject: [PATCH 66/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8bca082..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bb52204..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 440b3b7a970d7538412e8301aea9d9a4207c3945 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 11:21:10 +0000 Subject: [PATCH 67/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 108 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ----- 43 files changed, 4870 insertions(+), 5135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 23da4b2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T05:35:26.618Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8bca082 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 85078c7..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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.2" - }, - "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..bb52204 --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From fe1ba0acde6921a72acb30bd0a792e69f090cd1e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 07:39:40 +0000 Subject: [PATCH 68/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 02eb606..a3c296d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From da09d8c26751a76c21162b16f419b6e9b14e8fba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 11:31:03 +0000 Subject: [PATCH 69/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8bca082..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bb52204..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0ee479c777ffb4fabe8433097884b07eb8be9bf9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 11:31:35 +0000 Subject: [PATCH 70/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 108 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 44 files changed, 4870 insertions(+), 5240 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 946650c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T05:44:01.272Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8bca082 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index a3c296d..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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.2" - }, - "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..bb52204 --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From a1a480a30640945c8d0e39c3b1df9cfbbbe0116e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 03:27:01 +0000 Subject: [PATCH 71/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 02eb606..a3c296d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From a5fa1045b700f91d24557635f77cb23e7e4f00a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 04:41:54 +0000 Subject: [PATCH 72/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8bca082..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bb52204..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d6d378550f5687947066a5ca8a295f8551888939 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 04:42:27 +0000 Subject: [PATCH 73/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 108 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 44 files changed, 4870 insertions(+), 5240 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 68cb407..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T02:56:10.527Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b93b9ce..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manor, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c996f33..02a1b74 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8bca082 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index a3c296d..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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.2" - }, - "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..bb52204 --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From cadccdc1ca775a415939fbaa89cbd0c7ae9e805e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:46:27 +0000 Subject: [PATCH 74/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 02eb606..a3c296d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From b2c2117c06f592c999bf3ec827ab85fd1b97d25d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:48:35 +0000 Subject: [PATCH 75/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 02a1b74..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8bca082..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bb52204..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 70fece99d89f192b01b1dace6b99305077affc1d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Jan 2025 01:48:57 +0000 Subject: [PATCH 76/85] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 142 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 43 files changed, 4870 insertions(+), 5273 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 98cc12e..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/ndarray/iter/entries) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 30203c8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manner, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c8f89d1..baeb3a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0e60846 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index a3c296d..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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.2" - }, - "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..bb52204 --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 77ffa6ca96d505803a963051bf1ea20d68d96d4e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:05:59 +0000 Subject: [PATCH 77/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8785ebd..f7d88fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -78,7 +78,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -86,11 +86,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 02eb606..a3c296d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 173ccb19fa8be8fe78e86dc9eb009b0b9438e06d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:26:10 +0000 Subject: [PATCH 78/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index baeb3a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0e60846..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bb52204..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 952a4dab52680c4effc52a84c26a906db5d91a01 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:26:39 +0000 Subject: [PATCH 79/85] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 142 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 187 - package.json | 70 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 44 files changed, 4870 insertions(+), 5277 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b5f6c1b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-24T01:00:47.809Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 720e6a5..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/ndarray/iter/entries) 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 a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 1749b52..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/assert-is-ndarray-like/dist'),T=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),z=require('@stdlib/array-base-zeros/dist'),F=require('@stdlib/ndarray-shape/dist'),L=require('@stdlib/ndarray-base-numel/dist'),P=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,n,i,s,t,d,v,o;if(!j(e))throw new TypeError(l('1jr4f',e));if(n={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(T(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));n.order=r.order}}return a=F(e),u=a.length,v=L(a),v===0&&(s=!0),n.order==="row-major"?d=u-1:d=0,o=-1,t=z(u),i={},f(i,"next",c),f(i,"return",h),m&&f(i,m,y),i;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(t=P(a,n.order,t,d,t)),{value:[t.slice(),e.get.apply(e,t)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,n)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 7c0e223..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACX,EAASW,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFF,EAAK,QAAU,YACnBI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRjB,EAAaiB,EAAM,OAAQM,CAAK,EAChCvB,EAAaiB,EAAM,SAAUO,CAAI,EAG5BnB,GACJL,EAAaiB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAjB,EAAO,QAAUY,IC1IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 30203c8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manner, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c8f89d1..baeb3a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0e60846 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..920bce2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 f7d88fb..0000000 --- a/lib/main.js +++ /dev/null @@ -1,187 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( opts.order === 'row-major' ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index a3c296d..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,49 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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.2" - }, - "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..bb52204 --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From bdf3ec095616c1da9f84a69ffb0749d557716227 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 01:50:07 +0000 Subject: [PATCH 80/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 579351d..e34a743 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -79,7 +79,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -87,11 +87,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 6149b34..69d647d 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 4f845de2501dd9d3d497951245d908bf67b305c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 01:50:28 +0000 Subject: [PATCH 81/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index baeb3a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0e60846..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as j}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function a(p){var h,f,v,b,c,u,g,x,y,w;if(!t(p))throw new TypeError(l("1jr4f",p));if(b={order:p.order},arguments.length>1){if(!e(h=arguments[1]))throw new TypeError(l("1jr2V",h));if(n(h,"order")){if(!s(h.order))throw new TypeError(l("1jr5C","order",h.order));b.order=h.order}}return v=(f=o(p)).length,0===(y=m(f))&&(u=!0),x="row-major"===b.order?v-1:0,w=-1,g=i(v),r(c={},"next",(function(){if(w+=1,u||w>=y)return{done:!0};w>0&&(g=j(f,b.order,g,x,g));return{value:[g.slice(),p.get.apply(p,g)],done:!1}})),r(c,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),d&&r(c,d,(function(){return a(p,b)})),c}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 920bce2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( opts.order === 'row-major' ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;okCAmEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADmB,cAAfJ,EAAKU,MACHX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMe,EAAOnB,GAIboB,EADAlB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNe,MAAQ,GAGLd,EAAI,IACRH,EAAMkB,EAAoBvB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNmB,MAAS,CAAEnB,EAAIoB,QAAS3B,EAAE4B,IAAIC,MAAO7B,EAAGO,IACxCiB,MAAQ,EAET,IA7BDD,EAAalB,EAAM,UAsCnB,SAAcqB,GAEb,GADApB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNU,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAalB,EAAMyB,GAqDpB,WACC,OAAO/B,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bb52204..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6e840f00c22ff614f837ee0c508c5c648a4e6d86 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 01:50:53 +0000 Subject: [PATCH 82/85] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 143 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 188 - package.json | 71 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 43 files changed, 4870 insertions(+), 5279 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 720e6a5..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/ndarray/iter/entries) 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 a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0569610..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/ndarray-base-assert-is-row-major-string/dist'),T=require('@stdlib/assert-is-ndarray-like/dist'),z=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),F=require('@stdlib/array-base-zeros/dist'),L=require('@stdlib/ndarray-shape/dist'),P=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,t,n,s,i,d,v,o;if(!T(e))throw new TypeError(l('1jr4f',e));if(t={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(z(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));t.order=r.order}}return a=L(e),u=a.length,v=P(a),v===0&&(s=!0),j(t.order)?d=u-1:d=0,o=-1,i=F(u),n={},f(n,"next",c),f(n,"return",h),m&&f(n,m,y),n;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(i=R(a,t.order,i,d,i)),{value:[i.slice(),e.get.apply(e,i)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,t)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 6963f22..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isRowMajor = require( '@stdlib/ndarray-base-assert-is-row-major-string' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( isRowMajor( opts.order ) ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAa,QAAS,iDAAkD,EACxEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACb,EAAea,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACZ,EAASY,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFhB,EAAYc,EAAK,KAAM,EAC3BI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRlB,EAAakB,EAAM,OAAQM,CAAK,EAChCxB,EAAakB,EAAM,SAAUO,CAAI,EAG5BnB,GACJN,EAAakB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAlB,EAAO,QAAUa,IC3IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isRowMajor", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 30203c8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manner, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c8f89d1..baeb3a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4e7fa7a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-row-major-string@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function p(h){var f,v,b,c,g,u,x,y,w,E;if(!n(h))throw new TypeError(a("1jr4f",h));if(c={order:h.order},arguments.length>1){if(!e(f=arguments[1]))throw new TypeError(a("1jr2V",f));if(d(f,"order")){if(!s(f.order))throw new TypeError(a("1jr5C","order",f.order));c.order=f.order}}return b=(v=m(h)).length,0===(w=j(v))&&(u=!0),y=t(c.order)?b-1:0,E=-1,x=o(b),r(g={},"next",(function(){if(E+=1,u||E>=w)return{done:!0};E>0&&(x=l(v,c.order,x,y,x));return{value:[x.slice(),h.get.apply(h,x)],done:!1}})),r(g,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),i&&r(g,i,(function(){return p(h,c)})),g}export{p as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..29682cf --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isRowMajor from '@stdlib/ndarray-base-assert-is-row-major-string';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( isRowMajor( opts.order ) ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","isRowMajor","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;+qCAoEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADIc,EAAYlB,EAAKU,OACfX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMgB,EAAOpB,GAIbqB,EADAnB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNgB,MAAQ,GAGLf,EAAI,IACRH,EAAMmB,EAAoBxB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNoB,MAAS,CAAEpB,EAAIqB,QAAS5B,EAAE6B,IAAIC,MAAO9B,EAAGO,IACxCkB,MAAQ,EAET,IA7BDD,EAAanB,EAAM,UAsCnB,SAAcsB,GAEb,GADArB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNW,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAanB,EAAM0B,GAqDpB,WACC,OAAOhC,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 e34a743..0000000 --- a/lib/main.js +++ /dev/null @@ -1,188 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isRowMajor = require( '@stdlib/ndarray-base-assert-is-row-major-string' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( isRowMajor( opts.order ) ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 69d647d..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-row-major-string": "github:stdlib-js/ndarray-base-assert-is-row-major-string#main", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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.2" - }, - "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..5fb1872 --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); From 7090b469b42efdf6243fa530b5513f88ddcdaa4b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 01:53:25 +0000 Subject: [PATCH 83/85] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index 579351d..e34a743 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ var zeros = require( '@stdlib/array-base-zeros' ); var getShape = require( '@stdlib/ndarray-shape' ); var numel = require( '@stdlib/ndarray-base-numel' ); var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -79,7 +79,7 @@ function nditerEntries( x ) { var i; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jr4f', x ) ); } opts = { 'order': x.order @@ -87,11 +87,11 @@ function nditerEntries( x ) { if ( arguments.length > 1 ) { options = arguments[ 1 ]; if ( !isPlainObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '1jr2V', options ) ); } if ( hasOwnProp( options, 'order' ) ) { if ( !isOrder( options.order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) ); + throw new TypeError( format( '1jr5C', 'order', options.order ) ); } opts.order = options.order; } diff --git a/package.json b/package.json index 6149b34..69d647d 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", "@stdlib/ndarray-base-numel": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From f92e55254fb91d91e24fe5de69aed1cbef5453e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 02:14:52 +0000 Subject: [PATCH 84/85] Remove files --- index.d.ts | 81 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4928 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index baeb3a7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,81 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; -import { typedndarray, Order } from '@stdlib/types/ndarray'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = TypedIterator | TypedIterableIterator; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Index iteration order. - * - * ## Notes - * - * - By default, the returned iterator returns values according to the layout order of the provided array. Accordingly, for row-major input arrays, the last dimension indices increment fastest. For column-major input arrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input array's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input array may, in some circumstances, result in performance degradation due to cache misses. - */ - order?: Order; -} - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* ## Notes -* -* - Each returned index is a Cartesian index (i.e., an array of subscripts/dimension indices). -* -* @param x - input array -* @param options - function options -* @param options.order - index iteration order -* @returns iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { -* 'dtype': 'float64' -* }); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -declare function nditerEntries( x: typedndarray, options?: Options ): Iterator<[ Array, T ]>; - - -// EXPORTS // - -export = nditerEntries; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4e7fa7a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-row-major-string@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function p(h){var f,v,b,c,g,u,x,y,w,E;if(!n(h))throw new TypeError(a("1jr4f",h));if(c={order:h.order},arguments.length>1){if(!e(f=arguments[1]))throw new TypeError(a("1jr2V",f));if(d(f,"order")){if(!s(f.order))throw new TypeError(a("1jr5C","order",f.order));c.order=f.order}}return b=(v=m(h)).length,0===(w=j(v))&&(u=!0),y=t(c.order)?b-1:0,E=-1,x=o(b),r(g={},"next",(function(){if(E+=1,u||E>=w)return{done:!0};E>0&&(x=l(v,c.order,x,y,x));return{value:[x.slice(),h.get.apply(h,x)],done:!1}})),r(g,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),i&&r(g,i,(function(){return p(h,c)})),g}export{p as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 29682cf..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isRowMajor from '@stdlib/ndarray-base-assert-is-row-major-string';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( isRowMajor( opts.order ) ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","isRowMajor","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;+qCAoEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADIc,EAAYlB,EAAKU,OACfX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMgB,EAAOpB,GAIbqB,EADAnB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNgB,MAAQ,GAGLf,EAAI,IACRH,EAAMmB,EAAoBxB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNoB,MAAS,CAAEpB,EAAIqB,QAAS5B,EAAE6B,IAAIC,MAAO9B,EAAGO,IACxCkB,MAAQ,EAET,IA7BDD,EAAanB,EAAM,UAsCnB,SAAcsB,GAEb,GADArB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNW,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAanB,EAAM0B,GAqDpB,WACC,OAAOhC,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5fb1872..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3d4dfc64d7776701610d10e1715a043029e61eb0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 02:15:18 +0000 Subject: [PATCH 85/85] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 143 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 60 - docs/types/test.ts | 87 - examples/index.js | 41 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 54 - lib/main.js | 188 - package.json | 71 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1134 ---- 44 files changed, 4870 insertions(+), 5280 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ba15908..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-19T01:39:42.405Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 720e6a5..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/ndarray/iter/entries) 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 a994cbb..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/ndarray/iter/entries) 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 01c1854..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: '2 14 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -220,7 +211,7 @@ while ( true ) { ## 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]. @@ -285,13 +276,13 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices +[@stdlib/ndarray/iter/indices]: https://github.com/stdlib-js/ndarray-iter-indices/tree/esm -[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values +[@stdlib/ndarray/iter/values]: https://github.com/stdlib-js/ndarray-iter-values/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 5d0edee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +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 bench = require( '@stdlib/bench-harness' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var isArray = require( '@stdlib/assert-is-array' ); -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var pkg = require( './../package.json' ).name; -var nditerEntries = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var iter; - var x; - var i; - - x = array( [ [ 1, 2, 3, 4 ] ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - iter = nditerEntries( x ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var iter; - var x; - var z; - var i; - - x = zeros( [ b.iterations+1, 1 ], { - 'dtype': 'generic' - }); - - iter = nditerEntries( x ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( typeof z !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( z ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e4c1b0a..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/ndarray/iter/entries" -%% click B href "https://github.com/stdlib-js/ndarray-iter-entries/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-iter-entries/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-iter-entries/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-iter-entries/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-iter-entries/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/iter/entries -[production-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-iter-entries/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-iter-entries/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-iter-entries/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 32a7c2b..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import nditerEntries from '../docs/types/index'; -export = nditerEntries; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0569610..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var b=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var q=b(function(k,g){ -var f=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=require('@stdlib/assert-is-plain-object/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),j=require('@stdlib/ndarray-base-assert-is-row-major-string/dist'),T=require('@stdlib/assert-is-ndarray-like/dist'),z=require('@stdlib/assert-has-own-property/dist'),m=require('@stdlib/symbol-iterator/dist'),F=require('@stdlib/array-base-zeros/dist'),L=require('@stdlib/ndarray-shape/dist'),P=require('@stdlib/ndarray-base-numel/dist'),R=require('@stdlib/ndarray-base-next-cartesian-index/dist').assign,l=require('@stdlib/error-tools-fmtprodmsg/dist');function p(e){var r,a,u,t,n,s,i,d,v,o;if(!T(e))throw new TypeError(l('1jr4f',e));if(t={order:e.order},arguments.length>1){if(r=arguments[1],!O(r))throw new TypeError(l('1jr2V',r));if(z(r,"order")){if(!E(r.order))throw new TypeError(l('1jr5C',"order",r.order));t.order=r.order}}return a=L(e),u=a.length,v=P(a),v===0&&(s=!0),j(t.order)?d=u-1:d=0,o=-1,i=F(u),n={},f(n,"next",c),f(n,"return",h),m&&f(n,m,y),n;function c(){return o+=1,s||o>=v?{done:!0}:(o>0&&(i=R(a,t.order,i,d,i)),{value:[i.slice(),e.get.apply(e,i)],done:!1})}function h(w){return s=!0,arguments.length?{value:w,done:!0}:{done:!0}}function y(){return p(e,t)}}g.exports=p -});var S=q();module.exports=S; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 6963f22..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) 2023 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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar isOrder = require( '@stdlib/ndarray-base-assert-is-order' );\nvar isRowMajor = require( '@stdlib/ndarray-base-assert-is-row-major-string' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar getShape = require( '@stdlib/ndarray-shape' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( isRowMajor( opts.order ) ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = nditerEntries;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @module @stdlib/ndarray-iter-entries\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var nditerEntries = require( '@stdlib/ndarray-iter-entries' );\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAU,QAAS,sCAAuC,EAC1DC,EAAa,QAAS,iDAAkD,EACxEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAiB,QAAS,yBAA0B,EACpDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAqB,QAAS,2CAA4C,EAAE,OAC5EC,EAAS,QAAS,uBAAwB,EAmC9C,SAASC,EAAeC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACnB,EAAeS,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAKvG,GAHAI,EAAO,CACN,MAASJ,EAAE,KACZ,EACK,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAU,UAAW,CAAE,EAClB,CAACb,EAAea,CAAQ,EAC5B,MAAM,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE9G,GAAKT,EAAYS,EAAS,OAAQ,EAAI,CACrC,GAAK,CAACZ,EAASY,EAAQ,KAAM,EAC5B,MAAM,IAAI,UAAWH,EAAQ,wEAAyE,QAASG,EAAQ,KAAM,CAAE,EAEhIG,EAAK,MAAQH,EAAQ,KACtB,CACD,CAEA,OAAAC,EAAQP,EAAUK,CAAE,EACpBG,EAAQD,EAAM,OAGdO,EAAIb,EAAOM,CAAM,EACZO,IAAM,IACVH,EAAM,IAGFhB,EAAYc,EAAK,KAAM,EAC3BI,EAAML,EAAQ,EAEdK,EAAM,EAGPE,EAAI,GAGJH,EAAMb,EAAOS,CAAM,EAGnBE,EAAO,CAAC,EACRlB,EAAakB,EAAM,OAAQM,CAAK,EAChCxB,EAAakB,EAAM,SAAUO,CAAI,EAG5BnB,GACJN,EAAakB,EAAMZ,EAAgBoB,CAAQ,EAErCR,EAQP,SAASM,GAAO,CAEf,OADAD,GAAK,EACAJ,GAAOI,GAAKD,EACT,CACN,KAAQ,EACT,GAEIC,EAAI,IACRH,EAAMV,EAAoBK,EAAOE,EAAK,MAAOG,EAAKC,EAAKD,CAAI,GAGrD,CACN,MAAS,CAAEA,EAAI,MAAM,EAAGP,EAAE,IAAI,MAAOA,EAAGO,CAAI,CAAE,EAC9C,KAAQ,EACT,EACD,CASA,SAASK,EAAKE,EAAQ,CAErB,OADAR,EAAM,GACD,UAAU,OACP,CACN,MAASQ,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAOd,EAAeC,EAAGI,CAAK,CAC/B,CACD,CAKAlB,EAAO,QAAUa,IC3IjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isPlainObject", "isOrder", "isRowMajor", "isndarrayLike", "hasOwnProp", "iteratorSymbol", "zeros", "getShape", "numel", "nextCartesianIndex", "format", "nditerEntries", "x", "options", "shape", "ndims", "opts", "iter", "FLG", "idx", "dim", "N", "i", "next", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 30203c8..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,60 +0,0 @@ - -{{alias}}( x[, options] ) - Returns an iterator which returns [index, value] pairs for each element in a - provided ndarray. - - Each returned index is a Cartesian index (i.e., an array of subscripts/ - dimension indices). - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an ndarray's `@@iterator` method, regardless of whether this method - is defined. - - Parameters - ---------- - x: ndarray - Input array. - - options: Object (optional) - Options. - - options.order: string (optional) - Index iteration order. By default, the returned iterator returns values - according to the layout order of the provided array. Accordingly, for - row-major input arrays, the last dimension indices increment fastest. - For column-major input arrays, the first dimension indices increment - fastest. To override the inferred order and ensure that indices - increment in a specific manner, regardless of the input array's layout - order, explicitly set the iteration order. Note, however, that iterating - according to an order which does not match that of the input array may, - in some circumstances, result in performance degradation due to cache - misses. Must be either 'row-major' or 'column-major'. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ); - > var it = {{alias}}( x ); - > var v = it.next().value - [ [ 0, 0 ], 1 ] - > v = it.next().value - [ [ 0, 1 ], 2 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 42aff4d..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,87 +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. -*/ - -import zeros = require( '@stdlib/ndarray-zeros' ); -import nditerEntries = require( './index' ); - - -// TESTS // - -// The function returns an iterator... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x ); // $ExpectType Iterator<[number[], number]> - nditerEntries( x, {} ); // $ExpectType Iterator<[number[], number]> -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - nditerEntries( '123' ); // $ExpectError - nditerEntries( 123 ); // $ExpectError - nditerEntries( true ); // $ExpectError - nditerEntries( false ); // $ExpectError - nditerEntries( null ); // $ExpectError - nditerEntries( undefined ); // $ExpectError - nditerEntries( {} ); // $ExpectError - nditerEntries( ( x: number ): number => x ); // $ExpectError - - nditerEntries( '123', {} ); // $ExpectError - nditerEntries( 123, {} ); // $ExpectError - nditerEntries( true, {} ); // $ExpectError - nditerEntries( false, {} ); // $ExpectError - nditerEntries( null, {} ); // $ExpectError - nditerEntries( undefined, {} ); // $ExpectError - nditerEntries( {}, {} ); // $ExpectError - nditerEntries( ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an object... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, 'abc' ); // $ExpectError - nditerEntries( x, 123 ); // $ExpectError - nditerEntries( x, true ); // $ExpectError - nditerEntries( x, false ); // $ExpectError - nditerEntries( x, null ); // $ExpectError - nditerEntries( x, [] ); // $ExpectError - nditerEntries( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `order` option which is valid order... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries( x, { 'order': 'abc' } ); // $ExpectError - nditerEntries( x, { 'order': 123 } ); // $ExpectError - nditerEntries( x, { 'order': null } ); // $ExpectError - nditerEntries( x, { 'order': true } ); // $ExpectError - nditerEntries( x, { 'order': false } ); // $ExpectError - nditerEntries( x, { 'order': [] } ); // $ExpectError - nditerEntries( x, { 'order': {} } ); // $ExpectError - nditerEntries( x, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = zeros( [ 2, 2 ] ); - - nditerEntries(); // $ExpectError - nditerEntries( x, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 9d44e66..0000000 --- a/examples/index.js +++ /dev/null @@ -1,41 +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'; - -var array = require( '@stdlib/ndarray-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var nditerEntries = require( './../lib' ); - -// Define an input array: -var x = array( zeroTo( 27 ), { - 'shape': [ 3, 3, 3 ] -}); - -// Create an iterator for returning [index, value] pairs: -var it = nditerEntries( x ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index c8f89d1..baeb3a7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; import { typedndarray, Order } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4e7fa7a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-row-major-string@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import{assign as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-next-cartesian-index@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function p(h){var f,v,b,c,g,u,x,y,w,E;if(!n(h))throw new TypeError(a("1jr4f",h));if(c={order:h.order},arguments.length>1){if(!e(f=arguments[1]))throw new TypeError(a("1jr2V",f));if(d(f,"order")){if(!s(f.order))throw new TypeError(a("1jr5C","order",f.order));c.order=f.order}}return b=(v=m(h)).length,0===(w=j(v))&&(u=!0),y=t(c.order)?b-1:0,E=-1,x=o(b),r(g={},"next",(function(){if(E+=1,u||E>=w)return{done:!0};E>0&&(x=l(v,c.order,x,y,x));return{value:[x.slice(),h.get.apply(h,x)],done:!1}})),r(g,"return",(function(r){if(u=!0,arguments.length)return{value:r,done:!0};return{done:!0}})),i&&r(g,i,(function(){return p(h,c)})),g}export{p as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..29682cf --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isPlainObject from '@stdlib/assert-is-plain-object';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isRowMajor from '@stdlib/ndarray-base-assert-is-row-major-string';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport zeros from '@stdlib/array-base-zeros';\nimport getShape from '@stdlib/ndarray-shape';\nimport numel from '@stdlib/ndarray-base-numel';\nimport { assign as nextCartesianIndex } from '@stdlib/ndarray-base-next-cartesian-index';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray.\n*\n* @param {ndarray} x - input array\n* @param {Options} [options] - function options\n* @param {boolean} [options.order='row-major'] - index iteration order\n* @throws {TypeError} first argument must be an ndarray\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {Iterator} iterator\n*\n* @example\n* import array from '@stdlib/ndarray-array';\n*\n* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] );\n* // returns \n*\n* var iter = nditerEntries( x );\n*\n* var v = iter.next().value;\n* // returns [ [ 0, 0, 0 ], 1 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 0, 1 ], 2 ]\n*\n* v = iter.next().value;\n* // returns [ [ 0, 1, 0 ], 3 ]\n*\n* // ...\n*/\nfunction nditerEntries( x ) {\n\tvar options;\n\tvar shape;\n\tvar ndims;\n\tvar opts;\n\tvar iter;\n\tvar FLG;\n\tvar idx;\n\tvar dim;\n\tvar N;\n\tvar i;\n\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1jr4f', x ) );\n\t}\n\topts = {\n\t\t'order': x.order\n\t};\n\tif ( arguments.length > 1 ) {\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( '1jr2V', options ) );\n\t\t}\n\t\tif ( hasOwnProp( options, 'order' ) ) {\n\t\t\tif ( !isOrder( options.order ) ) {\n\t\t\t\tthrow new TypeError( format( '1jr5C', 'order', options.order ) );\n\t\t\t}\n\t\t\topts.order = options.order;\n\t\t}\n\t}\n\t// Retrieve input array meta data:\n\tshape = getShape( x );\n\tndims = shape.length;\n\n\t// Check whether the input array is empty...\n\tN = numel( shape );\n\tif ( N === 0 ) {\n\t\tFLG = true;\n\t}\n\t// Resolve the dimension in which indices iterate fastest:\n\tif ( isRowMajor( opts.order ) ) {\n\t\tdim = ndims - 1;\n\t} else {\n\t\tdim = 0;\n\t}\n\t// Initialize a counter:\n\ti = -1;\n\n\t// Initialize an index array:\n\tidx = zeros( ndims );\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tsetReadOnly( iter, 'next', next );\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next() {\n\t\ti += 1;\n\t\tif ( FLG || i >= N ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\tif ( i > 0 ) {\n\t\t\tidx = nextCartesianIndex( shape, opts.order, idx, dim, idx );\n\t\t}\n\t\t// Return the next set of indices:\n\t\treturn {\n\t\t\t'value': [ idx.slice(), x.get.apply( x, idx ) ],\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\treturn nditerEntries( x, opts );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default nditerEntries;\n"],"names":["nditerEntries","x","options","shape","ndims","opts","iter","FLG","idx","dim","N","i","isndarrayLike","TypeError","format","order","arguments","length","isPlainObject","hasOwnProp","isOrder","getShape","numel","isRowMajor","zeros","setReadOnly","done","nextCartesianIndex","value","slice","get","apply","iteratorSymbol"],"mappings":";;+qCAoEA,SAASA,EAAeC,GACvB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,IAAMC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAKvC,GAHAI,EAAO,CACNU,MAASd,EAAEc,OAEPC,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNhB,EAAUc,UAAW,IAEpB,MAAM,IAAIH,UAAWC,EAAQ,QAASZ,IAEvC,GAAKiB,EAAYjB,EAAS,SAAY,CACrC,IAAMkB,EAASlB,EAAQa,OACtB,MAAM,IAAIF,UAAWC,EAAQ,QAAS,QAASZ,EAAQa,QAExDV,EAAKU,MAAQb,EAAQa,KACrB,CACD,CA+BD,OA5BAX,GADAD,EAAQkB,EAAUpB,IACJgB,OAIH,KADXP,EAAIY,EAAOnB,MAEVI,GAAM,GAINE,EADIc,EAAYlB,EAAKU,OACfX,EAAQ,EAER,EAGPO,GAAK,EAGLH,EAAMgB,EAAOpB,GAIbqB,EADAnB,EAAO,CAAA,EACY,QAenB,WAEC,GADAK,GAAK,EACAJ,GAAOI,GAAKD,EAChB,MAAO,CACNgB,MAAQ,GAGLf,EAAI,IACRH,EAAMmB,EAAoBxB,EAAOE,EAAKU,MAAOP,EAAKC,EAAKD,IAGxD,MAAO,CACNoB,MAAS,CAAEpB,EAAIqB,QAAS5B,EAAE6B,IAAIC,MAAO9B,EAAGO,IACxCkB,MAAQ,EAET,IA7BDD,EAAanB,EAAM,UAsCnB,SAAcsB,GAEb,GADArB,GAAM,EACDS,UAAUC,OACd,MAAO,CACNW,MAASA,EACTF,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IA9CIM,GACJP,EAAanB,EAAM0B,GAqDpB,WACC,OAAOhC,EAAeC,EAAGI,EACzB,IArDMC,CAsDR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index cdc3a53..0000000 --- a/lib/index.js +++ /dev/null @@ -1,54 +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'; - -/** -* Create an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @module @stdlib/ndarray-iter-entries -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* var nditerEntries = require( '@stdlib/ndarray-iter-entries' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ - -// 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 e34a743..0000000 --- a/lib/main.js +++ /dev/null @@ -1,188 +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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isRowMajor = require( '@stdlib/ndarray-base-assert-is-row-major-string' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var nextCartesianIndex = require( '@stdlib/ndarray-base-next-cartesian-index' ).assign; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which returns `[index, value]` pairs for each element in a provided ndarray. -* -* @param {ndarray} x - input array -* @param {Options} [options] - function options -* @param {boolean} [options.order='row-major'] - index iteration order -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Iterator} iterator -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ] ); -* // returns -* -* var iter = nditerEntries( x ); -* -* var v = iter.next().value; -* // returns [ [ 0, 0, 0 ], 1 ] -* -* v = iter.next().value; -* // returns [ [ 0, 0, 1 ], 2 ] -* -* v = iter.next().value; -* // returns [ [ 0, 1, 0 ], 3 ] -* -* // ... -*/ -function nditerEntries( x ) { - var options; - var shape; - var ndims; - var opts; - var iter; - var FLG; - var idx; - var dim; - var N; - var i; - - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1jr4f', x ) ); - } - opts = { - 'order': x.order - }; - if ( arguments.length > 1 ) { - options = arguments[ 1 ]; - if ( !isPlainObject( options ) ) { - throw new TypeError( format( '1jr2V', options ) ); - } - if ( hasOwnProp( options, 'order' ) ) { - if ( !isOrder( options.order ) ) { - throw new TypeError( format( '1jr5C', 'order', options.order ) ); - } - opts.order = options.order; - } - } - // Retrieve input array meta data: - shape = getShape( x ); - ndims = shape.length; - - // Check whether the input array is empty... - N = numel( shape ); - if ( N === 0 ) { - FLG = true; - } - // Resolve the dimension in which indices iterate fastest: - if ( isRowMajor( opts.order ) ) { - dim = ndims - 1; - } else { - dim = 0; - } - // Initialize a counter: - i = -1; - - // Initialize an index array: - idx = zeros( ndims ); - - // Create an iterator protocol-compliant object: - iter = {}; - setReadOnly( iter, 'next', next ); - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next() { - i += 1; - if ( FLG || i >= N ) { - return { - 'done': true - }; - } - if ( i > 0 ) { - idx = nextCartesianIndex( shape, opts.order, idx, dim, idx ); - } - // Return the next set of indices: - return { - 'value': [ idx.slice(), x.get.apply( x, idx ) ], - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - return nditerEntries( x, opts ); - } -} - - -// EXPORTS // - -module.exports = nditerEntries; diff --git a/package.json b/package.json index 69d647d..57ca7a2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator which returns [index, value] pairs for each element in a provided ndarray.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-row-major-string": "github:stdlib-js/ndarray-base-assert-is-row-major-string#main", - "@stdlib/ndarray-base-next-cartesian-index": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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.2" - }, - "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..5fb1872 --- /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 c3ab0c3..0000000 --- a/test/test.js +++ /dev/null @@ -1,1134 +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 proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var array = require( '@stdlib/ndarray-array' ); -var zeros = require( '@stdlib/ndarray-zeros' ); -var nditerEntries = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof nditerEntries, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [ 1, '1' ], - 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() { - nditerEntries( value, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - nditerEntries( x, value ); - }; - } -}); - -tape( 'the function throws an error if provided an `order` option which is not a valid order', function test( t ) { - var values; - var x; - var i; - - x = zeros( [ 2, 2 ] ); - - values = [ - '5', - 5, - NaN, - null, - true, - false, - 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() { - nditerEntries( x, { - 'order': value - }); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=0)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [] ); - expected = [ - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=1, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], { - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 3 ], 4 ], - 'done': false - }, - { - 'value': [ [ 4 ], 5 ], - 'done': false - }, - { - 'value': [ [ 5 ], 6 ], - 'done': false - }, - { - 'value': [ [ 6 ], 7 ], - 'done': false - }, - { - 'value': [ [ 7 ], 8 ], - 'done': false - }, - { - 'value': [ [ 8 ], 9 ], - 'done': false - }, - { - 'value': [ [ 9 ], 10 ], - 'done': false - }, - { - 'value': [ [ 10 ], 11 ], - 'done': false - }, - { - 'value': [ [ 11 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=2, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12 ], { - 'shape': [ 4, 3 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0 ], 4 ], - 'done': false - }, - { - 'value': [ [ 2, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 3, 0 ], 10 ], - 'done': false - }, - { - 'value': [ [ 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 1 ], 5 ], - 'done': false - }, - { - 'value': [ [ 2, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 3, 1 ], 11 ], - 'done': false - }, - { - 'value': [ [ 0, 2 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 2 ], 6 ], - 'done': false - }, - { - 'value': [ [ 2, 2 ], 9 ], - 'done': false - }, - { - 'value': [ [ 3, 2 ], 12 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, row-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ [ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ] ], { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=3, column-major)', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = array( [ 1, 5, 3, 7, 2, 6, 4, 8 ], { - 'shape': [ 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, row-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (ndims=4, column-major)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ 1, 1, 5, 5, 3, 3, 7, 7, 2, 2, 6, 6, 4, 4, 8, 8 ]; - x = array( buf, { - 'shape': [ 2, 2, 2, 2 ], - 'order': 'column-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function supports specifying the index iteration order (ndims=4)', function test( t ) { - var expected; - var buf; - var it; - var e; - var x; - var r; - var i; - - buf = [ - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ], - [ - [ - [ 1, 2 ], - [ 3, 4 ] - ], - [ - [ 5, 6 ], - [ 7, 8 ] - ] - ] - ]; - x = array( buf, { - 'order': 'row-major' - }); - expected = [ - { - 'value': [ [ 0, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 0 ], 1 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 0 ], 5 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 0 ], 3 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 0 ], 7 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 0, 1 ], 2 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 0, 1 ], 6 ], - 'done': false - }, - { - 'value': [ [ 0, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 1, 0, 1, 1 ], 4 ], - 'done': false - }, - { - 'value': [ [ 0, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'value': [ [ 1, 1, 1, 1 ], 8 ], - 'done': false - }, - { - 'done': true - } - ]; - - it = nditerEntries( x, { - 'order': 'column-major' - }); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - if ( e.value === void 0 ) { - t.deepEqual( r, e, 'returns expected value' ); - } else { - t.strictEqual( r.value.length, 2, 'returns expected value' ); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.deepEqual( r.value, e.value, 'returns expected value' ); - t.strictEqual( r.done, e.done, 'returns expected value' ); - } - } - t.end(); -}); - -tape( 'the function returns an iterator which does not iterate over empty arrays', function test( t ) { - var expected; - var it; - var e; - var x; - var r; - var i; - - x = zeros( [ 2, 0, 2, 2, 2 ] ); - expected = [ - { - 'done': true - }, - { - 'done': true - }, - { - 'done': true - } - ]; - - it = nditerEntries( x ); - t.strictEqual( it.next.length, 0, 'has zero arity' ); - - for ( i = 0; i < expected.length; i++ ) { - r = it.next(); - e = expected[ i ]; - t.deepEqual( r, e, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.next(); - t.strictEqual( isNonNegativeIntegerArray( r.value[ 0 ] ), true, 'returns expected value' ); - t.strictEqual( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.strictEqual( r.value, 'finished', 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - r = it.next(); - t.strictEqual( r.value, void 0, 'returns expected value' ); - t.strictEqual( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var nditerEntries; - var it1; - var it2; - var x; - var i; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - - it1 = nditerEntries( x ); - t.strictEqual( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.strictEqual( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.strictEqual( typeof it2, 'object', 'returns an object' ); - t.strictEqual( typeof it2.next, 'function', 'has method' ); - t.strictEqual( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < x[ 0 ]; i++ ) { - t.deepEqual( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var nditerEntries; - var it; - - nditerEntries = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = nditerEntries( zeros( [ 2, 2 ] ) ); - t.strictEqual( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -});